File: crc.h

package info (click to toggle)
scummvm 2.7.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 363,784 kB
  • sloc: cpp: 3,622,060; asm: 27,410; python: 10,528; sh: 10,241; xml: 6,752; java: 5,579; perl: 2,570; yacc: 1,635; javascript: 1,016; lex: 539; makefile: 398; ansic: 378; awk: 275; objc: 82; sed: 11; php: 1
file content (69 lines) | stat: -rw-r--r-- 2,060 bytes parent folder | download
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
#include <cxxtest/TestSuite.h>

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

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

class CrcTestSuite : public CxxTest::TestSuite
{
public:
	void test_crc32() {
		Common::CRC32 crc;
		TS_ASSERT_EQUALS(crc.crcFast(testString, testLen), 0x414fa339U);
		uint32 running = crc.getInitRemainder();
		for (const byte *ptr = testString; *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(testString, testLen), 0xfcdfU);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testString; *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(testString, testLen), 0x8fddU);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testString; *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(testString, testLen), 0xf0c8U);
		uint16 running = crc.getInitRemainder();
		for (const byte *ptr = testString; *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(testString, testLen), 0x414fa339U);
	}

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

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

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