PIC24 Support Libraries
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions | Variables
unitTests.c File Reference

Implements unit tests for the PIC comm protocol. More...

#include "dataXfer.h"
#include <string.h>
#include <stdio.h>

Go to the source code of this file.

Functions

void runTest (uint u_index)
 
void runAllTests ()
 Run all the tests by executing everything in the list of tests.
 
Tests for the command-finding state machine
void findChar ()
 Run all normal chars through the machine.
 
void findEscapedCommandChar ()
 Run an escaped command through the machine.
 
void findCommand ()
 Look for all the normal (unescaped) commands.
 
void findEscapedCommand ()
 Run an escaped command through the machine.
 
void findRepeatedWait ()
 
void findRepeatedCommand ()
 

Variables

void(* afp_testList [])()
 

Tests for the receive state machine

#define CMD_TOKEN_STR   "\xAA"
 Used to create strings with commands in them below.
 
#define CMD_SEND_ONLY_STR   "\xFE"
 
#define CMD_SEND_RECEIVE_VAR_STR   "\xFF"
 
void sendData (uint8_t *pu8_data, uint u_len)
 
void sendOneNormalChar (char c_charToSend)
 
void sendLetter ()
 Sending a letter should report that letter received.
 
void send0x00 ()
 Sending the char 0x00 shold report that char receivd.
 
void send0xFF ()
 Sending the char 0xFF shold report that char receivd.
 
void sendEscapedCommand ()
 Check sending an escaped command.
 
void setupXferData (uint u_index, uint u_len)
 
void sendOneByteData ()
 
void sendFourBytesData ()
 Check sending a four-byte piece of data.
 
void sendFourBytesCmdTokenData ()
 
void sendRepeatedCommand ()
 
void sendCommandCmdToken ()
 Send a command of CMD_TOKEN.
 
void sendRepeatedCommandCmdToken ()
 Send a repeated command followed by a command of CMD_TOKEN.
 
void sendWithTimeout ()
 Test timeout detection.
 
void sendInterruptedCommand ()
 Test sending a second command before the first completes.
 
void sendToUnspecifiedIndex ()
 Test sending data to an unspecified index.
 
void sendToHighIndex ()
 
void sendWithWrongSize ()
 Test sending incorrectly-sized data to a variable.
 
void sendLongToUnspecifiedIndex ()
 Test sending long data to an unspecified index.
 
void sendLongToHighIndex ()
 
void sendLongWithWrongSize ()
 Test sending incorrectly-sized data to a long variable.
 
void sendLongData ()
 Test sending 256 bytes of data.
 
void sendVarSpec ()
 Test sending a variable specification.
 
void resendVarSpec ()
 Test sending a variable specification, then sending a different spec.
 
void sendWriteableVarSpec ()
 Test sending a variable specification.
 
void sendEmptyVarSpec ()
 Test sending a variable specification with no strings.
 
void sendFormatOnlyVarSpec ()
 Test sending a variable specification with only a format.
 
void sendNameOnlyVarSpec ()
 Test sending a variable specification with only a format.
 
void sendVarSpecAndData ()
 Test sending a spec followed by actual data.
 

Tests for the specify and send functions

#define REQUIRE_ASSERT(code, expectedMsg)   (void) 0
 
static size_t st_outCharLen = 0
 The length of an array of characters used to check OUT_CHAR's usage.
 
static size_t st_outCharIndex = 0
 An index into the array of check characters.
 
static uint8_tau8_outCharData = NULL
 A pointer to an array containing the expected characters to be output.
 
void clearOutChar ()
 Reset all the OUT_CHAR associated data (the variables above).
 
void testOutChar (uint8_t c)
 
void testSendIndexTooHigh ()
 Send to a index that's too high.
 
void testSendIndexUnspecificed ()
 Send to an unconfigured index.
 
void testSendToReadOnly ()
 Send to a read-only variable (PC only)
 
void checkSendVar (uint8_t u8_index, uint u_len, uint8_t *au8_data)
 A macro to send a variable and check the resulting output.
 
void testSendOneByteVar ()
 Send a one-byte variable.
 
void testSendOneEscapedByteVar ()
 Send a one-byte variable that needs to be escaped.
 
void testSendFourByteVar ()
 Send a four-byte variable.
 
void testSend256ByteVar ()
 Send a 256-byte variable.
 
void testSpecifyIndexTooHigh ()
 Specify an index that's too high.
 
