]> begriffs open source - freertos/blob - FreeRTOS-Plus/Source/CyaSSL/tests/unit.h
Update CyaSSL to latest version.
[freertos] / FreeRTOS-Plus / Source / CyaSSL / tests / unit.h
1 /* unit.h unit tests driver */
2
3 #ifndef CyaSSL_UNIT_H
4 #define CyaSSL_UNIT_H
5
6 #include <cyassl/test.h>    /* thread and tcp stuff */
7
8 #define Fail(description, result) do {                                         \
9     printf("\nERROR - %s line %d failed with:", __FILE__, __LINE__);           \
10     printf("\n\n    test:   "); printf description;                            \
11     printf("\n\n    result: "); printf result;                                 \
12     abort();                                                                   \
13 } while(0)
14
15 #define Assert(test, description, result) if (!(test)) Fail(description, result)
16
17 #define AssertTrue(x)    Assert( (x), ("%s is true",     #x), (#x " => FALSE"))
18 #define AssertFalse(x)   Assert(!(x), ("%s is false",    #x), (#x " => TRUE"))
19 #define AssertNotNull(x) Assert( (x), ("%s is not null", #x), (#x " => NULL"))
20
21 #define AssertNull(x) do {                                                     \
22     void* _x = (void *) (x);                                                   \
23                                                                                \
24     Assert(!_x, ("%s is null", #x), (#x " => %p", _x));                        \
25 } while(0)
26
27 #define AssertInt(x, y, op, er) do {                                           \
28     int _x = x;                                                                \
29     int _y = y;                                                                \
30                                                                                \
31     Assert(_x op _y, ("%s " #op " %s", #x, #y), ("%d " #er " %d", _x, _y));    \
32 } while(0)
33
34 #define AssertIntEQ(x, y) AssertInt(x, y, ==, !=)
35 #define AssertIntNE(x, y) AssertInt(x, y, !=, ==)
36 #define AssertIntGT(x, y) AssertInt(x, y,  >, <=)
37 #define AssertIntLT(x, y) AssertInt(x, y,  <, >=)
38 #define AssertIntGE(x, y) AssertInt(x, y, >=,  <)
39 #define AssertIntLE(x, y) AssertInt(x, y, <=,  >)
40
41 #define AssertStr(x, y, op, er) do {                                           \
42     const char* _x = x;                                                        \
43     const char* _y = y;                                                        \
44     int   _z = strcmp(_x, _y);                                                 \
45                                                                                \
46     Assert(_z op 0, ("%s " #op " %s", #x, #y),                                 \
47                                             ("\"%s\" " #er " \"%s\"", _x, _y));\
48 } while(0)
49
50 #define AssertStrEQ(x, y) AssertStr(x, y, ==, !=)
51 #define AssertStrNE(x, y) AssertStr(x, y, !=, ==)
52 #define AssertStrGT(x, y) AssertStr(x, y,  >, <=)
53 #define AssertStrLT(x, y) AssertStr(x, y,  <, >=)
54 #define AssertStrGE(x, y) AssertStr(x, y, >=,  <)
55 #define AssertStrLE(x, y) AssertStr(x, y, <=,  >)
56
57
58 int ApiTest(void);
59 int SuiteTest(void);
60 int HashTest(void);
61
62
63 #endif /* CyaSSL_UNIT_H */
64