PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
test
PropWare
PropWareTests.h
Go to the documentation of this file.
1
26
#pragma once
27
28
#include <
PropWare/PropWare.h
>
29
#include <
PropWare/printer/printer.h
>
30
#include <PropWare/c++allocate.h>
31
32
#define protected public
33
#define private public
34
35
void
_runPropWareUnitTest (
bool
(*test) (
void
),
const
char
testName[],
36
const
bool
expectValue, uint8_t *failures) {
37
if
(expectValue == test())
38
pwOut
<<
"#\tSUCCESS: "
<< testName <<
'\n'
;
39
else
{
40
pwOut
<<
"#\t***FAIL: "
<< testName <<
'\n'
;
41
++(*failures);
42
}
43
}
44
45
#define MESSAGE(...) \
46
pwOut.printf("#\t- " __VA_ARGS__); \
47
pwOut << '\n';
48
49
#define START(testSuiteName) \
50
uint8_t failures = 0; \
51
const char suiteName[] = #testSuiteName; \
52
pwOut.println( \
53
"####################" \
54
"####################" \
55
"####################" \
56
"####################"); \
57
pwOut << "# Test suite: " << suiteName << '\n';
58
59
#define COMPLETE() \
60
if (failures) \
61
pwOut << "# Test FAILURES = " << (unsigned int) failures << '\n'; \
62
else \
63
pwOut.println("done..."); \
64
pwOut << (char) 0xff << (char) 0x00 << (char) failures; \
65
return failures
66
67
#define TEST(testName) \
68
bool testName ()
69
70
#define RUN_TEST(testName) \
71
_runPropWareUnitTest(testName, #testName, true, &failures)
72
73
#define EXPECT_FAIL(testName) \
74
_runPropWareUnitTest(testName, #testName, false, &failures)
75
76
#define FAIL(...) \
77
MESSAGE(__VA_ARGS__) \
78
_tearDown(); \
79
return false
80
81
#define ASSERT(actual) \
82
if (!(actual)) { \
83
pwOut << "#\t\t`ASSERT(" << #actual << ")`\n"; \
84
_tearDown(); \
85
return false; \
86
}
87
88
#define ASSERT_TRUE(actual) \
89
if (true == !(actual)) { \
90
pwOut << "#\t\t`ASSERT_TRUE(" << #actual << ")`\n"; \
91
_tearDown(); \
92
return false; \
93
}
94
95
#define ASSERT_FALSE(actual) \
96
if (false == !(actual)) { \
97
pwOut << "#\t\t`ASSERT_FALSE(" << #actual << ")`\n"; \
98
_tearDown(); \
99
return false; \
100
}
101
102
#define ASSERT_NULL(actual) \
103
if (NULL != (actual)) { \
104
pwOut << "#\t\t`ASSERT_NULL(" << #actual << ")`\n"; \
105
_tearDown(); \
106
return false; \
107
}
108
109
#define ASSERT_NOT_NULL(actual) \
110
if (NULL == (actual)) { \
111
pwOut << "#\t\t`ASSERT_NULL(" << #actual << ")`\n"; \
112
_tearDown(); \
113
return false; \
114
}
115
116
#define ASSERT_EQ(expected, actual) \
117
if ((expected) != (actual)) { \
118
pwOut << "#\t\t`ASSERT_EQ(" << #expected << ", " << #actual << ")`\n"; \
119
_tearDown(); \
120
return false; \
121
}
122
123
#define ASSERT_NEQ(lhs, rhs) \
124
if ((lhs) == (rhs)) { \
125
pwOut << "#\t\t`ASSERT_NEQ(" << #lhs << ", " << #rhs << ")`\n"; \
126
_tearDown(); \
127
return false; \
128
}
129
130
#define ASSERT_EQ_MSG(expected, actual) \
131
if ((expected) != (actual)) { \
132
pwOut << "#\t[" << __FILE__ << ':' << __LINE__ << "]\t"; \
133
pwOut << "Expected: `" << expected << "`; Acutal: `" << actual << "`\n"; \
134
_tearDown(); \
135
return false; \
136
}
137
138
#define ASSERT_NEQ_MSG(lhs, rhs) \
139
if ((lhs) == (rhs)) { \
140
pwOut << "#\t[" << __FILE__ << ':' << __LINE__ << "]\t"; \
141
pwOut << "Expected mismatch. Got: `" << lhs << "` == `" << rhs << "`\n"; \
142
_tearDown(); \
143
return false; \
144
}
145
146
#define SETUP \
147
void setUp ()
148
149
#define TEARDOWN \
150
void _tearDown ()
151
152
#define tearDown() \
153
_tearDown(); \
154
return true
pwOut
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
PropWare.h
printer.h
Generated on Sat Aug 27 2016 00:58:10 for PropWare by
1.8.12