Rizin
unix-like reverse engineering framework and cli tools
test_check.c
Go to the documentation of this file.
1 //
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 //
14 
15 #include "tests.h"
16 
17 
18 // These must be specified as numbers so that the test works on EBCDIC
19 // systems too.
20 // static const uint8_t test_string[9] = "123456789";
21 // static const uint8_t test_unaligned[12] = "xxx123456789";
22 static const uint8_t test_string[9] = { 49, 50, 51, 52, 53, 54, 55, 56, 57 };
23 static const uint8_t test_unaligned[12]
24  = { 120, 120, 120, 49, 50, 51, 52, 53, 54, 55, 56, 57 };
25 
26 
27 static bool
29 {
30  static const uint32_t test_vector = 0xCBF43926;
31 
32  // Test 1
33  uint32_t crc = lzma_crc32(test_string, sizeof(test_string), 0);
34  if (crc != test_vector)
35  return true;
36 
37  // Test 2
38  crc = lzma_crc32(test_unaligned + 3, sizeof(test_string), 0);
39  if (crc != test_vector)
40  return true;
41 
42  // Test 3
43  crc = 0;
44  for (size_t i = 0; i < sizeof(test_string); ++i)
45  crc = lzma_crc32(test_string + i, 1, crc);
46  if (crc != test_vector)
47  return true;
48 
49  return false;
50 }
51 
52 
53 static bool
55 {
56  static const uint64_t test_vector = 0x995DC9BBDF1939FA;
57 
58  // Test 1
59  uint64_t crc = lzma_crc64(test_string, sizeof(test_string), 0);
60  if (crc != test_vector)
61  return true;
62 
63  // Test 2
64  crc = lzma_crc64(test_unaligned + 3, sizeof(test_string), 0);
65  if (crc != test_vector)
66  return true;
67 
68  // Test 3
69  crc = 0;
70  for (size_t i = 0; i < sizeof(test_string); ++i)
71  crc = lzma_crc64(test_string + i, 1, crc);
72  if (crc != test_vector)
73  return true;
74 
75  return false;
76 }
77 
78 
79 int
80 main(void)
81 {
82  bool error = false;
83 
84  error |= test_crc32();
85  error |= test_crc64();
86 
87  return error ? 1 : 0;
88 }
lzma_index ** i
Definition: index.h:629
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
static const uint8_t test_string[9]
Definition: test_check.c:22
static bool test_crc64(void)
Definition: test_check.c:54
static bool test_crc32(void)
Definition: test_check.c:28
int main(void)
Definition: test_check.c:80
static const uint8_t test_unaligned[12]
Definition: test_check.c:24
Common definitions for test applications.
void error(const char *msg)
Definition: untgz.c:593