void testSpecifyNullData ()
 Specify with NULL data.
 
void testSpecifyInvalidSize ()
 Specify with an invalid size.
 
void testSpecifyMinimalVar ()
 Minimally specify a variable.
 
void testSpecifyLongFormat ()
 
void testSpecifyLongName ()
 
void testSpecifyLongDesc ()
 
void testFormatIndexTooHigh ()
 Send to a index that's too high.
 
void testFormatIndexUnspecificed ()
 Send to an unconfigured index.
 

Detailed Description

Implements unit tests for the PIC comm protocol.

A very simple test runner, runAllTests(), executes the tests. ASSERT statements provide verification.

Definition in file unitTests.c.

Macro Definition Documentation

#define REQUIRE_ASSERT (   code,
  expectedMsg 
)    (void) 0

Test support: ASSERT if an exception isn't thrown.

Parameters
codeCode which when executed should cause a specific ASSERT.
expectedMsgString the ASSERT should throw. This macro expects to test ASSERT statements of the form ASSERT("a string" && someCondition). The "a string" portion is always true, but also provides a hackish way to name an assert. To make testing easier, only the text inside the quotes is tested: the expectedString in this case is "a string".

Definition at line 614 of file unitTests.c.

Referenced by testFormatIndexTooHigh(), testFormatIndexUnspecificed(), testSendIndexTooHigh(), testSendIndexUnspecificed(), testSendToReadOnly(), testSpecifyIndexTooHigh(), testSpecifyInvalidSize(), and testSpecifyNullData().

Function Documentation

void findRepeatedCommand ( )
Todo:
Cases still to unit test:
  • (repeated wait)
  • CMD_TOKEN CMD_TOKEN c (repeated command)

Definition at line 91 of file unitTests.c.

void findRepeatedWait ( )

Verify that the sequence CMD_TOKEN CMD_TOKEN CMD_TOKEN is recognized as a repeated wait.

Definition at line 77 of file unitTests.c.

void runTest ( uint  u_index)

Execute one test. This resets the state machines before a run to create a clean slate for every test.

Parameters
u_indexIndex of test to run. NO BOUNDS CHECKING is performed on this index. Be careful.

Definition at line 916 of file unitTests.c.

Referenced by runAllTests().

void sendData ( uint8_t pu8_data,
uint  u_len 
)
void sendFourBytesCmdTokenData ( )

Check sending a four-byte piece of data which contains four CMD_TOKEN bytes. 0x00 == 000000 11 : index 0, length 3 (4 bytes)

Definition at line 202 of file unitTests.c.

void sendLongToHighIndex ( )

Test sending long data to an index beyond the end of the variable storage area

Definition at line 373 of file unitTests.c.

void sendOneByteData ( )

Check sending a one-byte piece of data 0x00 == 000000 00 : index 0, length 0 (1 byte)

Definition at line 172 of file unitTests.c.

void sendOneNormalChar ( char  c_charToSend)

Sending a normal char shold report that char receivd

Parameters
c_charToSendThe character to send. This character will NOT be esacaped – an 0x55 will be sent as just an 0x55.

Definition at line 118 of file unitTests.c.

Referenced by send0x00(), send0xFF(), and sendLetter().

void sendRepeatedCommand ( )

Send a repeated command and make sure both an error is reported and data can be received (error recovery works).

Definition at line 220 of file unitTests.c.

void sendToHighIndex ( )

Test sending data to an index beyond the end of the variable storage area

Definition at line 339 of file unitTests.c.

void setupXferData ( uint  u_index,
uint  u_len 
)
void testOutChar ( uint8_t  c)

An outChar function which simply checks to see that the output character matches the expected string.

Definition at line 586 of file unitTests.c.

void testSpecifyLongDesc ( )

Test specifying a var with a description string which exceeds the max length. Also check a send-only variable.

Definition at line 810 of file unitTests.c.

void testSpecifyLongFormat ( )

Test specifying a var with a format string which exceeds the max length. Also check a send-only variable.

Definition at line 748 of file unitTests.c.

void testSpecifyLongName ( )

Test specifying a var with a name string which exceeds the max length. Also check a send-only variable.

Definition at line 779 of file unitTests.c.

Variable Documentation

void(* afp_testList[])()

A list of functions which comprise tests to be run, terminated with a NULL.

Definition at line 854 of file unitTests.c.

Referenced by runAllTests(), and runTest().