Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlassert / repo / tests / nlassert-test.c
1 /*
2  *
3  *    Copyright (c) 2012-2015 Nest Labs, Inc.
4  *    All rights reserved.
5  *
6  *    This document is the property of Nest. It is considered
7  *    confidential and proprietary information.
8  *
9  *    This document may not be reproduced or transmitted in any form,
10  *    in whole or in part, without the express written permission of
11  *    Nest.
12  *
13  */
14
15 /**
16  *    @file
17  *      This file implements a unit test suite for the Nest Labs
18  *      runtime assertion library.
19  *
20  */
21
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <unistd.h>
29
30 #include "nlassert-test-config.h"
31
32 #define NL_ASSERT_COMPONENT_STRING "nlassert-test"
33
34 static void nlassert_test_abort(void);
35 static void nlassert_test_backtrace(void);
36 static void nlassert_test_log(const char *format, ...);
37 static void nlassert_test_trap(void);
38
39 #define NL_ASSERT_PRODUCTION                         (NL_ASSERT_TEST_WANT_PRODUCTION)
40
41 /*
42  * Set the assertion trigger flags as desired by the test harness configuration
43  */
44 #if NL_ASSERT_TEST_WANT_BACKTRACE && NL_ASSERT_TEST_WANT_LOG && NL_ASSERT_TEST_WANT_TRAP
45 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_BACKTRACE | NL_ASSERT_FLAG_LOG | NL_ASSERT_FLAG_TRAP)
46 #elif NL_ASSERT_TEST_WANT_BACKTRACE && NL_ASSERT_TEST_WANT_LOG
47 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_BACKTRACE | NL_ASSERT_FLAG_LOG)
48 #elif NL_ASSERT_TEST_WANT_BACKTRACE && NL_ASSERT_TEST_WANT_TRAP
49 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_BACKTRACE | NL_ASSERT_FLAG_TRAP)
50 #elif NL_ASSERT_TEST_WANT_LOG && NL_ASSERT_TEST_WANT_TRAP
51 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_LOG       | NL_ASSERT_FLAG_TRAP)
52 #elif NL_ASSERT_TEST_WANT_BACKTRACE
53 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_BACKTRACE)
54 #elif NL_ASSERT_TEST_WANT_LOG
55 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_LOG)
56 #elif NL_ASSERT_TEST_WANT_TRAP
57 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_TRAP)
58 #else
59 #define __NL_TEST_ASSERT_FLAGS                       (NL_ASSERT_FLAG_NONE)
60 #endif
61
62 /*
63  * Configure both the non-production and production ssertion interface
64  * family trigger flags with the defaults, if so requested, or as set
65  * above.
66  */
67 #if NL_ASSERT_TEST_WANT_DEFAULTS
68 # define NL_ASSERT_USE_FLAGS_DEFAULT                 1
69 #else /* !NL_ASSERT_TEST_WANT_DEFAULTS */
70 # define NL_ASSERT_EXPECT_FLAGS                      __NL_TEST_ASSERT_FLAGS
71
72 # define NL_ASSERT_ABORT_PRODUCTION_FLAGS            __NL_TEST_ASSERT_FLAGS
73 # define NL_ASSERT_VERIFY_PRODUCTION_FLAGS           __NL_TEST_ASSERT_FLAGS
74 # define NL_ASSERT_PRECONDITION_PRODUCTION_FLAGS     __NL_TEST_ASSERT_FLAGS
75 # define NL_ASSERT_DESIRE_PRODUCTION_FLAGS           __NL_TEST_ASSERT_FLAGS
76 # define NL_ASSERT_REQUIRE_PRODUCTION_FLAGS          __NL_TEST_ASSERT_FLAGS
77
78 # define NL_ASSERT_ASSERT_NONPRODUCTION_FLAGS        __NL_TEST_ASSERT_FLAGS
79 # define NL_ASSERT_ABORT_NONPRODUCTION_FLAGS         __NL_TEST_ASSERT_FLAGS
80 # define NL_ASSERT_CHECK_NONPRODUCTION_FLAGS         __NL_TEST_ASSERT_FLAGS
81 # define NL_ASSERT_VERIFY_NONPRODUCTION_FLAGS        __NL_TEST_ASSERT_FLAGS
82 # define NL_ASSERT_PRECONDITION_NONPRODUCTION_FLAGS  __NL_TEST_ASSERT_FLAGS
83 # define NL_ASSERT_DESIRE_NONPRODUCTION_FLAGS        __NL_TEST_ASSERT_FLAGS
84 # define NL_ASSERT_REQUIRE_NONPRODUCTION_FLAGS       __NL_TEST_ASSERT_FLAGS
85 #endif /* NL_ASSERT_TEST_WANT_DEFAULTS */
86
87 /*
88  * Abstract the flags for each assertion style such that the
89  * abstracted flags mnemonic can be passed unconditionally to the test
90  * initialization code.
91  */
92 #if NL_ASSERT_TEST_WANT_PRODUCTION
93 # define __NL_ASSERT_TEST_ASSERT_FLAGS               (NL_ASSERT_FLAG_NONE)
94 # define __NL_ASSERT_TEST_ABORT_FLAGS                NL_ASSERT_ABORT_PRODUCTION_FLAGS
95 # define __NL_ASSERT_TEST_CHECK_FLAGS                (NL_ASSERT_FLAG_NONE)
96 # define __NL_ASSERT_TEST_VERIFY_FLAGS               NL_ASSERT_VERIFY_PRODUCTION_FLAGS
97 # define __NL_ASSERT_TEST_PRECONDITION_FLAGS         NL_ASSERT_PRECONDITION_PRODUCTION_FLAGS
98 # define __NL_ASSERT_TEST_EXPECT_FLAGS               NL_ASSERT_EXPECT_FLAGS
99 # define __NL_ASSERT_TEST_DESIRE_FLAGS               NL_ASSERT_DESIRE_PRODUCTION_FLAGS
100 # define __NL_ASSERT_TEST_REQUIRE_FLAGS              NL_ASSERT_REQUIRE_PRODUCTION_FLAGS
101 #else /* !NL_ASSERT_TEST_WANT_PRODUCTION */
102 # define __NL_ASSERT_TEST_ASSERT_FLAGS               NL_ASSERT_ASSERT_NONPRODUCTION_FLAGS
103 # define __NL_ASSERT_TEST_ABORT_FLAGS                NL_ASSERT_ABORT_NONPRODUCTION_FLAGS
104 # define __NL_ASSERT_TEST_CHECK_FLAGS                NL_ASSERT_CHECK_NONPRODUCTION_FLAGS
105 # define __NL_ASSERT_TEST_VERIFY_FLAGS               NL_ASSERT_VERIFY_NONPRODUCTION_FLAGS
106 # define __NL_ASSERT_TEST_PRECONDITION_FLAGS         NL_ASSERT_PRECONDITION_NONPRODUCTION_FLAGS
107 # define __NL_ASSERT_TEST_EXPECT_FLAGS               NL_ASSERT_EXPECT_FLAGS
108 # define __NL_ASSERT_TEST_DESIRE_FLAGS               NL_ASSERT_DESIRE_NONPRODUCTION_FLAGS
109 # define __NL_ASSERT_TEST_REQUIRE_FLAGS              NL_ASSERT_REQUIRE_NONPRODUCTION_FLAGS
110 #endif /* NL_ASSERT_TEST_WANT_PRODUCTION */
111
112 #define NL_ASSERT_ABORT()                       \
113     do {                                        \
114         nlassert_test_abort();                  \
115     } while (0)
116
117 #define NL_ASSERT_BACKTRACE()                   \
118     do {                                        \
119         nlassert_test_backtrace();              \
120     } while (0)
121
122 #define NL_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage)         \
123     do {                                                                                  \
124         nlassert_test_log(NL_ASSERT_LOG_FORMAT_DEFAULT,                                   \
125                           aPrefix,                                                        \
126                           (((aName) == 0) || (*(aName) == '\0')) ? "" : aName,            \
127                           (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ",             \
128                           aCondition,                                                     \
129                           ((aMessage == 0) ? "" : aMessage),                              \
130                           ((aMessage == 0) ? "" : ", "),                                  \
131                           aFile,                                                          \
132                           aLine);                                                         \
133     } while (0)
134
135 #define NL_ASSERT_TRAP()                        \
136     do {                                        \
137         nlassert_test_trap();                   \
138     } while (0)
139
140 #if NLASSERT_TEST_STDC
141 #include <assert.h>
142 #endif
143 #include <nlassert.h>
144
145 #include <nlunit-test.h>
146
147 // Type Defintions
148
149 struct AssertStyleContext {
150     bool                      mShouldAbort;
151     bool                      mShouldBacktrace;
152     bool                      mShouldLog;
153     bool                      mShouldTrap;
154     bool                      mShouldLogActionOnly;
155 };
156
157 struct TestBufferContext {
158     char *                    mBuffer;
159     size_t                    mBufferOffset;
160     size_t                    mBufferSize;
161 };
162
163 struct TestContext {
164     struct TestBufferContext  mActual;
165     struct TestBufferContext  mExpected;
166     bool                      mWantProduction;
167     bool                      mIsProduction;
168     bool                      mDidAbort;
169     bool                      mDidBacktrace;
170     bool                      mDidLog;
171     bool                      mDidTrap;
172     struct AssertStyleContext mAssert;
173     struct AssertStyleContext mAbort;
174     struct AssertStyleContext mCheck;
175     struct AssertStyleContext mVerify;
176     struct AssertStyleContext mPrecondition;
177     struct AssertStyleContext mExpect;
178     struct AssertStyleContext mDesire;
179     struct AssertStyleContext mRequire;
180 };
181
182 // Global Variables
183
184 static struct TestContext sContext;
185
186 /**
187  *  Reset a test buffer context by setting the offset to zero.
188  */
189 static void TestBufferContextReset(struct TestBufferContext *inContext)
190 {
191     if (inContext->mBuffer != NULL)
192     {
193         inContext->mBufferOffset = 0;
194         inContext->mBuffer[0]    = '\0';
195     }
196 }
197
198 /**
199  *  Reset a test context by resetting both the actual and expected
200  *  buffers and setting all of the abort, backtrace, log, and trap
201  *  Booleans to false.
202  */
203 static void TestContextReset(struct TestContext *inContext)
204 {
205     TestBufferContextReset(&inContext->mActual);
206     TestBufferContextReset(&inContext->mExpected);
207
208     sContext.mDidAbort     = false;
209     sContext.mDidBacktrace = false;
210     sContext.mDidLog       = false;
211     sContext.mDidTrap      = false;
212 }
213
214 /**
215  *  Initialize the assertion style context by determining whether or
216  *  not a backtrace, log, and trap are expected on assertion trigger.
217  */
218 static void AssertStyleContextInit(struct AssertStyleContext *inContext, const uint32_t inFlags, bool inAbort, bool inLogActionOnly)
219 {
220
221     inContext->mShouldAbort         = inAbort;
222     inContext->mShouldBacktrace     = inFlags & NL_ASSERT_FLAG_BACKTRACE;
223     inContext->mShouldLog           = inFlags & NL_ASSERT_FLAG_LOG;
224     inContext->mShouldTrap          = inFlags & NL_ASSERT_FLAG_TRAP;
225     inContext->mShouldLogActionOnly = inLogActionOnly;
226 }
227
228 /**
229  *  Test-specific hook for #NL_ASSERT_ABORT used with nlASSERT.
230  */
231 static void __attribute__((unused)) nlassert_test_abort(void)
232 {
233     sContext.mDidAbort = true;
234 }
235
236 /**
237  *  Test-specific hook for #NL_ASSERT_BACKTRACE used with all styles of
238  *  assertion.
239  */
240 static void __attribute__((unused)) nlassert_test_backtrace(void)
241 {
242     sContext.mDidBacktrace = true;
243 }
244
245 /**
246  *  Test-specific hook for #NL_ASSERT_TRAP used with all styles of
247  *  assertion.
248  */
249 static void __attribute__((unused)) nlassert_test_trap(void)
250 {
251     sContext.mDidTrap = true;
252 }
253
254 static void nlassert_test_vlog_with_buffer(struct TestBufferContext *inBuffer, const char *inFormat, va_list inArguments)
255 {
256     const size_t size = inBuffer->mBufferSize - inBuffer->mBufferOffset;
257     char *       p    = inBuffer->mBuffer + inBuffer->mBufferOffset;
258     int          n;
259
260     n = vsnprintf(p, size, inFormat, inArguments);
261
262     if (n > 0) {
263         inBuffer->mBufferOffset += n;
264     }
265 }
266
267 static void nlassert_test_log_with_buffer(struct TestBufferContext *inBuffer, const char *inFormat, ...)
268 {
269     va_list      args;
270
271     va_start(args, inFormat);
272
273     nlassert_test_vlog_with_buffer(inBuffer, inFormat, args);
274
275     va_end(args);
276 }
277
278 static void _nlassert_test_log(const char *inFormat, ...)
279 {
280     va_list args;
281
282     va_start(args, inFormat);
283
284     nlassert_test_vlog_with_buffer(&sContext.mActual, inFormat, args);
285
286     va_end(args);
287 }
288
289 /**
290  *  Test-specific hook for #NL_ASSERT_LOG used with all styles of
291  *  assertion.
292  */
293 static void __attribute__((unused)) nlassert_test_log(const char *inFormat, ...)
294 {
295     va_list args;
296
297     sContext.mDidLog = true;
298
299     va_start(args, inFormat);
300
301     nlassert_test_vlog_with_buffer(&sContext.mActual, inFormat, args);
302
303     va_end(args);
304 }
305
306 static void nlassert_test_action(const char *function, const char *message)
307 {
308     _nlassert_test_log("%s: %s test\n", function, message);
309 }
310
311 #define nlASSERT_TEST_ACTION(message) nlassert_test_action(__func__, message)
312
313 #define nlASSERT_TEST_CHECK_EXPECTED(context, style, assertion, extra, action, line) \
314     nlAssertTestCheckExpected(context, style, assertion, extra, action, __FILE__, line)
315
316 static bool nlAssertTestCheckExpected(struct TestContext *inContext, const struct AssertStyleContext *inStyle, const char *inAssertion, const char *inExtra, const char *inAction, const char *inFile, unsigned int inLine)
317 {
318     int  comparison;
319     bool matches;
320
321     /*
322      * Only log an expected message if the particular assertion style
323      * should have done so. Otherwise, only log an action message if
324      * we are not production or if the assertion style if not 'check',
325      * since production 'check' assertions are completely compiled
326      * out.
327      */
328     if (inStyle->mShouldLog)
329     {
330         nlassert_test_log_with_buffer(&inContext->mExpected,
331                                       "%s%s%s%s%s%s%s%s%u%s%s",
332                                       "ASSERT: ",
333                                       NL_ASSERT_COMPONENT_STRING ": ",
334                                       inAssertion,
335                                       ", ",
336                                       inExtra,
337                                       "file: ",
338                                       inFile,
339                                       ", line: ",
340                                       inLine,
341                                       "\n",
342                                       inAction);
343     }
344     else if (inStyle->mShouldLogActionOnly)
345     {
346         nlassert_test_log_with_buffer(&inContext->mExpected,
347                                       "%s",
348                                       inAction);
349     }
350
351     comparison = strcmp(inContext->mActual.mBuffer, inContext->mExpected.mBuffer);
352     matches    = (comparison == 0);
353
354     if (!matches) {
355         fprintf(stderr, "ACTUAL @ %u: %s\n", inLine, inContext->mActual.mBuffer);
356         fprintf(stderr, "EXPECT @ %u: %s\n", inLine, inContext->mExpected.mBuffer);
357     }
358
359     return (matches);
360 }
361
362 /**
363  *  Test whether the production vs. non-production aspect of
364  *  assertions is in effect and matches what is expected.
365  */
366 static void TestProduction(nlTestSuite *inSuite, void *inContext)
367 {
368     struct TestContext *theContext = inContext;
369
370     NL_TEST_ASSERT(inSuite, theContext->mWantProduction == NL_ASSERT_PRODUCTION);
371 }
372
373 #if NLASSERT_TEST_STDC
374 /**
375  *  Test the Standard C Library macro workalike for correct operation.
376  */
377 static void TestStandardCAssert(nlTestSuite *inSuite, void *inContext)
378 {
379     struct TestContext * theContext = inContext;
380     bool                 assert1;
381     bool                 matches;
382
383     // Test the assert, Standard C Library workalike
384
385     assert1 = false;
386
387     assert(assert1);
388     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mAssert, "assert1", "", "", __LINE__ - 1);
389     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldAbort     == theContext->mDidAbort);
390     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldBacktrace == theContext->mDidBacktrace);
391     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldLog       == theContext->mDidLog);
392     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldTrap      == theContext->mDidTrap);
393     NL_TEST_ASSERT(inSuite, matches);
394     TestContextReset(theContext);
395 }
396 #endif
397
398 /**
399  *  Test the nlASSERT macro for correct operation.
400  */
401 static void TestNestLabsAssert(nlTestSuite *inSuite, void *inContext)
402 {
403     struct TestContext * theContext = inContext;
404     bool                 assert1, assert2;
405     bool                 matches;
406
407     // Test nlASSERT
408
409     assert1 = assert2 = false;
410
411     nlASSERT(assert1);
412     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mAssert, "assert1", "", "", __LINE__ - 1);
413     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldAbort     == theContext->mDidAbort);
414     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldBacktrace == theContext->mDidBacktrace);
415     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldLog       == theContext->mDidLog);
416     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldTrap      == theContext->mDidTrap);
417     NL_TEST_ASSERT(inSuite, matches);
418     TestContextReset(theContext);
419
420     nlASSERT_ACTION(assert2, nlASSERT_TEST_ACTION("assert2"));
421     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mAssert, "assert2", "", "TestNestLabsAssert: assert2 test\n", __LINE__ - 1);
422     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldAbort     == theContext->mDidAbort);
423     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldBacktrace == theContext->mDidBacktrace);
424     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldLog       == theContext->mDidLog);
425     NL_TEST_ASSERT(inSuite, theContext->mAssert.mShouldTrap      == theContext->mDidTrap);
426     NL_TEST_ASSERT(inSuite, matches);
427     TestContextReset(theContext);
428 }
429
430 static void TestAssert(nlTestSuite *inSuite, void *inContext)
431 {
432 #if NLASSERT_TEST_STDC
433     TestStandardCAssert(inSuite, inContext);
434 #endif
435     TestNestLabsAssert(inSuite, inContext);
436 }
437
438 /**
439  *  Test the nlABORT macro for correct operation.
440  */
441 static void TestAbort(nlTestSuite *inSuite, void *inContext)
442 {
443     struct TestContext * theContext = inContext;
444     bool                 abort1, abort2;
445     bool                 matches;
446
447     // Test nlABORT
448
449     abort1 = abort2 = false;
450
451     nlABORT(abort1);
452     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mAbort, "abort1", "", "", __LINE__ - 1);
453     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldAbort     == theContext->mDidAbort);
454     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldBacktrace == theContext->mDidBacktrace);
455     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldLog       == theContext->mDidLog);
456     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldTrap      == theContext->mDidTrap);
457     NL_TEST_ASSERT(inSuite, matches);
458     TestContextReset(theContext);
459
460     nlABORT_ACTION(abort2, nlASSERT_TEST_ACTION("abort2"));
461     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mAbort, "abort2", "", "TestAbort: abort2 test\n", __LINE__ - 1);
462     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldAbort     == theContext->mDidAbort);
463     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldBacktrace == theContext->mDidBacktrace);
464     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldLog       == theContext->mDidLog);
465     NL_TEST_ASSERT(inSuite, theContext->mAbort.mShouldTrap      == theContext->mDidTrap);
466     NL_TEST_ASSERT(inSuite, matches);
467     TestContextReset(theContext);
468 }
469
470 /**
471  *  Test the nl[N]CHECK* style of macros for correct operation.
472  */
473 static void TestCheck(nlTestSuite *inSuite, void *inContext)
474 {
475     struct TestContext * theContext = inContext;
476     bool                 check1, check2, check3;
477     bool                 check5, check6, check7;
478     int                  status1, status2, status3;
479     bool                 matches;
480
481     // Test nlCHECK
482
483     check1 = check2 = check3 = false;
484
485     nlCHECK(check1);
486     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "check1", "", "", __LINE__ - 1);
487     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
488     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
489     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
490     NL_TEST_ASSERT(inSuite, matches);
491     TestContextReset(theContext);
492
493     nlCHECK_ACTION(check2, nlASSERT_TEST_ACTION("check2"));
494     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "check2", "", "TestCheck: check2 test\n", __LINE__ - 1);
495     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
496     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
497     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
498     NL_TEST_ASSERT(inSuite, matches);
499     TestContextReset(theContext);
500
501     nlCHECK_PRINT(check3, "nlCHECK_PRINT test");
502     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "check3", "nlCHECK_PRINT test, ", "",  __LINE__ - 1);
503     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
504     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
505     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
506     NL_TEST_ASSERT(inSuite, matches);
507     TestContextReset(theContext);
508
509     // Test nlCHECK_SUCCESS
510
511     status1 = status2 = status3 = -1;
512
513     nlCHECK_SUCCESS(status1);
514     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "status1 == 0", "", "", __LINE__ - 1);
515     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
516     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
517     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
518     NL_TEST_ASSERT(inSuite, matches);
519     TestContextReset(theContext);
520
521     nlCHECK_SUCCESS_ACTION(status2, nlASSERT_TEST_ACTION("status2"));
522     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "status2 == 0", "", "TestCheck: status2 test\n", __LINE__ - 1);
523     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
524     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
525     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
526     NL_TEST_ASSERT(inSuite, matches);
527     TestContextReset(theContext);
528
529     nlCHECK_SUCCESS_PRINT(status3, "nlCHECK_SUCCESS_PRINT test");
530     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "status3 == 0", "nlCHECK_SUCCESS_PRINT test, ", "", __LINE__ - 1);
531     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
532     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
533     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
534     NL_TEST_ASSERT(inSuite, matches);
535     TestContextReset(theContext);
536
537     // Test nlNCHECK
538
539     check5 = check6 = check7 = true;
540
541     nlNCHECK(check5);
542     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "!(check5)", "", "", __LINE__ - 1);
543     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
544     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
545     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
546     NL_TEST_ASSERT(inSuite, matches);
547     TestContextReset(theContext);
548
549     nlNCHECK_ACTION(check6, nlASSERT_TEST_ACTION("check6"));
550     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "!(check6)", "", "TestCheck: check6 test\n", __LINE__ - 1);
551     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
552     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
553     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
554     NL_TEST_ASSERT(inSuite, matches);
555     TestContextReset(theContext);
556
557     nlNCHECK_PRINT(check7, "nlNCHECK_PRINT test");
558     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mCheck, "!(check7)", "nlNCHECK_PRINT test, ", "", __LINE__ - 1);
559     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldBacktrace == theContext->mDidBacktrace);
560     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldLog       == theContext->mDidLog);
561     NL_TEST_ASSERT(inSuite, theContext->mCheck.mShouldTrap      == theContext->mDidTrap);
562     NL_TEST_ASSERT(inSuite, matches);
563     TestContextReset(theContext);
564 }
565
566 /**
567  *  Test the nl[N]VERIFY* style of macros for correct operation.
568  */
569 static void TestVerify(nlTestSuite *inSuite, void *inContext)
570 {
571     struct TestContext * theContext = inContext;
572     bool                 verify1, verify2, verify3;
573     bool                 verify4, verify5, verify6, verify7, verify8;
574     int                  status1, status2, status3, status4;
575     bool                 matches;
576
577     // nlVERIFY
578
579     verify1 = verify2 = verify3 = false;
580
581     nlVERIFY(verify1);
582     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "verify1", "", "", __LINE__ - 1);
583     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
584     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
585     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
586     NL_TEST_ASSERT(inSuite, matches);
587     TestContextReset(theContext);
588
589     nlVERIFY_ACTION(verify2, nlASSERT_TEST_ACTION("verify2"));
590     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "verify2", "", "TestVerify: verify2 test\n", __LINE__ - 1);
591     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
592     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
593     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
594     NL_TEST_ASSERT(inSuite, matches);
595     TestContextReset(theContext);
596
597     nlVERIFY_PRINT(verify3, "nlVERIFY_PRINT test");
598     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "verify3", "nlVERIFY_PRINT test, ", "", __LINE__ - 1);
599     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
600     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
601     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
602     NL_TEST_ASSERT(inSuite, matches);
603     TestContextReset(theContext);
604
605     // nlVERIFY_SUCCESS
606
607     status1 = status2 = status3 = -1;
608
609     nlVERIFY_SUCCESS(status1);
610     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "status1 == 0", "", "", __LINE__ - 1);
611     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
612     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
613     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
614     NL_TEST_ASSERT(inSuite, matches);
615     TestContextReset(theContext);
616
617     nlVERIFY_SUCCESS_ACTION(status2, nlASSERT_TEST_ACTION("status2"));
618     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "status2 == 0", "", "TestVerify: status2 test\n", __LINE__ - 1);
619     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
620     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
621     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
622     NL_TEST_ASSERT(inSuite, matches);
623     TestContextReset(theContext);
624
625     nlVERIFY_SUCCESS_PRINT(status3, "nlVERIFY_SUCCESS_PRINT test");
626     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "status3 == 0", "nlVERIFY_SUCCESS_PRINT test, ", "", __LINE__ - 1);
627     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
628     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
629     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
630     NL_TEST_ASSERT(inSuite, matches);
631     TestContextReset(theContext);
632
633     // nlNVERIFY
634
635     verify4 = verify5 = verify6 = true;
636
637     nlNVERIFY(verify4);
638     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "!(verify4)", "", "", __LINE__ - 1);
639     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
640     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
641     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
642     NL_TEST_ASSERT(inSuite, matches);
643     TestContextReset(theContext);
644
645     nlNVERIFY_ACTION(verify5, nlASSERT_TEST_ACTION("verify5"));
646     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "!(verify5)", "", "TestVerify: verify5 test\n", __LINE__ - 1);
647     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
648     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
649     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
650     NL_TEST_ASSERT(inSuite, matches);
651     TestContextReset(theContext);
652
653     nlNVERIFY_PRINT(verify6, "nlNVERIFY_PRINT test");
654     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "!(verify6)", "nlNVERIFY_PRINT test, ", "", __LINE__ - 1);
655     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
656     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
657     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
658     NL_TEST_ASSERT(inSuite, matches);
659     TestContextReset(theContext);
660
661     // Tests to make sure the break keyword works as an action inside
662     // control structures
663    
664     verify7 = false;
665     status4 = -1;
666     verify8 = true;
667
668     // Because 'break' is the action, any post-action triggers
669     // (i.e. trap) will be skipped. Consequently, don't assert that
670     // test post-condition.
671
672     while (true)
673     {
674         nlVERIFY_ACTION(verify7, break);
675     }
676     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "verify7", "", "", __LINE__ - 2);
677     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
678     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
679     NL_TEST_ASSERT(inSuite, matches);
680     TestContextReset(theContext);
681
682     // Because 'break' is the action, any post-action triggers
683     // (i.e. trap) will be skipped. Consequently, don't assert that
684     // test post-condition.
685
686     while (true)
687     {
688         nlVERIFY_SUCCESS_ACTION(status4, break);
689     }
690     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "status4 == 0", "", "", __LINE__ - 2);
691     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
692     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
693     NL_TEST_ASSERT(inSuite, matches);
694     TestContextReset(theContext);
695
696     // Because 'break' is the action, any post-action triggers
697     // (i.e. trap) will be skipped. Consequently, don't assert that
698     // test post-condition.
699
700     while (true)
701     {
702         nlNVERIFY_ACTION(verify8, break);
703     }
704     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mVerify, "!(verify8)", "", "", __LINE__ - 2);
705     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
706     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
707     NL_TEST_ASSERT(inSuite, matches);
708     TestContextReset(theContext);
709 }
710
711 static void TestPreconditionVoid(unsigned int *outLine)
712 {
713     const bool precondition1 = false;
714
715     *outLine = __LINE__ + 2;
716
717     nlPRECONDITION(precondition1);
718 }
719
720 static void TestPreconditionActionVoid(unsigned int *outLine)
721 {
722     const bool precondition2 = false;
723
724     *outLine = __LINE__ + 2;
725
726     nlPRECONDITION_ACTION(precondition2, nlASSERT_TEST_ACTION("precondition2"));
727 }
728
729 static void TestPreconditionPrintVoid(unsigned int *outLine)
730 {
731     const bool precondition3 = false;
732
733     *outLine = __LINE__ + 2;
734
735     nlPRECONDITION_PRINT(precondition3, "nlPRECONDITION_PRINT test");
736 }
737
738 static void TestNotPreconditionVoid(unsigned int *outLine)
739 {
740     const bool precondition4 = true;
741
742     *outLine = __LINE__ + 2;
743
744     nlNPRECONDITION(precondition4);
745 }
746
747 static void TestNotPreconditionActionVoid(unsigned int *outLine)
748 {
749     const bool precondition5 = true;
750
751     *outLine = __LINE__ + 2;
752
753     nlNPRECONDITION_ACTION(precondition5, nlASSERT_TEST_ACTION("precondition5"));
754 }
755
756 static void TestNotPreconditionPrintVoid(unsigned int *outLine)
757 {
758     const bool precondition6 = true;
759
760     *outLine = __LINE__ + 2;
761
762     nlNPRECONDITION_PRINT(precondition6, "nlNPRECONDITION_PRINT test");
763 }
764
765 static void TestPreconditionSuccessVoid(unsigned int *outLine)
766 {
767     const int status1 = -1;
768
769     *outLine = __LINE__ + 2;
770
771     nlPRECONDITION_SUCCESS(status1);
772 }
773
774 static void TestPreconditionSuccessActionVoid(unsigned int *outLine)
775 {
776     const int status2 = -1;
777
778     *outLine = __LINE__ + 2;
779
780     nlPRECONDITION_SUCCESS_ACTION(status2, nlASSERT_TEST_ACTION("status2"));
781 }
782
783 static void TestPreconditionSuccessPrintVoid(unsigned int *outLine)
784 {
785     const int status3 = -1;
786
787     *outLine = __LINE__ + 2;
788
789     nlPRECONDITION_SUCCESS_PRINT(status3, "nlPRECONDITION_SUCCESS_PRINT test");
790 }
791
792 static int TestPreconditionValue(unsigned int *outLine, int inStatus)
793 {
794     const bool precondition7 = false;
795
796     *outLine = __LINE__ + 2;
797
798     nlPRECONDITION_VALUE(precondition7, inStatus);
799
800     return 0;
801 }
802
803 static int TestPreconditionValueAction(unsigned int *outLine, int inStatus)
804 {
805     const bool precondition8 = false;
806
807     *outLine = __LINE__ + 2;
808
809     nlPRECONDITION_VALUE_ACTION(precondition8, inStatus, nlASSERT_TEST_ACTION("precondition8"));
810
811     return 0;
812 }
813
814 static int TestPreconditionValuePrint(unsigned int *outLine, int inStatus)
815 {
816     const bool precondition9 = false;
817
818     *outLine = __LINE__ + 2;
819
820     nlPRECONDITION_VALUE_PRINT(precondition9, inStatus, "nlPRECONDITION_VALUE_PRINT test");
821
822     return 0;
823 }
824
825 static int TestPreconditionValueSuccess(unsigned int *outLine, int inStatus)
826 {
827     const int status4 = -1;
828
829     *outLine = __LINE__ + 2;
830
831     nlPRECONDITION_VALUE_SUCCESS(status4, inStatus);
832
833     return 0;
834 }
835
836 static int TestPreconditionValueSuccessAction(unsigned int *outLine, int inStatus)
837 {
838     const int status5 = -1;
839
840     *outLine = __LINE__ + 2;
841
842     nlPRECONDITION_VALUE_SUCCESS_ACTION(status5, inStatus, nlASSERT_TEST_ACTION("status5"));
843
844     return 0;
845 }
846
847 static int TestPreconditionValueSuccessPrint(unsigned int *outLine, int inStatus)
848 {
849     const int status6 = -1;
850
851     *outLine = __LINE__ + 2;
852
853     nlPRECONDITION_VALUE_SUCCESS_PRINT(status6, inStatus, "nlPRECONDITION_VALUE_SUCCESS_PRINT test");
854
855     return 0;
856 }
857
858 static int TestNotPreconditionValue(unsigned int *outLine, int inStatus)
859 {
860     const bool precondition10 = true;
861
862     *outLine = __LINE__ + 2;
863
864     nlNPRECONDITION_VALUE(precondition10, inStatus);
865
866     return 0;
867 }
868
869 static int TestNotPreconditionValueAction(unsigned int *outLine, int inStatus)
870 {
871     const bool precondition11 = true;
872
873     *outLine = __LINE__ + 2;
874
875     nlNPRECONDITION_VALUE_ACTION(precondition11, inStatus, nlASSERT_TEST_ACTION("precondition11"));
876
877     return 0;
878 }
879
880 static int TestNotPreconditionValuePrint(unsigned int *outLine, int inStatus)
881 {
882     const bool precondition12 = true;
883
884     *outLine = __LINE__ + 2;
885
886     nlNPRECONDITION_VALUE_PRINT(precondition12, inStatus, "nlNPRECONDITION_VALUE_PRINT test");
887
888     return 0;
889 }
890
891 /**
892  *  Test the nl[N]PRECONDITION* style of macros for correct operation.
893  */
894 static void TestPrecondition(nlTestSuite *inSuite, void *inContext)
895 {
896     struct TestContext * theContext = (struct TestContext *)(inContext);
897     unsigned int         line;
898     int                  status;
899     bool                 matches;
900
901     // nlPRECONDITION{,_ACTION,_PRINT}
902
903     TestPreconditionVoid(&line);
904     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition1", "", "", line);
905     NL_TEST_ASSERT(inSuite, theContext->mPrecondition.mShouldBacktrace == theContext->mDidBacktrace);
906     NL_TEST_ASSERT(inSuite, theContext->mPrecondition.mShouldLog       == theContext->mDidLog);
907     NL_TEST_ASSERT(inSuite, theContext->mPrecondition.mShouldTrap      == theContext->mDidTrap);
908     NL_TEST_ASSERT(inSuite, matches);
909     TestContextReset(theContext);
910
911     TestPreconditionActionVoid(&line);
912     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition2", "", "TestPreconditionActionVoid: precondition2 test\n", line);
913     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
914     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
915     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
916     NL_TEST_ASSERT(inSuite, matches);
917     TestContextReset(theContext);
918
919     TestPreconditionPrintVoid(&line);
920     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition3", "nlPRECONDITION_PRINT test, ", "", line);
921     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
922     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
923     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
924     NL_TEST_ASSERT(inSuite, matches);
925     TestContextReset(theContext);
926
927     // nlNPRECONDITION{,_ACTION,_PRINT}
928
929     TestNotPreconditionVoid(&line);
930     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition4)", "", "", line);
931     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
932     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
933     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
934     NL_TEST_ASSERT(inSuite, matches);
935     TestContextReset(theContext);
936
937     TestNotPreconditionActionVoid(&line);
938     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition5)", "", "TestNotPreconditionActionVoid: precondition5 test\n", line);
939     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
940     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
941     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
942     NL_TEST_ASSERT(inSuite, matches);
943     TestContextReset(theContext);
944
945     TestNotPreconditionPrintVoid(&line);
946     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition6)", "nlNPRECONDITION_PRINT test, ", "", line);
947     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
948     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
949     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
950     NL_TEST_ASSERT(inSuite, matches);
951     TestContextReset(theContext);
952
953     // nlPRECONDITION_SUCCESS{,_ACTION,_PRINT}
954
955     TestPreconditionSuccessVoid(&line);
956     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status1 == 0", "", "", line);
957     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
958     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
959     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
960     NL_TEST_ASSERT(inSuite, matches);
961     TestContextReset(theContext);
962
963     TestPreconditionSuccessActionVoid(&line);
964     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status2 == 0", "", "TestPreconditionSuccessActionVoid: status2 test\n", line);
965     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
966     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
967     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
968     NL_TEST_ASSERT(inSuite, matches);
969     TestContextReset(theContext);
970
971     TestPreconditionSuccessPrintVoid(&line);
972     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status3 == 0", "nlPRECONDITION_SUCCESS_PRINT test, ", "", line);
973     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
974     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
975     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
976     NL_TEST_ASSERT(inSuite, matches);
977     TestContextReset(theContext);
978
979     // nlPRECONDITION_VALUE{,_ACTION,_PRINT}
980
981     status = TestPreconditionValue(&line, -EINVAL);
982     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition7", "", "", line);
983     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
984     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
985     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
986     NL_TEST_ASSERT(inSuite, matches);
987     NL_TEST_ASSERT(inSuite, status == -EINVAL);
988     TestContextReset(theContext);
989
990     status = TestPreconditionValueAction(&line, -EINVAL);
991     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition8", "", "TestPreconditionValueAction: precondition8 test\n", line);
992     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
993     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
994     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
995     NL_TEST_ASSERT(inSuite, matches);
996     NL_TEST_ASSERT(inSuite, status == -EINVAL);
997     TestContextReset(theContext);
998
999     status = TestPreconditionValuePrint(&line, -EINVAL);
1000     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "precondition9", "nlPRECONDITION_VALUE_PRINT test, ", "", line);
1001     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1002     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1003     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1004     NL_TEST_ASSERT(inSuite, matches);
1005     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1006     TestContextReset(theContext);
1007
1008     // nlPRECONDITION_VALUE_SUCCESS{,_ACTION,_PRINT}
1009
1010     status = TestPreconditionValueSuccess(&line, -EINVAL);
1011     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status4 == 0", "", "", line);
1012     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1013     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1014     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1015     NL_TEST_ASSERT(inSuite, matches);
1016     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1017     TestContextReset(theContext);
1018
1019     status = TestPreconditionValueSuccessAction(&line, -EINVAL);
1020     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status5 == 0", "", "TestPreconditionValueSuccessAction: status5 test\n", line);
1021     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1022     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1023     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1024     NL_TEST_ASSERT(inSuite, matches);
1025     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1026     TestContextReset(theContext);
1027
1028     status = TestPreconditionValueSuccessPrint(&line, -EINVAL);
1029     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "status6 == 0", "nlPRECONDITION_VALUE_SUCCESS_PRINT test, ", "", line);
1030     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1031     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1032     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1033     NL_TEST_ASSERT(inSuite, matches);
1034     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1035     TestContextReset(theContext);
1036
1037     // nlNPRECONDITION_VALUE{,_ACTION,_PRINT}
1038
1039     status = TestNotPreconditionValue(&line, -EINVAL);
1040     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition10)", "", "", line);
1041     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1042     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1043     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1044     NL_TEST_ASSERT(inSuite, matches);
1045     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1046     TestContextReset(theContext);
1047
1048     status = TestNotPreconditionValueAction(&line, -EINVAL);
1049     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition11)", "", "TestNotPreconditionValueAction: precondition11 test\n", line);
1050     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1051     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1052     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1053     NL_TEST_ASSERT(inSuite, matches);
1054     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1055     TestContextReset(theContext);
1056
1057     status = TestNotPreconditionValuePrint(&line, -EINVAL);
1058     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mPrecondition, "!(precondition12)", "nlNPRECONDITION_VALUE_PRINT test, ", "", line);
1059     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldBacktrace == theContext->mDidBacktrace);
1060     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldLog       == theContext->mDidLog);
1061     NL_TEST_ASSERT(inSuite, theContext->mVerify.mShouldTrap      == theContext->mDidTrap);
1062     NL_TEST_ASSERT(inSuite, matches);
1063     NL_TEST_ASSERT(inSuite, status == -EINVAL);
1064     TestContextReset(theContext);
1065 }
1066
1067 /**
1068  *  Test the nl[N]EXPECT* style of macros for correct operation.
1069  */
1070 static void TestExpect(nlTestSuite *inSuite, void *inContext)
1071 {
1072     struct TestContext * theContext = (struct TestContext *)(inContext);
1073     bool                 expect1, expect2, expect3, expect4;
1074     bool                 expect5, expect6, expect7, expect8;
1075     int                  status1, status2, status3, status4;
1076     bool                 matches;
1077
1078     // Establish test preconditions.
1079
1080     expect1 = expect2 = expect3 = expect4 = false;
1081     expect5 = expect6 = expect7 = expect8 = true;
1082     status1 = status2 = status3 = status4 = -1;
1083
1084     // nlEXPECT{,_PRINT,_ACTION,_ACTION_PRINT}
1085
1086     nlEXPECT(expect1, expect_next1);
1087     goto expect_next2;
1088  expect_next1:
1089     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "expect1", "", "", __LINE__ - 3);
1090     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1091     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1092     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1093     NL_TEST_ASSERT(inSuite, matches);
1094     TestContextReset(theContext);
1095
1096     nlEXPECT_PRINT(expect2, expect_next2, "nlEXPECT_PRINT test");
1097     goto expect_next3;
1098  expect_next2:
1099     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "expect2", "nlEXPECT_PRINT test, ", "", __LINE__ - 3);
1100     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1101     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1102     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1103     NL_TEST_ASSERT(inSuite, matches);
1104     TestContextReset(theContext);
1105
1106     nlEXPECT_ACTION(expect3, expect_next3, nlASSERT_TEST_ACTION("expect3"));
1107     goto expect_next4;
1108  expect_next3:
1109     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "expect3", "", "TestExpect: expect3 test\n", __LINE__ - 3);
1110     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1111     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1112     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1113     NL_TEST_ASSERT(inSuite, matches);
1114     TestContextReset(theContext);
1115
1116     nlEXPECT_ACTION_PRINT(expect4, expect_next4, nlASSERT_TEST_ACTION("expect4"), "nlEXPECT_ACTION_PRINT");
1117  expect_next4:
1118     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "expect4", "nlEXPECT_ACTION_PRINT, ", "TestExpect: expect4 test\n", __LINE__ - 2);
1119     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1120     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1121     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1122     NL_TEST_ASSERT(inSuite, matches);
1123     TestContextReset(theContext);
1124
1125     // nlEXPECT_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1126
1127     nlEXPECT_SUCCESS(status1, expect_next5);
1128     goto expect_next6;
1129  expect_next5:
1130     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "status1 == 0", "", "", __LINE__ - 3);
1131     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1132     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1133     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1134     NL_TEST_ASSERT(inSuite, matches);
1135     TestContextReset(theContext);
1136
1137     nlEXPECT_SUCCESS_PRINT(status2, expect_next6, "nlEXPECT_SUCCESS_PRINT test");
1138     goto expect_next7;
1139  expect_next6:
1140     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "status2 == 0", "nlEXPECT_SUCCESS_PRINT test, ", "", __LINE__ - 3);
1141     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1142     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1143     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1144     NL_TEST_ASSERT(inSuite, matches);
1145     TestContextReset(theContext);
1146
1147     nlEXPECT_SUCCESS_ACTION(status3, expect_next7, nlASSERT_TEST_ACTION("status3"));
1148     goto expect_next8;
1149  expect_next7:
1150     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "status3 == 0", "", "TestExpect: status3 test\n", __LINE__ - 3);
1151     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1152     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1153     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1154     NL_TEST_ASSERT(inSuite, matches);
1155     TestContextReset(theContext);
1156
1157     nlEXPECT_SUCCESS_ACTION_PRINT(status4, expect_next8, nlASSERT_TEST_ACTION("status4"), "nlEXPECT_SUCCESS_ACTION_PRINT test");
1158     goto expect_next9;
1159  expect_next8:
1160     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "status4 == 0", "nlEXPECT_SUCCESS_ACTION_PRINT test, ", "TestExpect: status4 test\n", __LINE__ - 3);
1161     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1162     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1163     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1164     NL_TEST_ASSERT(inSuite, matches);
1165     TestContextReset(theContext);
1166
1167     // nlNEXPECT{,PRINT,ACTION,ACTION_PRINT}
1168
1169     nlNEXPECT(expect5, expect_next9);
1170     goto expect_next10;
1171  expect_next9:
1172     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "!(expect5)", "", "", __LINE__ - 3);
1173     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1174     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1175     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1176     NL_TEST_ASSERT(inSuite, matches);
1177     TestContextReset(theContext);
1178
1179     nlNEXPECT_PRINT(expect6, expect_next10, "nlNEXPECT_PRINT test");
1180     goto expect_next11;
1181  expect_next10:
1182     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "!(expect6)", "nlNEXPECT_PRINT test, ", "", __LINE__ - 3);
1183     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1184     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1185     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1186     NL_TEST_ASSERT(inSuite, matches);
1187     TestContextReset(theContext);
1188
1189     nlNEXPECT_ACTION(expect7, expect_next11, nlASSERT_TEST_ACTION("expect7"));
1190     goto expect_next12;
1191  expect_next11:
1192     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "!(expect7)", "", "TestExpect: expect7 test\n", __LINE__ - 3);
1193     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1194     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1195     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1196     NL_TEST_ASSERT(inSuite, matches);
1197     TestContextReset(theContext);
1198
1199     nlNEXPECT_ACTION_PRINT(expect8, expect_next12, nlASSERT_TEST_ACTION("expect8"), "nlNEXPECT_ACTION_PRINT test");
1200     goto expect_next13;
1201  expect_next12:
1202     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mExpect, "!(expect8)", "nlNEXPECT_ACTION_PRINT test, ", "TestExpect: expect8 test\n",  __LINE__ - 3);
1203     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldBacktrace == theContext->mDidBacktrace);
1204     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldLog       == theContext->mDidLog);
1205     NL_TEST_ASSERT(inSuite, theContext->mExpect.mShouldTrap      == theContext->mDidTrap);
1206     NL_TEST_ASSERT(inSuite, matches);
1207     TestContextReset(theContext);
1208
1209  expect_next13:
1210     return;
1211 }
1212
1213 /**
1214  *  Test the nl[N]DESIRE* style of macros for correct operation.
1215  */
1216 static void TestDesire(nlTestSuite *inSuite, void *inContext)
1217 {
1218     struct TestContext * theContext = (struct TestContext *)(inContext);
1219     bool                 desire1, desire2, desire3, desire4;
1220     bool                 desire5, desire6, desire7, desire8;
1221     int                  status1, status2, status3, status4;
1222     bool                 matches;
1223
1224     // Establish test preconditions.
1225
1226     desire1 = desire2 = desire3 = desire4 = false;
1227     desire5 = desire6 = desire7 = desire8 = true;
1228     status1 = status2 = status3 = status4 = -1;
1229
1230     // nlDESIRE{,_PRINT,_ACTION,_ACTION_PRINT}
1231
1232     nlDESIRE(desire1, desire_next1);
1233     goto desire_next2;
1234  desire_next1:
1235     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "desire1", "", "", __LINE__ - 3);
1236     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1237     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1238     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1239     NL_TEST_ASSERT(inSuite, matches);
1240     TestContextReset(theContext);
1241
1242     nlDESIRE_PRINT(desire2, desire_next2, "nlDESIRE_PRINT test");
1243     goto desire_next3;
1244  desire_next2:
1245     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "desire2", "nlDESIRE_PRINT test, ", "", __LINE__ - 3);
1246     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1247     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1248     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1249     NL_TEST_ASSERT(inSuite, matches);
1250     TestContextReset(theContext);
1251
1252     nlDESIRE_ACTION(desire3, desire_next3, nlASSERT_TEST_ACTION("desire3"));
1253     goto desire_next4;
1254  desire_next3:
1255     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "desire3", "", "TestDesire: desire3 test\n", __LINE__ - 3);
1256     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1257     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1258     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1259     NL_TEST_ASSERT(inSuite, matches);
1260     TestContextReset(theContext);
1261
1262     nlDESIRE_ACTION_PRINT(desire4, desire_next4, nlASSERT_TEST_ACTION("desire4"), "nlDESIRE_ACTION_PRINT");
1263     goto desire_next5;
1264  desire_next4:
1265     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "desire4", "nlDESIRE_ACTION_PRINT, ", "TestDesire: desire4 test\n", __LINE__ - 3);
1266     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1267     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1268     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1269     NL_TEST_ASSERT(inSuite, matches);
1270     TestContextReset(theContext);
1271
1272     // nlDESIRE_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1273
1274     nlDESIRE_SUCCESS(status1, desire_next5);
1275     goto desire_next6;
1276  desire_next5:
1277     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "status1 == 0", "", "", __LINE__ - 3);
1278     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1279     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1280     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1281     NL_TEST_ASSERT(inSuite, matches);
1282     TestContextReset(theContext);
1283
1284     nlDESIRE_SUCCESS_PRINT(status2, desire_next6, "nlDESIRE_SUCCESS_PRINT test");
1285     goto desire_next7;
1286  desire_next6:
1287     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "status2 == 0", "nlDESIRE_SUCCESS_PRINT test, ", "", __LINE__ - 3);
1288     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1289     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1290     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1291     NL_TEST_ASSERT(inSuite, matches);
1292     TestContextReset(theContext);
1293
1294     nlDESIRE_SUCCESS_ACTION(status3, desire_next7, nlASSERT_TEST_ACTION("status3"));
1295     goto desire_next8;
1296  desire_next7:
1297     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "status3 == 0", "", "TestDesire: status3 test\n", __LINE__ - 3);
1298     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1299     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1300     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1301     NL_TEST_ASSERT(inSuite, matches);
1302     TestContextReset(theContext);
1303
1304     nlDESIRE_SUCCESS_ACTION_PRINT(status4, desire_next8, nlASSERT_TEST_ACTION("status4"), "nlDESIRE_SUCCESS_ACTION_PRINT test");
1305     goto desire_next9;
1306  desire_next8:
1307     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "status4 == 0", "nlDESIRE_SUCCESS_ACTION_PRINT test, ", "TestDesire: status4 test\n", __LINE__ - 3);
1308     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1309     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1310     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1311     NL_TEST_ASSERT(inSuite, matches);
1312     TestContextReset(theContext);
1313
1314     // nlNDESIRE{,PRINT,ACTION,ACTION_PRINT}
1315
1316     nlNDESIRE(desire5, desire_next9);
1317     goto desire_next10;
1318  desire_next9:
1319     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "!(desire5)", "", "", __LINE__ - 3);
1320     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1321     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1322     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1323     NL_TEST_ASSERT(inSuite, matches);
1324     TestContextReset(theContext);
1325
1326     nlNDESIRE_PRINT(desire6, desire_next10, "nlNDESIRE_PRINT test");
1327     goto desire_next11;
1328  desire_next10:
1329     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "!(desire6)", "nlNDESIRE_PRINT test, ", "",  __LINE__ - 3);
1330     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1331     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1332     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1333     NL_TEST_ASSERT(inSuite, matches);
1334     TestContextReset(theContext);
1335
1336     nlNDESIRE_ACTION(desire7, desire_next11, nlASSERT_TEST_ACTION("desire7"));
1337     goto desire_next12;
1338  desire_next11:
1339     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "!(desire7)", "", "TestDesire: desire7 test\n", __LINE__ - 3);
1340     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1341     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1342     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1343     NL_TEST_ASSERT(inSuite, matches);
1344     TestContextReset(theContext);
1345
1346     nlNDESIRE_ACTION_PRINT(desire8, desire_next12, nlASSERT_TEST_ACTION("desire8"), "nlNDESIRE_ACTION_PRINT test");
1347     goto desire_next13;
1348  desire_next12:
1349     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mDesire, "!(desire8)", "nlNDESIRE_ACTION_PRINT test, ", "TestDesire: desire8 test\n", __LINE__ - 3);
1350     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldBacktrace == theContext->mDidBacktrace);
1351     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldLog       == theContext->mDidLog);
1352     NL_TEST_ASSERT(inSuite, theContext->mDesire.mShouldTrap      == theContext->mDidTrap);
1353     NL_TEST_ASSERT(inSuite, matches);
1354     TestContextReset(theContext);
1355
1356  desire_next13:
1357     return;
1358 }
1359
1360 /**
1361  *  Test the nl[N]REQUIRE* style of macros for correct operation.
1362  */
1363 static void TestRequire(nlTestSuite *inSuite, void *inContext)
1364 {
1365     struct TestContext * theContext = (struct TestContext *)(inContext);
1366     bool                 require1, require2, require3, require4;
1367     bool                 require5, require6, require7, require8;
1368     int                  status1, status2, status3, status4;
1369     bool                 matches;
1370
1371     // Establish test preconditions.
1372
1373     require1 = require2 = require3 = require4 = false;
1374     require5 = require6 = require7 = require8 = true;
1375     status1 = status2 = status3 = status4 = -1;
1376
1377     // nlREQUIRE{,_PRINT,_ACTION,_ACTION_PRINT}
1378
1379     nlREQUIRE(require1, require_next1);
1380     goto require_next2;
1381  require_next1:
1382     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "require1", "", "", __LINE__ - 3);
1383     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1384     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1385     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1386     NL_TEST_ASSERT(inSuite, matches);
1387     TestContextReset(theContext);
1388
1389     nlREQUIRE_PRINT(require2, require_next2, "nlREQUIRE_PRINT test");
1390     goto require_next3;
1391  require_next2:
1392     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "require2", "nlREQUIRE_PRINT test, ", "", __LINE__ - 3);
1393     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1394     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1395     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1396     NL_TEST_ASSERT(inSuite, matches);
1397     TestContextReset(theContext);
1398
1399     nlREQUIRE_ACTION(require3, require_next3, nlASSERT_TEST_ACTION("require3"));
1400     goto require_next4;
1401  require_next3:
1402     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "require3", "", "TestRequire: require3 test\n", __LINE__ - 3);
1403     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1404     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1405     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1406     NL_TEST_ASSERT(inSuite, matches);
1407     TestContextReset(theContext);
1408
1409     nlREQUIRE_ACTION_PRINT(require4, require_next4, nlASSERT_TEST_ACTION("require4"), "nlREQUIRE_ACTION_PRINT");
1410     goto require_next5;
1411  require_next4:
1412     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "require4", "nlREQUIRE_ACTION_PRINT, ", "TestRequire: require4 test\n", __LINE__ - 3);
1413     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1414     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1415     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1416     NL_TEST_ASSERT(inSuite, matches);
1417     TestContextReset(theContext);
1418
1419     // nlREQUIRE_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1420
1421     nlREQUIRE_SUCCESS(status1, require_next5);
1422     goto require_next6;
1423  require_next5:
1424     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "status1 == 0", "", "", __LINE__ - 3);
1425     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1426     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1427     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1428     NL_TEST_ASSERT(inSuite, matches);
1429     TestContextReset(theContext);
1430
1431     nlREQUIRE_SUCCESS_PRINT(status2, require_next6, "nlREQUIRE_SUCCESS_PRINT test");
1432     goto require_next7;
1433  require_next6:
1434     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "status2 == 0", "nlREQUIRE_SUCCESS_PRINT test, ", "", __LINE__ - 3);
1435     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1436     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1437     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1438     NL_TEST_ASSERT(inSuite, matches);
1439     TestContextReset(theContext);
1440
1441     nlREQUIRE_SUCCESS_ACTION(status3, require_next7, nlASSERT_TEST_ACTION("status3"));
1442     goto require_next8;
1443  require_next7:
1444     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "status3 == 0", "", "TestRequire: status3 test\n", __LINE__ - 3);
1445     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1446     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1447     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1448     NL_TEST_ASSERT(inSuite, matches);
1449     TestContextReset(theContext);
1450
1451     nlREQUIRE_SUCCESS_ACTION_PRINT(status4, require_next8, nlASSERT_TEST_ACTION("status4"), "nlREQUIRE_SUCCESS_ACTION_PRINT test");
1452     goto require_next9;
1453  require_next8:
1454     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "status4 == 0", "nlREQUIRE_SUCCESS_ACTION_PRINT test, ", "TestRequire: status4 test\n", __LINE__ - 3);
1455     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1456     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1457     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1458     NL_TEST_ASSERT(inSuite, matches);
1459     TestContextReset(theContext);
1460
1461     // nlNREQUIRE{,PRINT,ACTION,ACTION_PRINT}
1462
1463     nlNREQUIRE(require5, require_next9);
1464     goto require_next10;
1465  require_next9:
1466     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "!(require5)", "", "", __LINE__ - 3);
1467     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1468     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1469     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1470     NL_TEST_ASSERT(inSuite, matches);
1471     TestContextReset(theContext);
1472
1473     nlNREQUIRE_PRINT(require6, require_next10, "nlNREQUIRE_PRINT test");
1474     goto require_next11;
1475  require_next10:
1476     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "!(require6)", "nlNREQUIRE_PRINT test, ", "", __LINE__ - 3);
1477     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1478     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1479     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1480     NL_TEST_ASSERT(inSuite, matches);
1481     TestContextReset(theContext);
1482
1483     nlNREQUIRE_ACTION(require7, require_next11, nlASSERT_TEST_ACTION("require7"));
1484     goto require_next12;
1485  require_next11:
1486     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "!(require7)", "", "TestRequire: require7 test\n", __LINE__ - 3);
1487     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1488     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1489     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1490     NL_TEST_ASSERT(inSuite, matches);
1491     TestContextReset(theContext);
1492
1493     nlNREQUIRE_ACTION_PRINT(require8, require_next12, nlASSERT_TEST_ACTION("require8"), "nlNREQUIRE_ACTION_PRINT test");
1494     goto require_next13;
1495  require_next12:
1496     matches = nlASSERT_TEST_CHECK_EXPECTED(theContext, &theContext->mRequire, "!(require8)", "nlNREQUIRE_ACTION_PRINT test, ", "TestRequire: require8 test\n", __LINE__ - 3);
1497     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldBacktrace == theContext->mDidBacktrace);
1498     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldLog       == theContext->mDidLog);
1499     NL_TEST_ASSERT(inSuite, theContext->mRequire.mShouldTrap      == theContext->mDidTrap);
1500     NL_TEST_ASSERT(inSuite, matches);
1501     TestContextReset(theContext);
1502
1503  require_next13:
1504     return;
1505 }
1506
1507 static const nlTest sTests[] = {
1508     NL_TEST_DEF("production",   TestProduction),
1509     NL_TEST_DEF("assert",       TestAssert),
1510     NL_TEST_DEF("abort",        TestAbort),
1511     NL_TEST_DEF("check",        TestCheck),
1512     NL_TEST_DEF("verify",       TestVerify),
1513     NL_TEST_DEF("precondition", TestPrecondition),
1514     NL_TEST_DEF("expect",       TestExpect),
1515     NL_TEST_DEF("desire",       TestDesire),
1516     NL_TEST_DEF("require",      TestRequire),
1517     NL_TEST_SENTINEL()
1518 };
1519
1520 /**
1521  *  Set up the test suite by resetting the test context, initializing
1522  *  the expected configuration flags, and allocating memory for the
1523  *  actual and expected logging buffers.
1524  */
1525 static int TestSetup(void *inContext)
1526 {
1527     struct TestContext *theContext = (struct TestContext *)(inContext);
1528     const size_t        offset     = 0;
1529     const size_t        size       = 1024;
1530     int                 status     = SUCCESS;
1531     void *              p;
1532     bool                abort;
1533
1534     TestContextReset(theContext);
1535
1536     theContext->mWantProduction = NL_ASSERT_TEST_WANT_PRODUCTION;
1537     theContext->mIsProduction   = NL_ASSERT_PRODUCTION;
1538
1539     /*
1540      * nlASSERT is absent in production code and should only abort in
1541      * non-production code when NL_ASSERT_TEST_WANT_ABORT is enabled.
1542      */
1543 #if NL_ASSERT_PRODUCTION
1544     abort      = false;
1545 #else
1546     abort      = NL_ASSERT_TEST_WANT_ABORT;
1547 #endif
1548
1549     AssertStyleContextInit(&theContext->mAssert,       __NL_ASSERT_TEST_ASSERT_FLAGS,       abort,                     !theContext->mIsProduction);
1550     AssertStyleContextInit(&theContext->mAbort,        __NL_ASSERT_TEST_ABORT_FLAGS,        NL_ASSERT_TEST_WANT_ABORT, true);
1551     AssertStyleContextInit(&theContext->mCheck,        __NL_ASSERT_TEST_CHECK_FLAGS,        false,                     !theContext->mIsProduction);
1552     AssertStyleContextInit(&theContext->mVerify,       __NL_ASSERT_TEST_VERIFY_FLAGS,       false,                     true);
1553     AssertStyleContextInit(&theContext->mPrecondition, __NL_ASSERT_TEST_PRECONDITION_FLAGS, false,                     true);
1554     AssertStyleContextInit(&theContext->mExpect,       __NL_ASSERT_TEST_EXPECT_FLAGS,       false,                     true);
1555     AssertStyleContextInit(&theContext->mDesire,       __NL_ASSERT_TEST_DESIRE_FLAGS,       false,                     true);
1556     AssertStyleContextInit(&theContext->mRequire,      __NL_ASSERT_TEST_REQUIRE_FLAGS,      false,                     true);
1557
1558     p = malloc(size);
1559
1560     if (p == NULL)
1561     {
1562         status = FAILURE;
1563     }
1564     else
1565     {
1566         theContext->mActual.mBuffer = p;
1567         theContext->mActual.mBufferOffset = offset;
1568         theContext->mActual.mBufferSize = size;
1569
1570         p = malloc(size);
1571
1572         if (p == NULL)
1573         {
1574             status = FAILURE;
1575         }
1576         else
1577         {
1578             theContext->mExpected.mBuffer = p;
1579             theContext->mExpected.mBufferOffset = offset;
1580             theContext->mExpected.mBufferSize = size;
1581         }
1582     }
1583
1584     return (status);
1585 }
1586
1587 /**
1588  *  Tear down the test suite by deallocating memory for the actual and
1589  *  expected logging buffers and resetting the test context.
1590  */
1591 static int TestTeardown(void *inContext)
1592 {
1593     struct TestContext *theContext = (struct TestContext *)(inContext);
1594
1595     if (theContext->mActual.mBuffer != NULL) {
1596         free(theContext->mActual.mBuffer);
1597     }
1598
1599     if (theContext->mExpected.mBuffer != NULL) {
1600         free(theContext->mExpected.mBuffer);
1601     }
1602
1603     TestContextReset(theContext);
1604
1605     return (SUCCESS);
1606 }
1607
1608 int main(void)
1609 {
1610     nlTestSuite theSuite = {
1611         "nlassert",
1612         &sTests[0],
1613         TestSetup,
1614         TestTeardown
1615     };
1616
1617     nlTestSetOutputStyle(OUTPUT_CSV);
1618
1619     nlTestRunner(&theSuite, &sContext);
1620
1621     return nlTestRunnerStats(&theSuite);
1622 }