/
main.c
86 lines (70 loc) · 2.25 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* @file main.c
*
* @section License
* Copyright (C) 2014-2016, Erik Moqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* This file is part of the Simba project.
*/
#include "simba.h"
static int test_crc_32(struct harness_t *harness_p)
{
char string[] = "The quick brown fox jumps over the lazy dog";
BTASSERT(crc_32(0, string, strlen(string)) == 0x414fa339);
return (0);
}
static int test_crc_ccitt(struct harness_t *harness_p)
{
uint16_t crc;
/* CCITT with 0xffff as initial value. */
BTASSERT(crc_ccitt(0xffff, "", 0) == 0xffff);
BTASSERT(crc_ccitt(0xffff, "1", 1) == 0xc782);
BTASSERT(crc_ccitt(0xffff, "123456789", 9) == 0x29b1);
crc = crc_ccitt(0xffff, "12345", 5);
BTASSERT(crc_ccitt(crc, "6789", 4) == 0x29b1);
return (0);
}
static int test_crc_xmodem(struct harness_t *harness_p)
{
uint16_t crc;
/* XModem with 0x0000 as initial value. */
BTASSERT(crc_xmodem(0x0000, "", 0) == 0x0000);
BTASSERT(crc_xmodem(0x0000, "1", 1) == 0x2672);
BTASSERT(crc_xmodem(0x0000, "123456789", 9) == 0x31c3);
crc = crc_xmodem(0x0000, "12345", 5);
BTASSERT(crc_xmodem(crc, "6789", 4) == 0x31c3);
return (0);
}
static int test_crc_7(struct harness_t *harness_p)
{
/* CRC-7 calculation. */
BTASSERT(crc_7("", 0) == 0x01);
BTASSERT(crc_7("1", 1) == 0x45);
BTASSERT(crc_7("123456789", 9) == 0xeb);
return (0);
}
int main()
{
struct harness_t harness;
struct harness_testcase_t harness_testcases[] = {
{ test_crc_32, "test_crc_32" },
{ test_crc_ccitt, "test_crc_ccitt" },
{ test_crc_xmodem, "test_crc_xmodem" },
{ test_crc_7, "test_crc_7" },
{ NULL, NULL }
};
sys_start();
harness_init(&harness);
harness_run(&harness, harness_testcases);
return (0);
}