File: crc.h

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (73 lines) | stat: -rw-r--r-- 2,146 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <cxxtest/TestSuite.h>

#include "common/crc.h"
#include "common/crc_slow.h"

namespace {
const byte *testStringCRC = (const byte *)"The quick brown fox jumps over the lazy dog";
const int testLenCRC = 43;
}

class CrcTestSuite : public CxxTest::TestSuite
{
public:
	void test_crc32() {
		Common::CRC32 crc;
		TS_ASSERT_EQUALS(crc.crcFast(testStringCRC, testLenCRC), 0x414fa339U);
		uint32 running = crc.getInitRemainder();
		for (const byte *ptr = testStringCRC; *ptr; ptr++) {
			running = crc.processByte(*ptr, running);
		}
		TS_ASSERT_EQUALS(crc.finalize(running), 0x414fa339U);
	}

	void test_crc16() {
		Common::CRC16 crc;
		TS_ASSERT_EQUALS(crc.crcFast(testStringCRC, testLenCRC), 0xfcdfU);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testStringCRC; *ptr; ptr++) {
			running = crc.processByte(*ptr, running);
		}
		TS_ASSERT_EQUALS(crc.finalize(running), 0xfcdfU);
	}

	void test_crc_ccitt() {
		Common::CRC_CCITT crc; // aka ccitt-false
		TS_ASSERT_EQUALS(crc.crcFast(testStringCRC, testLenCRC), 0x8fddU);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testStringCRC; *ptr; ptr++) {
			running = crc.processByte(*ptr, running);
		}
		TS_ASSERT_EQUALS(crc.finalize(running), 0x8fddU);
	}

	void test_crc_binhex() {
		Common::CRC_BINHEX crc; // Aka xmodem
		TS_ASSERT_EQUALS(crc.crcFast(testStringCRC, testLenCRC), 0xf0c8U);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testStringCRC; *ptr; ptr++) {
			running = crc.processByte(*ptr, running);
		}
		TS_ASSERT_EQUALS(crc.finalize(running), 0xf0c8U);
	}

	void test_crc32_slow() {
		Common::CRC32_Slow crc;
		TS_ASSERT_EQUALS(crc.crcSlow(testStringCRC, testLenCRC), 0x414fa339U);
	}

	void test_crc16_slow() {
		Common::CRC16_Slow crc;
		TS_ASSERT_EQUALS(crc.crcSlow(testStringCRC, testLenCRC), 0xfcdfU);
	}

	void test_crc_ccitt_slow() {
		Common::CRC_CCITT_Slow crc; // aka ccitt-false
		TS_ASSERT_EQUALS(crc.crcSlow(testStringCRC, testLenCRC), 0x8fddU);
	}

	void test_crc_binhex_slow() {
		Common::CRC_BINHEX_Slow crc; // Aka xmodem
		TS_ASSERT_EQUALS(crc.crcSlow(testStringCRC, testLenCRC), 0xf0c8U);
	}
};