Some typo fixes and other minor improvements.
[AROS.git] / test / icon / testframe.h
blob9b4604dd4ea293c66b06f38585f9790c17b63f02
1 /*
2 * Copyright (C) 2011-2014, The AROS Development Team. All rights reserved.
3 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
5 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
6 */
8 #ifndef TESTFRAME_H
9 #define TESTFRAME_H
11 #include <proto/alib.h>
12 #include <proto/exec.h>
13 #include <proto/dos.h>
15 #include <dos/stdio.h>
16 #include <exec/lists.h>
18 #ifdef __mc68000
19 /* For compatability with AOS, our test reference,
20 * use this SPrintf()
22 static AROS_UFH2(VOID, _SPutC,
23 AROS_UFHA(BYTE, c, D0),
24 AROS_UFHA(BYTE **, ptr, A3))
26 AROS_USERFUNC_INIT
28 **ptr = c;
30 (*ptr)++;
32 AROS_USERFUNC_EXIT
35 VOID SPrintf( char *target, const char *format, ...)
37 RawDoFmt( format, (APTR)&(((ULONG *)&format)[1]), _SPutC, &target);
39 #else
40 #define SPrintf(target,format,args...) __sprintf(target,format ,##args )
41 #endif
43 #define TESTING_BEGINS() \
44 do { \
45 int tests = 0, tests_failed = 0;
47 #define TESTING_ENDS() \
48 if (tests_failed == 0) Printf("All %ld tests passed\n", (LONG)tests); \
49 else Printf("%ld of %ld tests failed\n", (LONG)tests_failed, (LONG)tests); \
50 Flush(Output()); \
51 return (tests_failed == 0) ? RETURN_OK : RETURN_FAIL; \
52 } while (0)
55 #define TEST_START(name) do { \
56 CONST_STRPTR test_name = #name ; \
57 struct List expr_list; \
58 int failed = 0; \
59 int subtest = 0; \
60 tests++; \
61 NEWLIST(&expr_list);
63 #define _STRINGED(x) #x
64 #define STRINGED(x) _STRINGED(x)
66 #define VERIFY_EQ(retval, expected) \
67 do { \
68 __typeof__(retval) val = retval; \
69 subtest++; \
70 if (val != (expected)) { \
71 static char buff[128]; \
72 static struct Node expr_node; \
73 SPrintf(buff, "%ld.%ld %s (%ld) != %ld", tests, subtest, STRINGED(retval), (LONG)(IPTR)val, (LONG)(IPTR)expected); \
74 expr_node.ln_Name = buff; \
75 AddTail(&expr_list, &expr_node); \
76 failed |= 1; \
77 } \
78 } while (0)
80 #define VERIFY_NEQ(retval, expected) \
81 do { \
82 __typeof__(retval) val = retval; \
83 subtest++; \
84 if (val == (expected)) { \
85 static char buff[128]; \
86 static struct Node expr_node; \
87 SPrintf(buff, "%ld.%ld %s (%ld) == %ld", tests, subtest, STRINGED(retval) , (LONG)(IPTR)val, (LONG)(IPTR)expected); \
88 expr_node.ln_Name = buff; \
89 AddTail(&expr_list, &expr_node); \
90 failed |= 1; \
91 } \
92 } while (0)
94 #define VERIFY_RET(func, ret, reterr) \
95 do { \
96 SetIoErr(-1); \
97 VERIFY_EQ(func, ret); \
98 subtest--; \
99 VERIFY_EQ(IoErr(), reterr); \
100 } while (0)
102 #define TEST_END() \
103 (void)subtest; \
104 if (failed) { \
105 struct Node *node; \
106 tests_failed++; \
107 Printf("Test %ld: Failed (%s)\n", (LONG)tests, test_name); \
108 ForeachNode(&expr_list, node) { \
109 Printf("\t%s\n", node->ln_Name); \
112 } while (0)
114 #endif /* TESTFRAME_H */