-
Notifications
You must be signed in to change notification settings - Fork 0
/
crc32_test.c
51 lines (37 loc) · 1.14 KB
/
crc32_test.c
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
#include "sc_crc32.h"
#include <assert.h>
int main(int argc, char *argv[])
{
(void) argc;
(void) argv;
uint32_t crc1, crc2, crc3;
uint8_t buf[128] = {1, 1, 2, 3};
uint8_t buf2[4096 * 8] = {2, 5, 6, 5};
sc_crc32_init();
// pre-computed values
assert(sc_crc32(0, (uint8_t *) "", 1) == 1383945041);
assert(sc_crc32(0, (uint8_t *) "1", 2) == 2727214374);
assert(sc_crc32(0, (uint8_t *) "\0\0\0\0\0\0\0\0\0\0", 10) ==
3822973035);
assert(sc_crc32(0, (uint8_t *) "test", 5) == 2440484327);
assert(sc_crc32(0, (uint8_t *) "testtest", 9) == 443192409);
crc1 = sc_crc32(0, buf, 100);
crc2 = sc_crc32(crc1, buf + 100, 28);
crc3 = sc_crc32(0, buf, 128);
assert(crc2 == crc3);
crc1 = sc_crc32(0, buf2, 4096 * 4);
crc2 = sc_crc32(crc1, buf2 + (4096 * 4), 4096 * 4);
crc3 = sc_crc32(0, buf2, 4096 * 8);
assert(crc2 == crc3);
crc1 = sc_crc32(100, buf, 8);
crc2 = sc_crc32(100, buf, 7);
assert(crc1 != crc2);
crc2 = sc_crc32(100, buf + 7, 7);
assert(crc1 != crc2);
crc2 = sc_crc32(100, buf + 8, 7);
assert(crc1 != crc2);
crc2 = sc_crc32(100, buf + 8, 8);
assert(crc1 != crc2);
crc2 = sc_crc32(100, buf + 8, 0);
assert(crc1 != crc2);
}