Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
/**
 * @{
 * @name Macros that give different meaning depending on if we are compiling for UTs or production code
 *
 * 'FOREVER' helps test loops as this code will only run once in your unit-tests
 * 'MAIN' helps test your application main()
 */
#ifdef UNIT_TESTING
  #define FOREVER       for(bool __once = true; __once; __once = !__once)
  #define MAIN          application_main
#else
  #define FOREVER       for(;;)
  #define MAIN          main
#endif
/** @} */

/**
 * For production code, which is NOT UNIT_TEST, the NOOP() is truly a NOOP
 * For unit-test code, this helps spot branch coverage issues.  Example use case:
 * @code
 * if (foo) {
 * } else {
 *   NOOP("This branch should not happen");
 * }
 * @endcode
 */
#ifdef UNIT_TESTING
  #define NOOP(message)                      \
    do {                                 \
      volatile int _do_not_optimize = 0; \
      (void) _do_not_optimize;           \
    } while (0)
#else
  #define NOOP(message)
#endif

...

Code

...

Labs

Lab 1

Let us practice unit-testing, with a little bit of TDD thrown into the mix.

...