I'm using VectorCAST for unit testing, with Green Hills compiler and Renesas v850e2v3 microcontroller, and VectorCAST indicates that I have two branches to test in the following for loop.
typedef enum
{
MIN_ENUM_VAL = 0x00,
ENUM_VAL_1 = 0x01,
ENUM_VAL_2 = 0x02,
MAX_ENUM_VAL
} Enumeration_T;
void myFunction (void)
{
int counter;
for(counter = MIN_ENUM_VAL; counter < MAX_ENUM_VAL; counter++)
{
//Do something.
}
//Do something else.
}
How can I test these branches? Really I don't have idea on how to test inside the for loop.
If you insert a test case under myFunction() and run it, it should automatically pass through both branches, as the enum values less than MAX_ENUM_VAL satisfy the 'true' branch and MAX_ENUM_VAL satisfies the 'false' branch. VectorCAST understands branches in for loops as conditional branches with respect to the middle sub-statement. It can be seen by inserting the basis path test cases, then reading the notes section of the generated test cases.