AUnit
1.5.5
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
src
aunit
TestMacros.h
Go to the documentation of this file.
1
/*
2
MIT License
3
4
Copyright (c) 2018 Brian T. Park
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
25
// Significant portions of the design and implementation of this file came from
26
// https://github.com/mmurdoch/arduinounit/blob/master/src/ArduinoUnit.h
27
36
#ifndef AUNIT_TEST_MACROS_H
37
#define AUNIT_TEST_MACROS_H
38
39
#include <stdint.h>
40
#include <Arduino.h>
// F() macro
41
#include "
Flash.h
"
// AUNIT_F() macro
42
#include "FCString.h"
43
#include "TestOnce.h"
44
#include "TestAgain.h"
45
53
#define test(...) \
54
GET_TEST(__VA_ARGS__, TEST2, TEST1)(__VA_ARGS__)
55
56
#define GET_TEST(_1, _2, NAME, ...) NAME
57
58
#define TEST1(name) \
59
class test_##name : public aunit::TestOnce {\
60
public:\
61
test_##name();\
62
void once() override;\
63
} test_##name##_instance;\
64
test_##name :: test_##name() {\
65
init(AUNIT_F(#name)); \
66
}\
67
void test_##name :: once()
68
69
#define TEST2(suiteName, name) \
70
class suiteName##_##name : public aunit::TestOnce {\
71
public:\
72
suiteName##_##name();\
73
void once() override;\
74
} suiteName##_##name##_instance;\
75
suiteName##_##name :: suiteName##_##name() {\
76
init(AUNIT_F(#suiteName "_" #name)); \
77
}\
78
void suiteName##_##name :: once()
79
89
#define testing(...) \
90
GET_TESTING(__VA_ARGS__, TESTING2, TESTING1)(__VA_ARGS__)
91
92
#define GET_TESTING(_1, _2, NAME, ...) NAME
93
94
#define TESTING1(name) \
95
class test_##name : public aunit::TestAgain {\
96
public:\
97
test_##name();\
98
void again() override;\
99
} test_##name##_instance;\
100
test_##name :: test_##name() {\
101
init(AUNIT_F(#name));\
102
}\
103
void test_##name :: again()
104
105
#define TESTING2(suiteName, name) \
106
class suiteName##_##name : public aunit::TestAgain {\
107
public:\
108
suiteName##_##name();\
109
void again() override;\
110
} suiteName##_##name##_instance;\
111
suiteName##_##name :: suiteName##_##name() {\
112
init(AUNIT_F(#suiteName "_" #name));\
113
}\
114
void suiteName##_##name :: again()
115
125
#define externTest(...) \
126
GET_EXTERN_TEST(__VA_ARGS__, EXTERN_TEST2, EXTERN_TEST1)(__VA_ARGS__)
127
128
#define GET_EXTERN_TEST(_1, _2, NAME, ...) NAME
129
130
#define EXTERN_TEST1(name) \
131
class test_##name : public aunit::TestOnce {\
132
public:\
133
test_##name();\
134
void once();\
135
};\
136
extern test_##name test_##name##_instance
137
138
#define EXTERN_TEST2(suiteName, name) \
139
class suiteName##_##name : public aunit::TestOnce {\
140
public:\
141
suiteName##_##name();\
142
void once();\
143
};\
144
extern suiteName##_##name suiteName##_##name##_instance
145
155
#define externTesting(...) \
156
GET_EXTERN_TESTING(__VA_ARGS__, EXTERN_TESTING2, EXTERN_TESTING1)(__VA_ARGS__)
157
158
#define GET_EXTERN_TESTING(_1, _2, NAME, ...) NAME
159
160
#define EXTERN_TESTING1(name) \
161
class test_ ## name : public aunit::TestAgain {\
162
public:\
163
test_ ## name();\
164
void again();\
165
};\
166
extern test_##name test_##name##_instance
167
168
#define EXTERN_TESTING2(suiteName, name) \
169
class suiteName##_ ## name : public aunit::TestAgain {\
170
public:\
171
suiteName##_ ## name();\
172
void again();\
173
};\
174
extern suiteName##_##name suiteName##_##name##_instance
175
181
#define testF(testClass, name) \
182
class testClass ## _ ## name : public testClass {\
183
public:\
184
testClass ## _ ## name();\
185
void once() override;\
186
} testClass ## _ ## name ## _instance;\
187
testClass ## _ ## name :: testClass ## _ ## name() {\
188
init(AUNIT_F(#testClass "_" #name));\
189
}\
190
void testClass ## _ ## name :: once()
191
200
#define testingF(testClass, name) \
201
class testClass ## _ ## name : public testClass {\
202
public:\
203
testClass ## _ ## name();\
204
void again() override;\
205
} testClass ## _ ## name ## _instance;\
206
testClass ## _ ## name :: testClass ## _ ## name() {\
207
init(AUNIT_F(#testClass "_" #name));\
208
}\
209
void testClass ## _ ## name :: again()
210
216
#define externTestF(testClass, name) \
217
class testClass ## _ ## name : public testClass {\
218
public:\
219
testClass ## _ ## name();\
220
void once() override;\
221
};\
222
extern testClass ## _ ## name testClass##_##name##_instance
223
230
#define externTestingF(testClass, name) \
231
class testClass ## _ ## name : public testClass {\
232
public:\
233
testClass ## _ ## name();\
234
void again() override;\
235
};\
236
extern testClass ## _ ## name testClass##_##name##_instance
237
238
#endif
Flash.h
Generated by
1.8.17