Rizin
unix-like reverse engineering framework and cli tools
test_check.c File Reference

Tests integrity checks. More...

#include "tests.h"

Go to the source code of this file.

Functions

static bool test_crc32 (void)
 
static bool test_crc64 (void)
 
int main (void)
 

Variables

static const uint8_t test_string [9] = { 49, 50, 51, 52, 53, 54, 55, 56, 57 }
 
static const uint8_t test_unaligned [12] = { 120, 120, 120, 49, 50, 51, 52, 53, 54, 55, 56, 57 }
 

Detailed Description

Tests integrity checks.

Todo:
Add SHA256

Definition in file test_check.c.

Function Documentation

◆ main()

int main ( void  )

Definition at line 80 of file test_check.c.

81 {
82  bool error = false;
83 
84  error |= test_crc32();
85  error |= test_crc64();
86 
87  return error ? 1 : 0;
88 }
static bool test_crc64(void)
Definition: test_check.c:54
static bool test_crc32(void)
Definition: test_check.c:28
void error(const char *msg)
Definition: untgz.c:593

References error(), test_crc32(), and test_crc64().

◆ test_crc32()

static bool test_crc32 ( void  )
static

Definition at line 28 of file test_check.c.

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 }
lzma_index ** i
Definition: index.h:629
unsigned int uint32_t
Definition: sftypes.h:29
static const uint8_t test_string[9]
Definition: test_check.c:22
static const uint8_t test_unaligned[12]
Definition: test_check.c:24

References i, test_string, and test_unaligned.

Referenced by main().

◆ test_crc64()

static bool test_crc64 ( void  )
static

Definition at line 54 of file test_check.c.

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 }
unsigned long uint64_t
Definition: sftypes.h:28

References i, test_string, and test_unaligned.

Referenced by main().

Variable Documentation

◆ test_string

const uint8_t test_string[9] = { 49, 50, 51, 52, 53, 54, 55, 56, 57 }
static

Definition at line 22 of file test_check.c.

Referenced by test_crc32(), and test_crc64().

◆ test_unaligned

const uint8_t test_unaligned[12] = { 120, 120, 120, 49, 50, 51, 52, 53, 54, 55, 56, 57 }
static

Definition at line 23 of file test_check.c.

Referenced by test_crc32(), and test_crc64().