AUnit
1.1
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
46
// On the ESP8266 platform, the F() string cannot be placed in an inline
47
// context, because it interferes with other PROGMEM strings. See
48
// https://github.com/esp8266/Arduino/issues/3369. The solution was to move the
49
// constructor definition out from an inline function into a normal function
50
// defined outside of the class declaration. Unfortunately, if the user code
51
// has any other usage of F() in an inline context, those interfere with the
52
// F() used below. I have abandoned supporting the F() macro for these test*()
53
// macros on the ESP8266.
54
56
#define test(name) struct test_ ## name : aunit::TestOnce {\
57
test_ ## name();\
58
virtual void once() override;\
59
} test_ ## name ## _instance;\
60
test_ ## name :: test_ ## name() {\
61
init(AUNIT_F(#name)); \
62
}\
63
void test_ ## name :: once()
64
70
#define testing(name) struct test_ ## name : aunit::TestAgain {\
71
test_ ## name();\
72
virtual void again() override;\
73
} test_ ## name ## _instance;\
74
test_ ## name :: test_ ## name() {\
75
init(AUNIT_F(#name));\
76
}\
77
void test_ ## name :: again()
78
84
#define externTest(name) struct test_ ## name : aunit::TestOnce {\
85
test_ ## name();\
86
void once();\
87
};\
88
extern test_##name test_##name##_instance
89
96
#define externTesting(name) struct test_ ## name : aunit::TestAgain {\
97
test_ ## name();\
98
void again();\
99
};\
100
extern test_##name test_##name##_instance
101
107
#define testF(testClass, name) \
108
struct testClass ## _ ## name : testClass {\
109
testClass ## _ ## name();\
110
virtual void once() override;\
111
} testClass ## _ ## name ## _instance;\
112
testClass ## _ ## name :: testClass ## _ ## name() {\
113
init(AUNIT_F(#testClass "_" #name));\
114
}\
115
void testClass ## _ ## name :: once()
116
122
#define testingF(testClass, name) \
123
struct testClass ## _ ## name : testClass {\
124
testClass ## _ ## name();\
125
virtual void again() override;\
126
} testClass ## _ ## name ## _instance;\
127
testClass ## _ ## name :: testClass ## _ ## name() {\
128
init(AUNIT_F(#testClass "_" #name));\
129
}\
130
void testClass ## _ ## name :: again()
131
137
#define externTestF(testClass, name) \
138
struct testClass ## _ ## name : testClass {\
139
testClass ## _ ## name();\
140
virtual void once() override;\
141
};\
142
extern testClass ## _ ## name testClass##_##name##_instance
143
150
#define externTestingF(testClass, name) \
151
struct testClass ## _ ## name : testClass {\
152
testClass ## _ ## name();\
153
virtual void again() override;\
154
};\
155
extern testClass ## _ ## name testClass##_##name##_instance
156
157
#endif
Flash.h
Various macros to smooth over the differences among the various platforms with regards to their suppo...
Generated by
1.8.13