1 /*
2 * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <common/crc32/crc32.h>
8 #include <CppUTest/TestHarness.h>
9
TEST_GROUP(Crc32Tests)10 TEST_GROUP(Crc32Tests)
11 {
12 TEST_SETUP()
13 {
14 crc32_init();
15 }
16 };
17
18 /*
19 * Expected results obtained from: https://crc32.online/
20 */
TEST(Crc32Tests,shortString)21 TEST(Crc32Tests, shortString)
22 {
23 const unsigned char test_input[] = "Hello";
24 uint32_t expected_result = 0xf7d18982;
25 uint32_t input_crc = 0;
26
27 uint32_t result = crc32(input_crc, test_input, sizeof(test_input) - 1);
28
29 UNSIGNED_LONGS_EQUAL(expected_result, result);
30 }
31
TEST(Crc32Tests,longString)32 TEST(Crc32Tests, longString)
33 {
34 const unsigned char test_input[] =
35 "The boy stood on the burning deck Whence all but he had fled";
36 uint32_t expected_result = 0x1f11704c;
37 uint32_t input_crc = 0;
38
39 uint32_t result = crc32(input_crc, test_input, sizeof(test_input) - 1);
40
41 UNSIGNED_LONGS_EQUAL(expected_result, result);
42 }
43
TEST(Crc32Tests,multiPart)44 TEST(Crc32Tests, multiPart)
45 {
46 const unsigned char test_input_1[] =
47 "The boy stood on the burning deck ";
48 const unsigned char test_input_2[] =
49 "Whence all but he had fled";
50
51 uint32_t expected_result = 0x1f11704c;
52 uint32_t result = 0;
53
54 result = crc32(result, test_input_1, sizeof(test_input_1) - 1);
55 result = crc32(result, test_input_2, sizeof(test_input_2) - 1);
56
57 UNSIGNED_LONGS_EQUAL(expected_result, result);
58 }