PIC24 Support Libraries
Macros | Functions
pic24_unittest.h File Reference
#include <stdint.h>

Go to the source code of this file.

Macros

#define TOSTRING(x)   _TOSTRING(x)
 
#define ERROR_FILE_LINE(msg)   "Error in " __FILE__ " line " TOSTRING(__LINE__) ": " msg
 
#define COMPILE_ASSERT(test, msg)   typedef char _COMPILE_ASSERT_SYMBOL(__LINE__, msg) [ ((test) ? 1 : -1) ]
 
#define ASSERT(test)   picAssert(test, ERROR_FILE_LINE("ASSERT(" #test ") failed.\n"))
 

Functions

void reportError (const char *message)
 
static void picAssert (uint8_t test, const char *message)
 

Detailed Description

Extremely simple unit testing framework, inspired by http://www.jera.com/techinfo/jtns/jtn002.html.

Definition in file pic24_unittest.h.

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   test)    picAssert(test, ERROR_FILE_LINE("ASSERT(" #test ") failed.\n"))

Assert that test is true. See picAssert for details. NOTE: only test results; DO NOT include main-line code in an ASSERT, since it can be compiled out. For example, ASSERT(myFunc()) is dangerous, since myFunc() will no longer be called if ASSERT is disabled by defining _NDEBUG.

Definition at line 94 of file pic24_unittest.h.

Referenced by compute_brg(), CONFIG_BAUDRATE_UART1(), CONFIG_PDSEL_UART1(), CONFIG_STOPBITS_UART1(), configUART1(), doReadPageFlash(), doWritePageFlash(), formatVar(), getReceiveErrorString(), getTimerPrescaleBits(), msToU16Ticks(), parseVarSpec(), stepCommandFindMachine(), stepReceiveMachine(), switchClock(), and usToU16Ticks().

◆ COMPILE_ASSERT

#define COMPILE_ASSERT (   test,
  msg 
)    typedef char _COMPILE_ASSERT_SYMBOL(__LINE__, msg) [ ((test) ? 1 : -1) ]

A useful compile-time assert macro. USAGE: COMPILE_ASSERT( condition, message_to_print_if_fails)

Note: these macros use typedef so they can't be use in a value assignment type macro Note: message_to_print_if_fails is used as C language variable in this clever little macro, SO.... your message must adhere to C variable naming rules, i.e. no spaces or funny characters. Use underscores or CamelCase to separate words.

Definition at line 80 of file pic24_unittest.h.

◆ ERROR_FILE_LINE

#define ERROR_FILE_LINE (   msg)    "Error in " __FILE__ " line " TOSTRING(__LINE__) ": " msg

A macro to add the file name and line at which the macro was called to the given message.

Parameters
msgMessage to add file/line info to.

Definition at line 59 of file pic24_unittest.h.

◆ TOSTRING

#define TOSTRING (   x)    _TOSTRING(x)

Macro to convert a number to a string. Typical usage: TOSTRING(LINE)

Definition at line 50 of file pic24_unittest.h.

Function Documentation

◆ picAssert()

static void picAssert ( uint8_t  test,
const char *  message 
)
inlinestatic

A function to reset the chip and report a message if the test is false. Assumes reportError is called at start-up to report any assertion violations.

Parameters
testBoolean results of test run. If false, reset and print message.
messageMessage to print if assertion fails.

Definition at line 105 of file pic24_unittest.h.

◆ reportError()

void reportError ( const char *  sz_errorMessage)

Report a critical error by recording a message in sz_lastError then resetting the chip, assuming hat printResetCause will be called during chip initialization.

Parameters
sz_errorMessageError message to report.
See also
REPORT_ERROR

Definition at line 183 of file pic24_util.c.

Referenced by picAssert().