3 * Copyright (c) 2012-2015 Nest Labs, Inc.
6 * This document is the property of Nest. It is considered
7 * confidential and proprietary information.
9 * This document may not be reproduced or transmitted in any form,
10 * in whole or in part, without the express written permission of
17 * This file implements a unit test suite for the Nest Labs
18 * runtime assertion library.
30 #include "nlassert-test-config.h"
32 #define NL_ASSERT_COMPONENT_STRING "nlassert-test"
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);
39 #define NL_ASSERT_PRODUCTION (NL_ASSERT_TEST_WANT_PRODUCTION)
42 * Set the assertion trigger flags as desired by the test harness configuration
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)
59 #define __NL_TEST_ASSERT_FLAGS (NL_ASSERT_FLAG_NONE)
63 * Configure both the non-production and production ssertion interface
64 * family trigger flags with the defaults, if so requested, or as set
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
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
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 */
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.
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 */
112 #define NL_ASSERT_ABORT() \
114 nlassert_test_abort(); \
117 #define NL_ASSERT_BACKTRACE() \
119 nlassert_test_backtrace(); \
122 #define NL_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \
124 nlassert_test_log(NL_ASSERT_LOG_FORMAT_DEFAULT, \
126 (((aName) == 0) || (*(aName) == '\0')) ? "" : aName, \
127 (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ", \
129 ((aMessage == 0) ? "" : aMessage), \
130 ((aMessage == 0) ? "" : ", "), \
135 #define NL_ASSERT_TRAP() \
137 nlassert_test_trap(); \
140 #if NLASSERT_TEST_STDC
143 #include <nlassert.h>
145 #include <nlunit-test.h>
149 struct AssertStyleContext {
151 bool mShouldBacktrace;
154 bool mShouldLogActionOnly;
157 struct TestBufferContext {
159 size_t mBufferOffset;
164 struct TestBufferContext mActual;
165 struct TestBufferContext mExpected;
166 bool mWantProduction;
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;
184 static struct TestContext sContext;
187 * Reset a test buffer context by setting the offset to zero.
189 static void TestBufferContextReset(struct TestBufferContext *inContext)
191 if (inContext->mBuffer != NULL)
193 inContext->mBufferOffset = 0;
194 inContext->mBuffer[0] = '\0';
199 * Reset a test context by resetting both the actual and expected
200 * buffers and setting all of the abort, backtrace, log, and trap
203 static void TestContextReset(struct TestContext *inContext)
205 TestBufferContextReset(&inContext->mActual);
206 TestBufferContextReset(&inContext->mExpected);
208 sContext.mDidAbort = false;
209 sContext.mDidBacktrace = false;
210 sContext.mDidLog = false;
211 sContext.mDidTrap = false;
215 * Initialize the assertion style context by determining whether or
216 * not a backtrace, log, and trap are expected on assertion trigger.
218 static void AssertStyleContextInit(struct AssertStyleContext *inContext, const uint32_t inFlags, bool inAbort, bool inLogActionOnly)
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;
229 * Test-specific hook for #NL_ASSERT_ABORT used with nlASSERT.
231 static void __attribute__((unused)) nlassert_test_abort(void)
233 sContext.mDidAbort = true;
237 * Test-specific hook for #NL_ASSERT_BACKTRACE used with all styles of
240 static void __attribute__((unused)) nlassert_test_backtrace(void)
242 sContext.mDidBacktrace = true;
246 * Test-specific hook for #NL_ASSERT_TRAP used with all styles of
249 static void __attribute__((unused)) nlassert_test_trap(void)
251 sContext.mDidTrap = true;
254 static void nlassert_test_vlog_with_buffer(struct TestBufferContext *inBuffer, const char *inFormat, va_list inArguments)
256 const size_t size = inBuffer->mBufferSize - inBuffer->mBufferOffset;
257 char * p = inBuffer->mBuffer + inBuffer->mBufferOffset;
260 n = vsnprintf(p, size, inFormat, inArguments);
263 inBuffer->mBufferOffset += n;
267 static void nlassert_test_log_with_buffer(struct TestBufferContext *inBuffer, const char *inFormat, ...)
271 va_start(args, inFormat);
273 nlassert_test_vlog_with_buffer(inBuffer, inFormat, args);
278 static void _nlassert_test_log(const char *inFormat, ...)
282 va_start(args, inFormat);
284 nlassert_test_vlog_with_buffer(&sContext.mActual, inFormat, args);
290 * Test-specific hook for #NL_ASSERT_LOG used with all styles of
293 static void __attribute__((unused)) nlassert_test_log(const char *inFormat, ...)
297 sContext.mDidLog = true;
299 va_start(args, inFormat);
301 nlassert_test_vlog_with_buffer(&sContext.mActual, inFormat, args);
306 static void nlassert_test_action(const char *function, const char *message)
308 _nlassert_test_log("%s: %s test\n", function, message);
311 #define nlASSERT_TEST_ACTION(message) nlassert_test_action(__func__, message)
313 #define nlASSERT_TEST_CHECK_EXPECTED(context, style, assertion, extra, action, line) \
314 nlAssertTestCheckExpected(context, style, assertion, extra, action, __FILE__, line)
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)
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
328 if (inStyle->mShouldLog)
330 nlassert_test_log_with_buffer(&inContext->mExpected,
331 "%s%s%s%s%s%s%s%s%u%s%s",
333 NL_ASSERT_COMPONENT_STRING ": ",
344 else if (inStyle->mShouldLogActionOnly)
346 nlassert_test_log_with_buffer(&inContext->mExpected,
351 comparison = strcmp(inContext->mActual.mBuffer, inContext->mExpected.mBuffer);
352 matches = (comparison == 0);
355 fprintf(stderr, "ACTUAL @ %u: %s\n", inLine, inContext->mActual.mBuffer);
356 fprintf(stderr, "EXPECT @ %u: %s\n", inLine, inContext->mExpected.mBuffer);
363 * Test whether the production vs. non-production aspect of
364 * assertions is in effect and matches what is expected.
366 static void TestProduction(nlTestSuite *inSuite, void *inContext)
368 struct TestContext *theContext = inContext;
370 NL_TEST_ASSERT(inSuite, theContext->mWantProduction == NL_ASSERT_PRODUCTION);
373 #if NLASSERT_TEST_STDC
375 * Test the Standard C Library macro workalike for correct operation.
377 static void TestStandardCAssert(nlTestSuite *inSuite, void *inContext)
379 struct TestContext * theContext = inContext;
383 // Test the assert, Standard C Library workalike
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);
399 * Test the nlASSERT macro for correct operation.
401 static void TestNestLabsAssert(nlTestSuite *inSuite, void *inContext)
403 struct TestContext * theContext = inContext;
404 bool assert1, assert2;
409 assert1 = assert2 = false;
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);
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);
430 static void TestAssert(nlTestSuite *inSuite, void *inContext)
432 #if NLASSERT_TEST_STDC
433 TestStandardCAssert(inSuite, inContext);
435 TestNestLabsAssert(inSuite, inContext);
439 * Test the nlABORT macro for correct operation.
441 static void TestAbort(nlTestSuite *inSuite, void *inContext)
443 struct TestContext * theContext = inContext;
449 abort1 = abort2 = false;
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);
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);
471 * Test the nl[N]CHECK* style of macros for correct operation.
473 static void TestCheck(nlTestSuite *inSuite, void *inContext)
475 struct TestContext * theContext = inContext;
476 bool check1, check2, check3;
477 bool check5, check6, check7;
478 int status1, status2, status3;
483 check1 = check2 = check3 = false;
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);
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);
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);
509 // Test nlCHECK_SUCCESS
511 status1 = status2 = status3 = -1;
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);
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);
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);
539 check5 = check6 = check7 = true;
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);
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);
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);
567 * Test the nl[N]VERIFY* style of macros for correct operation.
569 static void TestVerify(nlTestSuite *inSuite, void *inContext)
571 struct TestContext * theContext = inContext;
572 bool verify1, verify2, verify3;
573 bool verify4, verify5, verify6, verify7, verify8;
574 int status1, status2, status3, status4;
579 verify1 = verify2 = verify3 = false;
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);
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);
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);
607 status1 = status2 = status3 = -1;
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);
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);
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);
635 verify4 = verify5 = verify6 = true;
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);
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);
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);
661 // Tests to make sure the break keyword works as an action inside
662 // control structures
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.
674 nlVERIFY_ACTION(verify7, break);
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);
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.
688 nlVERIFY_SUCCESS_ACTION(status4, break);
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);
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.
702 nlNVERIFY_ACTION(verify8, break);
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);
711 static void TestPreconditionVoid(unsigned int *outLine)
713 const bool precondition1 = false;
715 *outLine = __LINE__ + 2;
717 nlPRECONDITION(precondition1);
720 static void TestPreconditionActionVoid(unsigned int *outLine)
722 const bool precondition2 = false;
724 *outLine = __LINE__ + 2;
726 nlPRECONDITION_ACTION(precondition2, nlASSERT_TEST_ACTION("precondition2"));
729 static void TestPreconditionPrintVoid(unsigned int *outLine)
731 const bool precondition3 = false;
733 *outLine = __LINE__ + 2;
735 nlPRECONDITION_PRINT(precondition3, "nlPRECONDITION_PRINT test");
738 static void TestNotPreconditionVoid(unsigned int *outLine)
740 const bool precondition4 = true;
742 *outLine = __LINE__ + 2;
744 nlNPRECONDITION(precondition4);
747 static void TestNotPreconditionActionVoid(unsigned int *outLine)
749 const bool precondition5 = true;
751 *outLine = __LINE__ + 2;
753 nlNPRECONDITION_ACTION(precondition5, nlASSERT_TEST_ACTION("precondition5"));
756 static void TestNotPreconditionPrintVoid(unsigned int *outLine)
758 const bool precondition6 = true;
760 *outLine = __LINE__ + 2;
762 nlNPRECONDITION_PRINT(precondition6, "nlNPRECONDITION_PRINT test");
765 static void TestPreconditionSuccessVoid(unsigned int *outLine)
767 const int status1 = -1;
769 *outLine = __LINE__ + 2;
771 nlPRECONDITION_SUCCESS(status1);
774 static void TestPreconditionSuccessActionVoid(unsigned int *outLine)
776 const int status2 = -1;
778 *outLine = __LINE__ + 2;
780 nlPRECONDITION_SUCCESS_ACTION(status2, nlASSERT_TEST_ACTION("status2"));
783 static void TestPreconditionSuccessPrintVoid(unsigned int *outLine)
785 const int status3 = -1;
787 *outLine = __LINE__ + 2;
789 nlPRECONDITION_SUCCESS_PRINT(status3, "nlPRECONDITION_SUCCESS_PRINT test");
792 static int TestPreconditionValue(unsigned int *outLine, int inStatus)
794 const bool precondition7 = false;
796 *outLine = __LINE__ + 2;
798 nlPRECONDITION_VALUE(precondition7, inStatus);
803 static int TestPreconditionValueAction(unsigned int *outLine, int inStatus)
805 const bool precondition8 = false;
807 *outLine = __LINE__ + 2;
809 nlPRECONDITION_VALUE_ACTION(precondition8, inStatus, nlASSERT_TEST_ACTION("precondition8"));
814 static int TestPreconditionValuePrint(unsigned int *outLine, int inStatus)
816 const bool precondition9 = false;
818 *outLine = __LINE__ + 2;
820 nlPRECONDITION_VALUE_PRINT(precondition9, inStatus, "nlPRECONDITION_VALUE_PRINT test");
825 static int TestPreconditionValueSuccess(unsigned int *outLine, int inStatus)
827 const int status4 = -1;
829 *outLine = __LINE__ + 2;
831 nlPRECONDITION_VALUE_SUCCESS(status4, inStatus);
836 static int TestPreconditionValueSuccessAction(unsigned int *outLine, int inStatus)
838 const int status5 = -1;
840 *outLine = __LINE__ + 2;
842 nlPRECONDITION_VALUE_SUCCESS_ACTION(status5, inStatus, nlASSERT_TEST_ACTION("status5"));
847 static int TestPreconditionValueSuccessPrint(unsigned int *outLine, int inStatus)
849 const int status6 = -1;
851 *outLine = __LINE__ + 2;
853 nlPRECONDITION_VALUE_SUCCESS_PRINT(status6, inStatus, "nlPRECONDITION_VALUE_SUCCESS_PRINT test");
858 static int TestNotPreconditionValue(unsigned int *outLine, int inStatus)
860 const bool precondition10 = true;
862 *outLine = __LINE__ + 2;
864 nlNPRECONDITION_VALUE(precondition10, inStatus);
869 static int TestNotPreconditionValueAction(unsigned int *outLine, int inStatus)
871 const bool precondition11 = true;
873 *outLine = __LINE__ + 2;
875 nlNPRECONDITION_VALUE_ACTION(precondition11, inStatus, nlASSERT_TEST_ACTION("precondition11"));
880 static int TestNotPreconditionValuePrint(unsigned int *outLine, int inStatus)
882 const bool precondition12 = true;
884 *outLine = __LINE__ + 2;
886 nlNPRECONDITION_VALUE_PRINT(precondition12, inStatus, "nlNPRECONDITION_VALUE_PRINT test");
892 * Test the nl[N]PRECONDITION* style of macros for correct operation.
894 static void TestPrecondition(nlTestSuite *inSuite, void *inContext)
896 struct TestContext * theContext = (struct TestContext *)(inContext);
901 // nlPRECONDITION{,_ACTION,_PRINT}
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);
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);
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);
927 // nlNPRECONDITION{,_ACTION,_PRINT}
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);
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);
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);
953 // nlPRECONDITION_SUCCESS{,_ACTION,_PRINT}
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);
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);
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);
979 // nlPRECONDITION_VALUE{,_ACTION,_PRINT}
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);
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);
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);
1008 // nlPRECONDITION_VALUE_SUCCESS{,_ACTION,_PRINT}
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);
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);
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);
1037 // nlNPRECONDITION_VALUE{,_ACTION,_PRINT}
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);
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);
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);
1068 * Test the nl[N]EXPECT* style of macros for correct operation.
1070 static void TestExpect(nlTestSuite *inSuite, void *inContext)
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;
1078 // Establish test preconditions.
1080 expect1 = expect2 = expect3 = expect4 = false;
1081 expect5 = expect6 = expect7 = expect8 = true;
1082 status1 = status2 = status3 = status4 = -1;
1084 // nlEXPECT{,_PRINT,_ACTION,_ACTION_PRINT}
1086 nlEXPECT(expect1, 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);
1096 nlEXPECT_PRINT(expect2, expect_next2, "nlEXPECT_PRINT test");
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);
1106 nlEXPECT_ACTION(expect3, expect_next3, nlASSERT_TEST_ACTION("expect3"));
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);
1116 nlEXPECT_ACTION_PRINT(expect4, expect_next4, nlASSERT_TEST_ACTION("expect4"), "nlEXPECT_ACTION_PRINT");
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);
1125 // nlEXPECT_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1127 nlEXPECT_SUCCESS(status1, 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);
1137 nlEXPECT_SUCCESS_PRINT(status2, expect_next6, "nlEXPECT_SUCCESS_PRINT test");
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);
1147 nlEXPECT_SUCCESS_ACTION(status3, expect_next7, nlASSERT_TEST_ACTION("status3"));
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);
1157 nlEXPECT_SUCCESS_ACTION_PRINT(status4, expect_next8, nlASSERT_TEST_ACTION("status4"), "nlEXPECT_SUCCESS_ACTION_PRINT test");
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);
1167 // nlNEXPECT{,PRINT,ACTION,ACTION_PRINT}
1169 nlNEXPECT(expect5, 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);
1179 nlNEXPECT_PRINT(expect6, expect_next10, "nlNEXPECT_PRINT test");
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);
1189 nlNEXPECT_ACTION(expect7, expect_next11, nlASSERT_TEST_ACTION("expect7"));
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);
1199 nlNEXPECT_ACTION_PRINT(expect8, expect_next12, nlASSERT_TEST_ACTION("expect8"), "nlNEXPECT_ACTION_PRINT test");
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);
1214 * Test the nl[N]DESIRE* style of macros for correct operation.
1216 static void TestDesire(nlTestSuite *inSuite, void *inContext)
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;
1224 // Establish test preconditions.
1226 desire1 = desire2 = desire3 = desire4 = false;
1227 desire5 = desire6 = desire7 = desire8 = true;
1228 status1 = status2 = status3 = status4 = -1;
1230 // nlDESIRE{,_PRINT,_ACTION,_ACTION_PRINT}
1232 nlDESIRE(desire1, 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);
1242 nlDESIRE_PRINT(desire2, desire_next2, "nlDESIRE_PRINT test");
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);
1252 nlDESIRE_ACTION(desire3, desire_next3, nlASSERT_TEST_ACTION("desire3"));
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);
1262 nlDESIRE_ACTION_PRINT(desire4, desire_next4, nlASSERT_TEST_ACTION("desire4"), "nlDESIRE_ACTION_PRINT");
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);
1272 // nlDESIRE_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1274 nlDESIRE_SUCCESS(status1, 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);
1284 nlDESIRE_SUCCESS_PRINT(status2, desire_next6, "nlDESIRE_SUCCESS_PRINT test");
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);
1294 nlDESIRE_SUCCESS_ACTION(status3, desire_next7, nlASSERT_TEST_ACTION("status3"));
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);
1304 nlDESIRE_SUCCESS_ACTION_PRINT(status4, desire_next8, nlASSERT_TEST_ACTION("status4"), "nlDESIRE_SUCCESS_ACTION_PRINT test");
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);
1314 // nlNDESIRE{,PRINT,ACTION,ACTION_PRINT}
1316 nlNDESIRE(desire5, 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);
1326 nlNDESIRE_PRINT(desire6, desire_next10, "nlNDESIRE_PRINT test");
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);
1336 nlNDESIRE_ACTION(desire7, desire_next11, nlASSERT_TEST_ACTION("desire7"));
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);
1346 nlNDESIRE_ACTION_PRINT(desire8, desire_next12, nlASSERT_TEST_ACTION("desire8"), "nlNDESIRE_ACTION_PRINT test");
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);
1361 * Test the nl[N]REQUIRE* style of macros for correct operation.
1363 static void TestRequire(nlTestSuite *inSuite, void *inContext)
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;
1371 // Establish test preconditions.
1373 require1 = require2 = require3 = require4 = false;
1374 require5 = require6 = require7 = require8 = true;
1375 status1 = status2 = status3 = status4 = -1;
1377 // nlREQUIRE{,_PRINT,_ACTION,_ACTION_PRINT}
1379 nlREQUIRE(require1, 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);
1389 nlREQUIRE_PRINT(require2, require_next2, "nlREQUIRE_PRINT test");
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);
1399 nlREQUIRE_ACTION(require3, require_next3, nlASSERT_TEST_ACTION("require3"));
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);
1409 nlREQUIRE_ACTION_PRINT(require4, require_next4, nlASSERT_TEST_ACTION("require4"), "nlREQUIRE_ACTION_PRINT");
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);
1419 // nlREQUIRE_SUCCESS{,_PRINT,_ACTION,_ACTION_PRINT}
1421 nlREQUIRE_SUCCESS(status1, 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);
1431 nlREQUIRE_SUCCESS_PRINT(status2, require_next6, "nlREQUIRE_SUCCESS_PRINT test");
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);
1441 nlREQUIRE_SUCCESS_ACTION(status3, require_next7, nlASSERT_TEST_ACTION("status3"));
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);
1451 nlREQUIRE_SUCCESS_ACTION_PRINT(status4, require_next8, nlASSERT_TEST_ACTION("status4"), "nlREQUIRE_SUCCESS_ACTION_PRINT test");
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);
1461 // nlNREQUIRE{,PRINT,ACTION,ACTION_PRINT}
1463 nlNREQUIRE(require5, require_next9);
1464 goto require_next10;
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);
1473 nlNREQUIRE_PRINT(require6, require_next10, "nlNREQUIRE_PRINT test");
1474 goto require_next11;
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);
1483 nlNREQUIRE_ACTION(require7, require_next11, nlASSERT_TEST_ACTION("require7"));
1484 goto require_next12;
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);
1493 nlNREQUIRE_ACTION_PRINT(require8, require_next12, nlASSERT_TEST_ACTION("require8"), "nlNREQUIRE_ACTION_PRINT test");
1494 goto require_next13;
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);
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),
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.
1525 static int TestSetup(void *inContext)
1527 struct TestContext *theContext = (struct TestContext *)(inContext);
1528 const size_t offset = 0;
1529 const size_t size = 1024;
1530 int status = SUCCESS;
1534 TestContextReset(theContext);
1536 theContext->mWantProduction = NL_ASSERT_TEST_WANT_PRODUCTION;
1537 theContext->mIsProduction = NL_ASSERT_PRODUCTION;
1540 * nlASSERT is absent in production code and should only abort in
1541 * non-production code when NL_ASSERT_TEST_WANT_ABORT is enabled.
1543 #if NL_ASSERT_PRODUCTION
1546 abort = NL_ASSERT_TEST_WANT_ABORT;
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);
1566 theContext->mActual.mBuffer = p;
1567 theContext->mActual.mBufferOffset = offset;
1568 theContext->mActual.mBufferSize = size;
1578 theContext->mExpected.mBuffer = p;
1579 theContext->mExpected.mBufferOffset = offset;
1580 theContext->mExpected.mBufferSize = size;
1588 * Tear down the test suite by deallocating memory for the actual and
1589 * expected logging buffers and resetting the test context.
1591 static int TestTeardown(void *inContext)
1593 struct TestContext *theContext = (struct TestContext *)(inContext);
1595 if (theContext->mActual.mBuffer != NULL) {
1596 free(theContext->mActual.mBuffer);
1599 if (theContext->mExpected.mBuffer != NULL) {
1600 free(theContext->mExpected.mBuffer);
1603 TestContextReset(theContext);
1610 nlTestSuite theSuite = {
1617 nlTestSetOutputStyle(OUTPUT_CSV);
1619 nlTestRunner(&theSuite, &sContext);
1621 return nlTestRunnerStats(&theSuite);