BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
unittest.h
Go to the documentation of this file.
1 
2 /* Copyright 2012-2014, Peter A. Bigot
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *
9  * * Redistributions of source code must retain the above copyright notice,
10  * this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  *
16  * * Neither the name of the software nor the names of its contributors may be
17  * used to endorse or promote products derived from this software without
18  * specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
59 #ifndef BSP430_UTILITY_UNITTEST_H
60 #define BSP430_UTILITY_UNITTEST_H
61 
62 #include <bsp430/core.h>
63 #include <string.h>
64 #include <inttypes.h>
65 
74 #ifndef configBSP430_UNITTEST
75 #define configBSP430_UNITTEST 0
76 #endif /* configBSP430_UNITTEST */
77 
85 #define BSP430_UNITTEST (configBSP430_UNITTEST - 0)
86 
87 #if defined(BSP430_DOXYGEN) || (defined(BSP430_LED_GREEN) && defined(BSP430_LED_RED))
88 
92 #define BSP430_UNITTEST_LED_FAILED BSP430_LED_RED
93 
98 #define BSP430_UNITTEST_LED_PASSED BSP430_LED_GREEN
99 #else
100 #define BSP430_UNITTEST_LED_FAILED 0
101 #define BSP430_UNITTEST_LED_PASSED 1
102 #endif
103 
114 #ifndef configBSP430_UNITTEST_FAILFAST
115 #define configBSP430_UNITTEST_FAILFAST 0
116 #endif /* configBSP430_UNITTEST_FAILFAST */
117 
123 void vBSP430unittestInitialize (void);
124 
137 void vBSP430unittestResult_ (int line,
138  int passp,
139  const char * format,
140  ...);
141 
155 void vBSP430unittestFinalize (void);
156 
158 #define BSP430_UNITTEST_FAIL(msg_) do { \
159  vBSP430unittestResult_(__LINE__, 0, msg_); \
160  } while (0)
161 
163 #define BSP430_UNITTEST_ASSERT_TRUE(expr_) do { \
164  static const char * expr_str_ = #expr_; \
165  vBSP430unittestResult_(__LINE__, !!(expr_), expr_str_); \
166  } while (0)
167 
169 #define BSP430_UNITTEST_ASSERT_FALSE(expr_) do { \
170  static const char * expr_str_ = #expr_; \
171  vBSP430unittestResult_(__LINE__, !(expr_), "NOT %s", expr_str_); \
172  } while (0)
173 
175 #define BSP430_UNITTEST_ASSERT_EQUAL(v1_,v2_) do { \
176  static const char * expr_str_ = #v1_ "==" #v2_; \
177  vBSP430unittestResult_(__LINE__, (v1_) == (v2_), expr_str_); \
178  } while (0)
179 
181 #define BSP430_UNITTEST_ASSERT_EQUAL_ASCIIZ(v1_,v2_) do { \
182  static const char * expr_str_ = #v1_ "==" #v2_; \
183  const char * v1v_ = (v1_); \
184  const char * v2v_ = (v2_); \
185  vBSP430unittestResult_(__LINE__, 0 == strcmp(v1v_, v2v_), expr_str_); \
186  } while (0)
187 
200 #define BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,type_,pri_) do { \
201  static const char * expr_str_ = #v1_ "==" #v2_; \
202  type_ v1v_ = (v1_); \
203  type_ v2v_ = (v2_); \
204  if (v1v_ == v2v_) { \
205  vBSP430unittestResult_(__LINE__, 1, "%s", expr_str_); \
206  } else { \
207  vBSP430unittestResult_(__LINE__, 0, "%s: " pri_ " != " pri_, expr_str_, v1v_, v2v_); \
208  } \
209  } while (0)
210 
211 
216 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTd(v1_,v2_) \
217  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,int,"%" PRId16)
218 
223 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTu(v1_,v2_) \
224  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned int,"%" PRIu16)
225 
230 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTx(v1_,v2_) \
231  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned int,"%#" PRIx16)
232 
237 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTld(v1_,v2_) \
238  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,long,"%" PRId32)
239 
240 #ifdef PRId64
241 
245 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTlld(v1_,v2_) \
246  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,long long,"%" PRId64)
247 #endif /* PRId64 */
248 
253 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTlu(v1_,v2_) \
254  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned long,"%" PRIu32)
255 
256 #ifdef PRIu64
257 
261 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTllu(v1_,v2_) \
262  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned long long,"%" PRIu64)
263 #endif /* PRIu64 */
264 
269 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTlx(v1_,v2_) \
270  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned long, "%#" PRIx32)
271 
272 #ifdef PRIx64
273 
277 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTllx(v1_,v2_) \
278  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,unsigned long long, "%#" PRIx64)
279 #endif /* PRIx64 */
280 
284 #define BSP430_UNITTEST_ASSERT_EQUAL_FMTp(v1_,v2_) \
285  BSP430_UNITTEST_ASSERT_EQUAL_FMT_(v1_,v2_,const void *,"%p")
286 
287 #endif /* BSP430_UTILITY_UNITTEST_H */
void vBSP430unittestInitialize(void)
Common header included by all BSP430 leaf headers.
void vBSP430unittestResult_(int line, int passp, const char *format,...)
void vBSP430unittestFinalize(void)