]> git.sur5r.net Git - cc65/blob - include/unittest.h
Added "strrchr" optimizaion a matching unit test and tiny unit test framework. (Docum...
[cc65] / include / unittest.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                               unittest.h                                  */
4 /*                                                                           */
5 /*                        Unit test helper macros                            */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2017 Christian Krueger                                                        */
10 /*                                                                           */
11 /* This software is provided 'as-is', without any expressed or implied       */
12 /* warranty.  In no event will the authors be held liable for any damages    */
13 /* arising from the use of this software.                                    */
14 /*                                                                           */
15 /* Permission is granted to anyone to use this software for any purpose,     */
16 /* including commercial applications, and to alter it and redistribute it    */
17 /* freely, subject to the following restrictions:                            */
18 /*                                                                           */
19 /* 1. The origin of this software must not be misrepresented; you must not   */
20 /*    claim that you wrote the original software. If you use this software   */
21 /*    in a product, an acknowledgment in the product documentation would be  */
22 /*    appreciated but is not required.                                       */
23 /* 2. Altered source versions must be plainly marked as such, and must not   */
24 /*    be misrepresented as being the original software.                      */
25 /* 3. This notice may not be removed or altered from any source              */
26 /*    distribution.                                                          */
27 /*                                                                           */
28 /*****************************************************************************/
29
30 #ifndef _UNITTEST_H
31 #define _UNITTEST_H
32
33 #include <stdio.h>
34 #include <stdlib.h>
35
36 #ifndef COMMA
37 #define COMMA ,
38 #endif
39
40 #define TEST    int main(void) \
41                                 {\
42                                         printf("%s: ",__FILE__);
43
44 #define ENDTEST         printf("Passed\n"); \
45                                         return EXIT_SUCCESS; \
46                                 }
47
48 #define ASSERT_IsTrue(a,b)                                      if (!(a)) \
49                                                                                         {\
50                                                                                                 printf("Fail at line %d:\n",__LINE__);\
51                                                                                                 printf(b);\
52                                                                                                 printf("\n");\
53                                                                                                 printf("Expected status should be true but wasn't!\n");\
54                                                                                                 exit(EXIT_FAILURE);\
55                                                                                         }
56
57 #define ASSERT_IsFalse(a,b)                                     if ((a)) \
58                                                                                         {\
59                                                                                                 printf("Fail at line %d:\n",__LINE__);\
60                                                                                                 printf(b);\
61                                                                                                 printf("\n");\
62                                                                                                 printf("Expected status should be false but wasn't!\n");\
63                                                                                                 exit(EXIT_FAILURE);\
64                                                                                         }
65
66 #define ASSERT_AreEqual(a,b,c,d)                        if ((a) != (b)) \
67                                                                                         {\
68                                                                                                 printf("Fail at line %d:\n",__LINE__);\
69                                                                                                 printf(d);\
70                                                                                                 printf("\n");\
71                                                                                                 printf("Expected value: "c", but is "c"!\n", (a), (b));\
72                                                                                                 exit(EXIT_FAILURE);\
73                                                                                         }
74
75 #define ASSERT_AreNotEqual(a,b,c,d)                     if ((a) == (b)) \
76                                                                                         {\
77                                                                                                 printf("Fail at line %d:\n",__LINE__);\
78                                                                                                 printf(d);\
79                                                                                                 printf("\n");\
80                                                                                                 printf("Expected value not: "c", but is "c"!\n", (a), (b));\
81                                                                                                 exit(EXIT_FAILURE);\
82                                                                                         }
83
84 /* End of unittest.h */
85 #endif
86
87
88
89