1 /////////////////////////////////////////////////////////////////////////////// 2 // 3 /// \file test_check.c 4 /// \brief Tests integrity checks 5 /// 6 /// \todo Add SHA256 7 // 8 // Author: Lasse Collin 9 // 10 // This file has been put into the public domain. 11 // You can do whatever you want with this file. 12 // 13 /////////////////////////////////////////////////////////////////////////////// 14 15 #include "tests.h" 16 17 18 static const uint8_t test_string[9] = "123456789"; 19 static const uint8_t test_unaligned[12] = "xxx123456789"; 20 21 22 static bool 23 test_crc32(void) 24 { 25 static const uint32_t test_vector = 0xCBF43926; 26 27 // Test 1 28 uint32_t crc = lzma_crc32(test_string, sizeof(test_string), 0); 29 if (crc != test_vector) 30 return true; 31 32 // Test 2 33 crc = lzma_crc32(test_unaligned + 3, sizeof(test_string), 0); 34 if (crc != test_vector) 35 return true; 36 37 // Test 3 38 crc = 0; 39 for (size_t i = 0; i < sizeof(test_string); ++i) 40 crc = lzma_crc32(test_string + i, 1, crc); 41 if (crc != test_vector) 42 return true; 43 44 return false; 45 } 46 47 48 static bool 49 test_crc64(void) 50 { 51 static const uint64_t test_vector = 0x995DC9BBDF1939FA; 52 53 // Test 1 54 uint64_t crc = lzma_crc64(test_string, sizeof(test_string), 0); 55 if (crc != test_vector) 56 return true; 57 58 // Test 2 59 crc = lzma_crc64(test_unaligned + 3, sizeof(test_string), 0); 60 if (crc != test_vector) 61 return true; 62 63 // Test 3 64 crc = 0; 65 for (size_t i = 0; i < sizeof(test_string); ++i) 66 crc = lzma_crc64(test_string + i, 1, crc); 67 if (crc != test_vector) 68 return true; 69 70 return false; 71 } 72 73 74 int 75 main(void) 76 { 77 bool error = false; 78 79 error |= test_crc32(); 80 error |= test_crc64(); 81 82 return error ? 1 : 0; 83 } 84