summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_crc.c
blob: 61db0e22ebe420ad1db2076d2a31d68ec451d049 (plain)
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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <Eina.h>

#include "eina_suite.h"

START_TEST(eina_crc_simple)
{
   unsigned int seed = 0xffffffff, i, ret;
   const char *data[] =
     {
        "Hello World",
        "This is to test crc",
        "4baAsru=A$r&e.-",
        "=-.^Y@~Lp5e1)b^",
        "J(uhX4)!&Q#2,jr"
     };

   unsigned int result[] =
     {
        0x4a17b156,
        0x738bec38,
        0xcd56f3c6,
        0x9732147f,
        0x12c660a3
     };
   const char *s1 = "Hello ";
   const char *s2 = "World";

   for (i = 0; i < sizeof(data) / sizeof(data[0]); ++i)
     {
        ret = eina_crc(data[i], strlen(data[i]), seed, EINA_TRUE);
        fail_if(ret != result[i]);
     }

   ret = eina_crc(s1, strlen(s1), 0xffffffff, EINA_TRUE);
   ret = eina_crc(s2, strlen(s2), ret, EINA_FALSE);
   fail_if(ret != result[0]);
}
END_TEST

void eina_test_crc(TCase *tc)
{
   tcase_add_test(tc, eina_crc_simple);
}