]> icculus.org git repositories - icculus/xz.git/blob - tests/test_check.c
Imported to git.
[icculus/xz.git] / tests / test_check.c
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file       test_check.c
4 /// \brief      Tests integrity checks
5 ///
6 /// \todo       Add SHA256
7 //
8 //  Copyright (C) 2007 Lasse Collin
9 //
10 //  This library is free software; you can redistribute it and/or
11 //  modify it under the terms of the GNU Lesser General Public
12 //  License as published by the Free Software Foundation; either
13 //  version 2.1 of the License, or (at your option) any later version.
14 //
15 //  This library is distributed in the hope that it will be useful,
16 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
17 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 //  Lesser General Public License for more details.
19 //
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #include "tests.h"
23
24
25 static const uint8_t test_string[9] = "123456789";
26 static const uint8_t test_unaligned[12] = "xxx123456789";
27
28
29 static bool
30 test_crc32(void)
31 {
32         static const uint32_t test_vector = 0xCBF43926;
33
34         // Test 1
35         uint32_t crc = lzma_crc32(test_string, sizeof(test_string), 0);
36         if (crc != test_vector)
37                 return true;
38
39         // Test 2
40         crc = lzma_crc32(test_unaligned + 3, sizeof(test_string), 0);
41         if (crc != test_vector)
42                 return true;
43
44         // Test 3
45         crc = 0;
46         for (size_t i = 0; i < sizeof(test_string); ++i)
47                 crc = lzma_crc32(test_string + i, 1, crc);
48         if (crc != test_vector)
49                 return true;
50
51         return false;
52 }
53
54
55 static bool
56 test_crc64(void)
57 {
58         static const uint64_t test_vector = 0x995DC9BBDF1939FA;
59
60         // Test 1
61         uint64_t crc = lzma_crc64(test_string, sizeof(test_string), 0);
62         if (crc != test_vector)
63                 return true;
64
65         // Test 2
66         crc = lzma_crc64(test_unaligned + 3, sizeof(test_string), 0);
67         if (crc != test_vector)
68                 return true;
69
70         // Test 3
71         crc = 0;
72         for (size_t i = 0; i < sizeof(test_string); ++i)
73                 crc = lzma_crc64(test_string + i, 1, crc);
74         if (crc != test_vector)
75                 return true;
76
77         return false;
78 }
79
80
81 int
82 main()
83 {
84         bool error = false;
85
86         error |= test_crc32();
87         error |= test_crc64();
88
89         return error ? 1 : 0;
90 }