Julian Hall | d635ad7 | 2022-09-20 15:50:35 +0100 | [diff] [blame^] | 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 | |
| 10 | TEST_GROUP(Crc32Tests) |
| 11 | { |
| 12 | |
| 13 | }; |
| 14 | |
| 15 | /* |
| 16 | * Expected results obtained from: https://crc32.online/ |
| 17 | */ |
| 18 | TEST(Crc32Tests, shortString) |
| 19 | { |
| 20 | const unsigned char test_input[] = "Hello"; |
| 21 | uint32_t expected_result = 0xf7d18982; |
| 22 | uint32_t input_crc = 0; |
| 23 | |
| 24 | uint32_t result = crc32(input_crc, test_input, sizeof(test_input) - 1); |
| 25 | |
| 26 | UNSIGNED_LONGS_EQUAL(expected_result, result); |
| 27 | } |
| 28 | |
| 29 | TEST(Crc32Tests, longString) |
| 30 | { |
| 31 | const unsigned char test_input[] = |
| 32 | "The boy stood on the burning deck Whence all but he had fled"; |
| 33 | uint32_t expected_result = 0x1f11704c; |
| 34 | uint32_t input_crc = 0; |
| 35 | |
| 36 | uint32_t result = crc32(input_crc, test_input, sizeof(test_input) - 1); |
| 37 | |
| 38 | UNSIGNED_LONGS_EQUAL(expected_result, result); |
| 39 | } |
| 40 | |
| 41 | TEST(Crc32Tests, multiPart) |
| 42 | { |
| 43 | const unsigned char test_input_1[] = |
| 44 | "The boy stood on the burning deck "; |
| 45 | const unsigned char test_input_2[] = |
| 46 | "Whence all but he had fled"; |
| 47 | |
| 48 | uint32_t expected_result = 0x1f11704c; |
| 49 | uint32_t result = 0; |
| 50 | |
| 51 | result = crc32(result, test_input_1, sizeof(test_input_1) - 1); |
| 52 | result = crc32(result, test_input_2, sizeof(test_input_2) - 1); |
| 53 | |
| 54 | UNSIGNED_LONGS_EQUAL(expected_result, result); |
| 55 | } |