AUnit  1.0.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  // 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  // Verbose versions of above.
139 
140  bool assertionBoolVerbose(const char* file, uint16_t line, bool arg,
141  const __FlashStringHelper* argString, bool value);
142 
143  bool assertionVerbose(const char* file, uint16_t line, bool lhs,
144  const __FlashStringHelper* lhsString, const char* opName,
145  bool (*op)(bool lhs, bool rhs),
146  bool rhs, const __FlashStringHelper* rhsString);
147 
148  bool assertionVerbose(const char* file, uint16_t line, char lhs,
149  const __FlashStringHelper* lhsString, const char* opName,
150  bool (*op)(char lhs, char rhs),
151  char rhs, const __FlashStringHelper* rhsString);
152 
153  bool assertionVerbose(const char* file, uint16_t line, int lhs,
154  const __FlashStringHelper* lhsString, const char* opName,
155  bool (*op)(int lhs, int rhs),
156  int rhs, const __FlashStringHelper* rhsString);
157 
158  bool assertionVerbose(const char* file, uint16_t line, unsigned int lhs,
159  const __FlashStringHelper* lhsString, const char* opName,
160  bool (*op)(unsigned int lhs, unsigned int rhs),
161  unsigned int rhs, const __FlashStringHelper* rhsString);
162 
163  bool assertionVerbose(const char* file, uint16_t line, long lhs,
164  const __FlashStringHelper* lhsString, const char* opName,
165  bool (*op)(long lhs, long rhs),
166  long rhs, const __FlashStringHelper* rhsString);
167 
168  bool assertionVerbose(const char* file, uint16_t line, unsigned long lhs,
169  const __FlashStringHelper* lhsString, const char* opName,
170  bool (*op)(unsigned long lhs, unsigned long rhs),
171  unsigned long rhs, const __FlashStringHelper* rhsString);
172 
173  bool assertionVerbose(const char* file, uint16_t line, double lhs,
174  const __FlashStringHelper* lhsString, const char* opName,
175  bool (*op)(double lhs, double rhs),
176  double rhs, const __FlashStringHelper* rhsString);
177 
178  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
179  const __FlashStringHelper* lhsString, const char* opName,
180  bool (*op)(const char* lhs, const char* rhs),
181  const char* rhs, const __FlashStringHelper* rhsString);
182 
183  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
184  const __FlashStringHelper* lhsString, const char *opName,
185  bool (*op)(const char* lhs, const String& rhs),
186  const String& rhs, const __FlashStringHelper* rhsString);
187 
188  bool assertionVerbose(const char* file, uint16_t line, const char* lhs,
189  const __FlashStringHelper* lhsString, const char *opName,
190  bool (*op)(const char* lhs, const __FlashStringHelper* rhs),
191  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
192 
193  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
194  const __FlashStringHelper* lhsString, const char *opName,
195  bool (*op)(const String& lhs, const char* rhs),
196  const char* rhs, const __FlashStringHelper* rhsString);
197 
198  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
199  const __FlashStringHelper* lhsString, const char *opName,
200  bool (*op)(const String& lhs, const String& rhs),
201  const String& rhs, const __FlashStringHelper* rhsString);
202 
203  bool assertionVerbose(const char* file, uint16_t line, const String& lhs,
204  const __FlashStringHelper* lhsString, const char *opName,
205  bool (*op)(const String& lhs, const __FlashStringHelper* rhs),
206  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
207 
208  bool assertionVerbose(const char* file, uint16_t line,
209  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
210  const char *opName,
211  bool (*op)(const __FlashStringHelper* lhs, const char* rhs),
212  const char* rhs, const __FlashStringHelper* rhsString);
213 
214  bool assertionVerbose(const char* file, uint16_t line,
215  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
216  const char *opName,
217  bool (*op)(const __FlashStringHelper* lhs, const String& rhs),
218  const String& rhs, const __FlashStringHelper* rhsString);
219 
220  bool assertionVerbose(const char* file, uint16_t line,
221  const __FlashStringHelper* lhs, const __FlashStringHelper* lhsString,
222  const char *opName,
223  bool (*op)(const __FlashStringHelper* lhs,
224  const __FlashStringHelper* rhs),
225  const __FlashStringHelper* rhs, const __FlashStringHelper* rhsString);
226 
227  private:
228  // Disable copy-constructor and assignment operator
229  Assertion(const Assertion&) = delete;
230  Assertion& operator=(const Assertion&) = delete;
231 };
232 
233 }
234 
235 #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
Various macros to smooth over the differences among the various platforms with regards to their suppo...
Assertion()
Empty constructor.
Definition: Assertion.h:58