AUnit  1.2.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, long long lhs,
93  const char* opName, bool (*op)(long long lhs, long long rhs),
94  long long rhs);
95 
96  bool assertion(const char* file, uint16_t line, unsigned long long lhs,
97  const char* opName,
98  bool (*op)(unsigned long long lhs, unsigned long long rhs),
99  unsigned long long rhs);
100 
101  bool assertion(const char* file, uint16_t line, double lhs,
102  const char* opName, bool (*op)(double lhs, double rhs),
103  double rhs);
104 
105  bool assertion(const char* file, uint16_t line, const char* lhs,
106  const char* opName, bool (*op)(const char* lhs, const char* rhs),
107  const char* rhs);
108 
109  bool assertion(const char* file, uint16_t line, const char* lhs,
110  const char* opName, bool (*op)(const char* lhs, const String& rhs),
111  const String& rhs);
112 
113  bool assertion(const char* file, uint16_t line, const char* lhs,
114  const char* opName,
115  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
116  const __FlashStringHelper* rhs);
117 
118  bool assertion(const char* file, uint16_t line, const String& lhs,
119  const char* opName, bool (*op)(const String& lhs, const char* rhs),
120  const char* rhs);
121 
122  bool assertion(const char* file, uint16_t line, const String& lhs,
123  const char* opName, bool (*op)(const String& lhs, const String& rhs),
124  const String& rhs);
125 
126  bool assertion(const char* file, uint16_t line, const String& lhs,
127  const char* opName,
128  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
129  const __FlashStringHelper* rhs);
130 
131  bool assertion(const char* file, uint16_t line,
132  const __FlashStringHelper* lhs, const char* opName,
133  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
134  const char* rhs);
135 
136  bool assertion(const char* file, uint16_t line,
137  const __FlashStringHelper* lhs, const char* opName,
138  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
139  const String& rhs);
140 
141  bool assertion(const char* file, uint16_t line,
142  const __FlashStringHelper* lhs, const char* opName,
143  bool (*op)(const __FlashStringHelper* lhs,
144  const __FlashStringHelper* rhs),
145  const __FlashStringHelper* rhs);
146 
147  bool assertionNear(const char* file, uint16_t line,
148  int lhs, int rhs, int error, const char* opName,
149  bool (*compareNear)(int lhs, int rhs, int error));
150 
151  bool assertionNear(const char* file, uint16_t line,
152  unsigned int lhs, unsigned int rhs, unsigned int error,
153  const char* opName,
154  bool (*compareNear)(
155  unsigned int lhs, unsigned int rhs, unsigned int error));
156 
157  bool assertionNear(const char* file, uint16_t line,
158  long lhs, long rhs, long error, const char* opName,
159  bool (*compareNear)(long lhs, long rhs, long error));
160 
161  bool assertionNear(const char* file, uint16_t line,
162  unsigned long lhs, unsigned long rhs, unsigned long error,
163  const char* opName,
164  bool (*compareNear)(
165  unsigned long lhs, unsigned long rhs, unsigned long error));
166 
167  bool assertionNear(const char* file, uint16_t line,
168  double lhs, double rhs, double error, const char* opName,
169  bool (*compareNear)(double lhs, double rhs, double error));
170 
171  // Verbose versions of above.
172 
173  bool assertionBoolVerbose(const char* file, uint16_t line, bool arg,
174  const __FlashStringHelper* argString, bool value);
175 
176  bool assertionVerbose(const char* file, uint16_t line, bool lhs,
177  const __FlashStringHelper* lhsString, const char* opName,
178  bool (*op)(bool lhs, bool rhs),
179  bool rhs, const __FlashStringHelper* rhsString);
180 
181  bool assertionVerbose(const char* file, uint16_t line, char lhs,
182  const __FlashStringHelper* lhsString, const char* opName,
183  bool (*op)(char lhs, char rhs),
184  char rhs, const __FlashStringHelper* rhsString);
185 
186  bool assertionVerbose(const char* file, uint16_t line, int lhs,
187  const __FlashStringHelper* lhsString, const char* opName,
188  bool (*op)(int lhs, int rhs),
189  int rhs, const __FlashStringHelper* rhsString);
190 
191  bool assertionVerbose(const char* file, uint16_t line, unsigned int lhs,
192  const __FlashStringHelper* lhsString, const char* opName,
193  bool (*op)(unsigned int lhs, unsigned int rhs),
194  unsigned int rhs, const __FlashStringHelper* rhsString);
195 
196  bool assertionVerbose(const char* file, uint16_t line, long lhs,
197  const __FlashStringHelper* lhsString, const char* opName,
198  bool (*op)(long lhs, long rhs),
199  long rhs, const __FlashStringHelper* rhsString);
200 
201  bool assertionVerbose(const char* file, uint16_t line, unsigned long lhs,
202  const __FlashStringHelper* lhsString, const char* opName,
203  bool (*op)(unsigned long lhs, unsigned long rhs),
204  unsigned long rhs, const __FlashStringHelper* rhsString);
205 
206  bool assertionVerbose(const char* file, uint16_t line, long long lhs,
207  const __FlashStringHelper* lhsString, const char* opName,
208  bool (*op)(long long lhs, long long rhs),
209  long long rhs, const __FlashStringHelper* rhsString);
210 
211  bool assertionVerbose(const char* file, uint16_t line,
212  unsigned long long lhs,
213  const __FlashStringHelper* lhsString, const char* opName,
214  bool (*op)(unsigned long long lhs, unsigned long long rhs),
215  unsigned long long rhs, const __FlashStringHelper* rhsString);
216 
217  bool assertionVerbose(const char* file, uint16_t line, double lhs,
218  const __FlashStringHelper* lhsString, const char* opName,
219  bool (*op)(double lhs, double rhs),
220  double rhs, const __FlashStringHelper* rhsString);
221 
222  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
223  const __FlashStringHelper* lhsString, const char* opName,
224  bool (*op)(const char* lhs, const char* rhs),
225  const char* rhs, const __FlashStringHelper* rhsString);
226 
227  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
228  const __FlashStringHelper* lhsString, const char* opName,
229  bool (*op)(const char* lhs, const String& rhs),
230  const String& rhs, const __FlashStringHelper* rhsString);
231 
232  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
233  const __FlashStringHelper* lhsString, const char* opName,
234  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
235  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
236 
237  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
238  const __FlashStringHelper* lhsString, const char* opName,
239  bool (*op)(const String& lhs, const char* rhs),
240  const char* rhs, const __FlashStringHelper* rhsString);
241 
242  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
243  const __FlashStringHelper* lhsString, const char* opName,
244  bool (*op)(const String& lhs, const String& rhs),
245  const String& rhs, const __FlashStringHelper* rhsString);
246 
247  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
248  const __FlashStringHelper* lhsString, const char* opName,
249  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
250  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
251 
252  bool assertionVerbose(const char* file, uint16_t line,
253  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
254  const char* opName,
255  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
256  const char* rhs, const __FlashStringHelper* rhsString);
257 
258  bool assertionVerbose(const char* file, uint16_t line,
259  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
260  const char* opName,
261  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
262  const String& rhs, const __FlashStringHelper* rhsString);
263 
264  bool assertionVerbose(const char* file, uint16_t line,
265  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
266  const char* opName,
267  bool (*op)(const __FlashStringHelper* lhs,
268  const __FlashStringHelper* rhs),
269  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
270 
271  bool assertionNearVerbose(const char* file, uint16_t line,
272  int lhs, const __FlashStringHelper* lhsString,
273  int rhs, const __FlashStringHelper* rhsString,
274  int error, const __FlashStringHelper* errorString,
275  const char* opName,
276  bool (*compareNear)(int lhs, int rhs, int error));
277 
278  bool assertionNearVerbose(const char* file, uint16_t line,
279  unsigned int lhs, const __FlashStringHelper* lhsString,
280  unsigned int rhs, const __FlashStringHelper* rhsString,
281  unsigned int error, const __FlashStringHelper* errorString,
282  const char* opName,
283  bool (*compareNear)(
284  unsigned int lhs, unsigned int rhs, unsigned int error));
285 
286  bool assertionNearVerbose(const char* file, uint16_t line,
287  long lhs, const __FlashStringHelper* lhsString,
288  long rhs, const __FlashStringHelper* rhsString,
289  long error, const __FlashStringHelper* errorString,
290  const char* opName,
291  bool (*compareNear)(long lhs, long rhs, long error));
292 
293  bool assertionNearVerbose(const char* file, uint16_t line,
294  unsigned long lhs, const __FlashStringHelper* lhsString,
295  unsigned long rhs, const __FlashStringHelper* rhsString,
296  unsigned long error, const __FlashStringHelper* errorString,
297  const char* opName,
298  bool (*compareNear)(
299  unsigned long lhs, unsigned long rhs, unsigned long error));
300 
301  bool assertionNearVerbose(const char* file, uint16_t line,
302  double lhs, const __FlashStringHelper* lhsString,
303  double rhs, const __FlashStringHelper* rhsString,
304  double error, const __FlashStringHelper* errorString,
305  const char* opName,
306  bool (*compareNear)(double lhs, double rhs, double error));
307 
308  private:
309  // Disable copy-constructor and assignment operator
310  Assertion(const Assertion&) = delete;
311  Assertion& operator=(const Assertion&) = delete;
312 };
313 
314 }
315 
316 #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:183
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