AUnit  0.5.0
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  bool assertionBool(const char* file, uint16_t line, bool arg,
64  bool value);
65 
66  bool assertion(const char* file, uint16_t line, bool lhs,
67  const char* opName, bool (*op)(bool lhs, bool rhs),
68  bool rhs);
69 
70  bool assertion(const char* file, uint16_t line, char lhs,
71  const char* opName, bool (*op)(char lhs, char rhs),
72  char rhs);
73 
74  bool assertion(const char* file, uint16_t line, int lhs,
75  const char* opName, bool (*op)(int lhs, int rhs),
76  int rhs);
77 
78  bool assertion(const char* file, uint16_t line, unsigned int lhs,
79  const char* opName, bool (*op)(unsigned int lhs, unsigned int rhs),
80  unsigned int rhs);
81 
82  bool assertion(const char* file, uint16_t line, long lhs,
83  const char* opName, bool (*op)(long lhs, long rhs),
84  long rhs);
85 
86  bool assertion(const char* file, uint16_t line, unsigned long lhs,
87  const char* opName, bool (*op)(unsigned long lhs, unsigned long rhs),
88  unsigned long rhs);
89 
90  bool assertion(const char* file, uint16_t line, double lhs,
91  const char* opName, bool (*op)(double lhs, double rhs),
92  double rhs);
93 
94  bool assertion(const char* file, uint16_t line, const char* lhs,
95  const char* opName, bool (*op)(const char* lhs, const char* rhs),
96  const char* rhs);
97 
98  bool assertion(const char* file, uint16_t line, const char* lhs,
99  const char *opName, bool (*op)(const char* lhs, const String& rhs),
100  const String& rhs);
101 
102  bool assertion(const char* file, uint16_t line, const char* lhs,
103  const char *opName,
104  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
105  const __FlashStringHelper* rhs);
106 
107  bool assertion(const char* file, uint16_t line, const String& lhs,
108  const char *opName, bool (*op)(const String& lhs, const char* rhs),
109  const char* rhs);
110 
111  bool assertion(const char* file, uint16_t line, const String& lhs,
112  const char *opName, bool (*op)(const String& lhs, const String& rhs),
113  const String& rhs);
114 
115  bool assertion(const char* file, uint16_t line, const String& lhs,
116  const char *opName,
117  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
118  const __FlashStringHelper* rhs);
119 
120  bool assertion(const char* file, uint16_t line,
121  const __FlashStringHelper* lhs, const char *opName,
122  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
123  const char* rhs);
124 
125  bool assertion(const char* file, uint16_t line,
126  const __FlashStringHelper* lhs, const char *opName,
127  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
128  const String& rhs);
129 
130  bool assertion(const char* file, uint16_t line,
131  const __FlashStringHelper* lhs, const char *opName,
132  bool (*op)(const __FlashStringHelper* lhs,
133  const __FlashStringHelper* rhs),
134  const __FlashStringHelper* rhs);
135 
136  // Verbose versions of above.
137 
138  bool assertionBoolVerbose(const char* file, uint16_t line, bool arg,
139  internal::FlashStringType argString, bool value);
140 
141  bool assertionVerbose(const char* file, uint16_t line, bool lhs,
142  internal::FlashStringType lhsString, const char* opName,
143  bool (*op)(bool lhs, bool rhs),
144  bool rhs, internal::FlashStringType rhsString);
145 
146  bool assertionVerbose(const char* file, uint16_t line, char lhs,
147  internal::FlashStringType lhsString, const char* opName,
148  bool (*op)(char lhs, char rhs),
149  char rhs, internal::FlashStringType rhsString);
150 
151  bool assertionVerbose(const char* file, uint16_t line, int lhs,
152  internal::FlashStringType lhsString, const char* opName,
153  bool (*op)(int lhs, int rhs),
154  int rhs, internal::FlashStringType rhsString);
155 
156  bool assertionVerbose(const char* file, uint16_t line, unsigned int lhs,
157  internal::FlashStringType lhsString, const char* opName,
158  bool (*op)(unsigned int lhs, unsigned int rhs),
159  unsigned int rhs, internal::FlashStringType rhsString);
160 
161  bool assertionVerbose(const char* file, uint16_t line, long lhs,
162  internal::FlashStringType lhsString, const char* opName,
163  bool (*op)(long lhs, long rhs),
164  long rhs, internal::FlashStringType rhsString);
165 
166  bool assertionVerbose(const char* file, uint16_t line, unsigned long lhs,
167  internal::FlashStringType lhsString, const char* opName,
168  bool (*op)(unsigned long lhs, unsigned long rhs),
169  unsigned long rhs, internal::FlashStringType rhsString);
170 
171  bool assertionVerbose(const char* file, uint16_t line, double lhs,
172  internal::FlashStringType lhsString, const char* opName,
173  bool (*op)(double lhs, double rhs),
174  double rhs, internal::FlashStringType rhsString);
175 
176  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
177  internal::FlashStringType lhsString, const char* opName,
178  bool (*op)(const char* lhs, const char* rhs),
179  const char* rhs, internal::FlashStringType rhsString);
180 
181  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
182  internal::FlashStringType lhsString, const char *opName,
183  bool (*op)(const char* lhs, const String& rhs),
184  const String& rhs, internal::FlashStringType rhsString);
185 
186  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
187  internal::FlashStringType lhsString, const char *opName,
188  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
189  const __FlashStringHelper* rhs, internal::FlashStringType rhsString);
190 
191  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
192  internal::FlashStringType lhsString, const char *opName,
193  bool (*op)(const String& lhs, const char* rhs),
194  const char* rhs, internal::FlashStringType rhsString);
195 
196  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
197  internal::FlashStringType lhsString, const char *opName,
198  bool (*op)(const String& lhs, const String& rhs),
199  const String& rhs, internal::FlashStringType rhsString);
200 
201  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
202  internal::FlashStringType lhsString, const char *opName,
203  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
204  const __FlashStringHelper* rhs, internal::FlashStringType rhsString);
205 
206  bool assertionVerbose(const char* file, uint16_t line,
207  const __FlashStringHelper* lhs, internal::FlashStringType lhsString,
208  const char *opName,
209  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
210  const char* rhs, internal::FlashStringType rhsString);
211 
212  bool assertionVerbose(const char* file, uint16_t line,
213  const __FlashStringHelper* lhs, internal::FlashStringType lhsString,
214  const char *opName,
215  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
216  const String& rhs, internal::FlashStringType rhsString);
217 
218  bool assertionVerbose(const char* file, uint16_t line,
219  const __FlashStringHelper* lhs, internal::FlashStringType lhsString,
220  const char *opName,
221  bool (*op)(const __FlashStringHelper* lhs,
222  const __FlashStringHelper* rhs),
223  const __FlashStringHelper* rhs, internal::FlashStringType rhsString);
224 
225  private:
226  // Disable copy-constructor and assignment operator
227  Assertion(const Assertion&) = delete;
228  Assertion& operator=(const Assertion&) = delete;
229 };
230 
231 }
232 
233 #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:116
An Assertion class is a subclass of Test and provides various overloaded assertion() functions...
Definition: Assertion.h:55
Flash strings (using F() macro) on the ESP8266 platform cannot be placed in an inline context...
Assertion()
Empty constructor.
Definition: Assertion.h:58