AUnit
0.4.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
src
aunit
TestMacro.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
32
#ifndef AUNIT_TEST_MACRO_H
33
#define AUNIT_TEST_MACRO_H
34
35
#include <stdint.h>
36
#include <Arduino.h>
// F() macro
37
#include "FCString.h"
38
#include "TestOnce.h"
39
#include "TestAgain.h"
40
41
class
__FlashStringHelper;
42
43
// On the ESP8266 platform, The F() string cannot be placed in an inline
44
// context, because it interferes with other PROGMEM strings. See
45
// https://github.com/esp8266/Arduino/issues/3369. The solution was to move the
46
// constructor definition out from an inline function into a normal function
47
// defined outside of the class declaration..
48
50
#define test(name) struct test_ ## name : aunit::TestOnce {\
51
test_ ## name();\
52
virtual void once() override;\
53
} test_ ## name ## _instance;\
54
test_ ## name :: test_ ## name() {\
55
init(F(#name)); \
56
}\
57
void test_ ## name :: once()
58
64
#define testing(name) struct test_ ## name : aunit::TestAgain {\
65
test_ ## name();\
66
virtual void again() override;\
67
} test_ ## name ## _instance;\
68
test_ ## name :: test_ ## name() {\
69
init(F(#name));\
70
}\
71
void test_ ## name :: again()
72
78
#define externTest(name) struct test_ ## name : aunit::TestOnce {\
79
test_ ## name();\
80
void once();\
81
};\
82
extern test_##name test_##name##_instance
83
90
#define externTesting(name) struct test_ ## name : aunit::TestAgain {\
91
test_ ## name();\
92
void again();\
93
};\
94
extern test_##name test_##name##_instance
95
101
#define testF(test_class, name) \
102
struct test_class ## _ ## name : test_class {\
103
test_class ## _ ## name();\
104
virtual void once() override;\
105
} test_class ## _ ## name ## _instance;\
106
test_class ## _ ## name :: test_class ## _ ## name() {\
107
init(F(#test_class "_" #name));\
108
}\
109
void test_class ## _ ## name :: once()
110
116
#define testingF(test_class, name) \
117
struct test_class ## _ ## name : test_class {\
118
test_class ## _ ## name();\
119
virtual void again() override;\
120
} test_class ## _ ## name ## _instance;\
121
test_class ## _ ## name :: test_class ## _ ## name() {\
122
init(F(#test_class "_" #name));\
123
}\
124
void test_class ## _ ## name :: again()
125
131
#define externTestF(test_class, name) \
132
struct test_class ## _ ## name : test_class {\
133
test_class ## _ ## name();\
134
virtual void once() override;\
135
};\
136
extern test_class ## _ ## name test_class##_##name##_instance
137
144
#define externTestingF(test_class, name) \
145
struct test_class ## _ ## name : test_class {\
146
test_class ## _ ## name();\
147
virtual void again() override;\
148
};\
149
extern test_class ## _ ## name test_class##_##name##_instance
150
151
#endif
Generated by
1.8.14