xz: Fix use of wrong variable in a fcntl() call.
[xz/debian.git] / tests / test_check.c
blob7d4a36078cf75d14cc032513f404405ea4b40f11
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.
13 ///////////////////////////////////////////////////////////////////////////////
15 #include "tests.h"
18 static const uint8_t test_string[9] = "123456789";
19 static const uint8_t test_unaligned[12] = "xxx123456789";
22 static bool
23 test_crc32(void)
25 static const uint32_t test_vector = 0xCBF43926;
27 // Test 1
28 uint32_t crc = lzma_crc32(test_string, sizeof(test_string), 0);
29 if (crc != test_vector)
30 return true;
32 // Test 2
33 crc = lzma_crc32(test_unaligned + 3, sizeof(test_string), 0);
34 if (crc != test_vector)
35 return true;
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;
44 return false;
48 static bool
49 test_crc64(void)
51 static const uint64_t test_vector = 0x995DC9BBDF1939FA;
53 // Test 1
54 uint64_t crc = lzma_crc64(test_string, sizeof(test_string), 0);
55 if (crc != test_vector)
56 return true;
58 // Test 2
59 crc = lzma_crc64(test_unaligned + 3, sizeof(test_string), 0);
60 if (crc != test_vector)
61 return true;
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;
70 return false;
74 int
75 main(void)
77 bool error = false;
79 error |= test_crc32();
80 error |= test_crc64();
82 return error ? 1 : 0;