Debian Codegraph @

libdrgn/tests/crc32.c.in

raw
1 // Copyright (c) Meta Platforms, Inc. and affiliates.
2 // SPDX-License-Identifier: LGPL-2.1-or-later
3
4 #include <stdint.h>
5
6 #include "test_util.h"
7 #include "../crc32.h"
8
9 static uint32_t string_crc32(const char *s)
10 {
11 return ~crc32_update(~0, s, strlen(s));
12 }
13
14 #suite crc32
15
16 #tcase crc32
17
18 #test empty
19 {
20 ck_assert_uint_eq(string_crc32(""), 0);
21 }
22
23 #test simple
24 {
25 // https://reveng.sourceforge.io/crc-catalogue/17plus.htm#crc.cat.crc-32-iso-hdlc
26 ck_assert_uint_eq(string_crc32("123456789"), 0xcbf43926);
27 // http://www.febooti.com/products/filetweak/members/hash-and-crc/test-vectors/
28 ck_assert_uint_eq(string_crc32("The quick brown fox jumps over the lazy dog"),
29 0x414fa339);
30 }
31
32 #test update
33 {
34 uint32_t crc = ~0;
35 crc = crc32_update(crc, "12", 2);
36 crc = crc32_update(crc, "345", 3);
37 crc = crc32_update(crc, "6789", 4);
38 crc = ~crc;
39 ck_assert_uint_eq(crc, 0xcbf43926);
40 }