AUnit  1.1
Unit testing framework for Arduino platforms inspired by ArduinoUnit and Google Test.
Assertion.h
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 #ifndef AUNIT_ASSERTION_H
26 #define AUNIT_ASSERTION_H
27 
28 #include "Flash.h"
29 #include "Test.h"
30 
31 class __FlashStringHelper;
32 class String;
33 
34 namespace aunit {
35 
55 class Assertion: public Test {
56  protected:
58  Assertion() {}
59 
61  bool isOutputEnabled(bool ok);
62 
63  // Terse assertions. Prints only the argument values.
64 
65  bool assertionBool(const char* file, uint16_t line, bool arg,
66  bool value);
67 
68  bool assertion(const char* file, uint16_t line, bool lhs,
69  const char* opName, bool (*op)(bool lhs, bool rhs),
70  bool rhs);
71 
72  bool assertion(const char* file, uint16_t line, char lhs,
73  const char* opName, bool (*op)(char lhs, char rhs),
74  char rhs);
75 
76  bool assertion(const char* file, uint16_t line, int lhs,
77  const char* opName, bool (*op)(int lhs, int rhs),
78  int rhs);
79 
80  bool assertion(const char* file, uint16_t line, unsigned int lhs,
81  const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
82  unsigned int rhs);
83 
84  bool assertion(const char* file, uint16_t line, long lhs,
85  const char* opName, bool (*op)(long lhs, long rhs),
86  long rhs);
87 
88  bool assertion(const char* file, uint16_t line, unsigned long lhs,
89  const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
90  unsigned long rhs);
91 
92  bool assertion(const char* file, uint16_t line, double lhs,
93  const char* opName, bool (*op)(double lhs, double rhs),
94  double rhs);
95 
96  bool assertion(const char* file, uint16_t line, const char* lhs,
97  const char* opName, bool (*op)(const char* lhs, const char* rhs),
98  const char* rhs);
99 
100  bool assertion(const char* file, uint16_t line, const char* lhs,
101  const char* opName, bool (*op)(const char* lhs, const String& rhs),
102  const String& rhs);
103 
104  bool assertion(const char* file, uint16_t line, const char* lhs,
105  const char* opName,
106  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
107  const __FlashStringHelper* rhs);
108 
109  bool assertion(const char* file, uint16_t line, const String& lhs,
110  const char* opName, bool (*op)(const String& lhs, const char* rhs),
111  const char* rhs);
112 
113  bool assertion(const char* file, uint16_t line, const String& lhs,
114  const char* opName, bool (*op)(const String& lhs, const String& rhs),
115  const String& rhs);
116 
117  bool assertion(const char* file, uint16_t line, const String& lhs,
118  const char* opName,
119  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
120  const __FlashStringHelper* rhs);
121 
122  bool assertion(const char* file, uint16_t line,
123  const __FlashStringHelper* lhs, const char* opName,
124  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
125  const char* rhs);
126 
127  bool assertion(const char* file, uint16_t line,
128  const __FlashStringHelper* lhs, const char* opName,
129  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
130  const String& rhs);
131 
132  bool assertion(const char* file, uint16_t line,
133  const __FlashStringHelper* lhs, const char* opName,
134  bool (*op)(const __FlashStringHelper* lhs,
135  const __FlashStringHelper* rhs),
136  const __FlashStringHelper* rhs);
137 
138  bool assertionNear(const char* file, uint16_t line,
139  int lhs, int rhs, int error, const char* opName,
140  bool (*compareNear)(int lhs, int rhs, int error));
141 
142  bool assertionNear(const char* file, uint16_t line,
143  unsigned int lhs, unsigned int rhs, unsigned int error,
144  const char* opName,
145  bool (*compareNear)(
146  unsigned int lhs, unsigned int rhs, unsigned int error));
147 
148  bool assertionNear(const char* file, uint16_t line,
149  long lhs, long rhs, long error, const char* opName,
150  bool (*compareNear)(long lhs, long rhs, long error));
151 
152  bool assertionNear(const char* file, uint16_t line,
153  unsigned long lhs, unsigned long rhs, unsigned long error,
154  const char* opName,
155  bool (*compareNear)(
156  unsigned long lhs, unsigned long rhs, unsigned long error));
157 
158  bool assertionNear(const char* file, uint16_t line,
159  double lhs, double rhs, double error, const char* opName,
160  bool (*compareNear)(double lhs, double rhs, double error));
161 
162  // Verbose versions of above.
163 
164  bool assertionBoolVerbose(const char* file, uint16_t line, bool arg,
165  const __FlashStringHelper* argString, bool value);
166 
167  bool assertionVerbose(const char* file, uint16_t line, bool lhs,
168  const __FlashStringHelper* lhsString, const char* opName,
169  bool (*op)(bool lhs, bool rhs),
170  bool rhs, const __FlashStringHelper* rhsString);
171 
172  bool assertionVerbose(const char* file, uint16_t line, char lhs,
173  const __FlashStringHelper* lhsString, const char* opName,
174  bool (*op)(char lhs, char rhs),
175  char rhs, const __FlashStringHelper* rhsString);
176 
177  bool assertionVerbose(const char* file, uint16_t line, int lhs,
178  const __FlashStringHelper* lhsString, const char* opName,
179  bool (*op)(int lhs, int rhs),
180  int rhs, const __FlashStringHelper* rhsString);
181 
182  bool assertionVerbose(const char* file, uint16_t line, unsigned int lhs,
183  const __FlashStringHelper* lhsString, const char* opName,
184  bool (*op)(unsigned int lhs, unsigned int rhs),
185  unsigned int rhs, const __FlashStringHelper* rhsString);
186 
187  bool assertionVerbose(const char* file, uint16_t line, long lhs,
188  const __FlashStringHelper* lhsString, const char* opName,
189  bool (*op)(long lhs, long rhs),
190  long rhs, const __FlashStringHelper* rhsString);
191 
192  bool assertionVerbose(const char* file, uint16_t line, unsigned long lhs,
193  const __FlashStringHelper* lhsString, const char* opName,
194  bool (*op)(unsigned long lhs, unsigned long rhs),
195  unsigned long rhs, const __FlashStringHelper* rhsString);
196 
197  bool assertionVerbose(const char* file, uint16_t line, double lhs,
198  const __FlashStringHelper* lhsString, const char* opName,
199  bool (*op)(double lhs, double rhs),
200  double rhs, const __FlashStringHelper* rhsString);
201 
202  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
203  const __FlashStringHelper* lhsString, const char* opName,
204  bool (*op)(const char* lhs, const char* rhs),
205  const char* rhs, const __FlashStringHelper* rhsString);
206 
207  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
208  const __FlashStringHelper* lhsString, const char* opName,
209  bool (*op)(const char* lhs, const String& rhs),
210  const String& rhs, const __FlashStringHelper* rhsString);
211 
212  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
213  const __FlashStringHelper* lhsString, const char* opName,
214  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
215  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
216 
217  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
218  const __FlashStringHelper* lhsString, const char* opName,
219  bool (*op)(const String& lhs, const char* rhs),
220  const char* rhs, const __FlashStringHelper* rhsString);
221 
222  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
223  const __FlashStringHelper* lhsString, const char* opName,
224  bool (*op)(const String& lhs, const String& rhs),
225  const String& rhs, const __FlashStringHelper* rhsString);
226 
227  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
228  const __FlashStringHelper* lhsString, const char* opName,
229  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
230  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
231 
232  bool assertionVerbose(const char* file, uint16_t line,
233  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
234  const char* opName,
235  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
236  const char* rhs, const __FlashStringHelper* rhsString);
237 
238  bool assertionVerbose(const char* file, uint16_t line,
239  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
240  const char* opName,
241  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
242  const String& rhs, const __FlashStringHelper* rhsString);
243 
244  bool assertionVerbose(const char* file, uint16_t line,
245  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
246  const char* opName,
247  bool (*op)(const __FlashStringHelper* lhs,
248  const __FlashStringHelper* rhs),
249  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
250 
251  bool assertionNearVerbose(const char* file, uint16_t line,
252  int lhs, const __FlashStringHelper* lhsString,
253  int rhs, const __FlashStringHelper* rhsString,
254  int error, const __FlashStringHelper* errorString,
255  const char* opName,
256  bool (*compareNear)(int lhs, int rhs, int error));
257 
258  bool assertionNearVerbose(const char* file, uint16_t line,
259  unsigned int lhs, const __FlashStringHelper* lhsString,
260  unsigned int rhs, const __FlashStringHelper* rhsString,
261  unsigned int error, const __FlashStringHelper* errorString,
262  const char* opName,
263  bool (*compareNear)(
264  unsigned int lhs, unsigned int rhs, unsigned int error));
265 
266  bool assertionNearVerbose(const char* file, uint16_t line,
267  long lhs, const __FlashStringHelper* lhsString,
268  long rhs, const __FlashStringHelper* rhsString,
269  long error, const __FlashStringHelper* errorString,
270  const char* opName,
271  bool (*compareNear)(long lhs, long rhs, long error));
272 
273  bool assertionNearVerbose(const char* file, uint16_t line,
274  unsigned long lhs, const __FlashStringHelper* lhsString,
275  unsigned long rhs, const __FlashStringHelper* rhsString,
276  unsigned long error, const __FlashStringHelper* errorString,
277  const char* opName,
278  bool (*compareNear)(
279  unsigned long lhs, unsigned long rhs, unsigned long error));
280 
281  bool assertionNearVerbose(const char* file, uint16_t line,
282  double lhs, const __FlashStringHelper* lhsString,
283  double rhs, const __FlashStringHelper* rhsString,
284  double error, const __FlashStringHelper* errorString,
285  const char* opName,
286  bool (*compareNear)(double lhs, double rhs, double error));
287 
288  private:
289  // Disable copy-constructor and assignment operator
290  Assertion(const Assertion&) = delete;
291  Assertion& operator=(const Assertion&) = delete;
292 };
293 
294 }
295 
296 #endif
Base class of all test cases.
Definition: Test.h:43
bool isOutputEnabled(bool ok)
Returns true if an assertion message should be printed.
Definition: Assertion.cpp:138
An Assertion class is a subclass of Test and provides various overloaded assertion() functions...
Definition: Assertion.h:55
Various macros to smooth over the differences among the various platforms with regards to their suppo...
Assertion()
Empty constructor.
Definition: Assertion.h:58