Simple XUnit test library / objects in plain C Snapshot
Classes | Defines | Typedefs | Functions
vtest.h File Reference

Go to the source code of this file.

Classes

struct  tagVTEST_TEST
struct  tagVTEST_TEST_SUITE

Defines

#define VTEST_DEFINE_LAST_SUITE(name, setUp, tearDown)
#define VTEST_DEFINE_SUITE(name, setUp, tearDown, nextsuite)
#define VTEST_END_SUITE
#define VTEST_TEST_REPEATED(tname, test_fun, repeat_count)   { (tname), (VTEST_ACTION) (test_fun), (int) (repeat_count) },
#define VTEST_TEST(tname, test_fun)   { (tname), (VTEST_ACTION) (test_fun), 1 },
#define VTEST_TESTN(test_fun)   { #test_fun, (VTEST_ACTION) (test_fun), 1 },
#define VCHECK(cond)   { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); } while(0);
#define VASSERT(cond)   { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); return; } } while(0);
#define VASSERT_RET(cond, ret)   { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); return (ret); } } while(0);
#define VTEST_SUITE_DECLARE_GET(name)   extern VTEST_TEST_SUITE *get_vtest_##name ();
#define VTEST_SUITE_GET(name)   (VTEST_TEST_SUITE *)get_vtest_##name ()

Typedefs

typedef void(* VTEST_ACTION )(void)
typedef struct tagVTEST_TEST VTEST_TEST
typedef struct tagVTEST_TEST_SUITE VTEST_TEST_SUITE

Functions

void VFAIL (const char *cond, const char *file, int line)

Define Documentation

#define VASSERT (   cond)    { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); return; } } while(0);

Assert the condition, failure of condtion will signal test failure,and return from function (this assumes that curernt function is void).

Examples:
example.c.

Definition at line 129 of file vtest.h.

#define VASSERT_RET (   cond,
  ret 
)    { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); return (ret); } } while(0);

Assert the condition, failure of condtion will signal test failure, and return with will be called (this assumes that curernt function is void).

Definition at line 136 of file vtest.h.

#define VCHECK (   cond)    { if (!(cond)) { VFAIL( #cond, __FILE__,__LINE__); } while(0);

Check the condition, failure of condtion will signal test failure, but test execution will continue.

Definition at line 123 of file vtest.h.

#define VTEST_DEFINE_LAST_SUITE (   name,
  setUp,
  tearDown 
)
Value:
extern VTEST_TEST_SUITE *get_vtest_##name () \
{ \
  VTEST_ACTION argSetUp = (VTEST_ACTION) (setUp), argTearDown = (VTEST_ACTION) (tearDown);\
  \
  VTEST_TEST_SUITE *next_suite = 0;\
  \
  const char *suitename = #name;\
  \
  static VTEST_TEST_SUITE test; \
  \
  static VTEST_TEST test_cases[] = { \

Start declaration of a test suite that is the last one out of a chain of tests.

Parameters:
namename of test (not string)
setUpfunction is called before start of suite
tearDownfunction is called after completion of suite
Examples:
example.c.

Definition at line 37 of file vtest.h.

#define VTEST_DEFINE_SUITE (   name,
  setUp,
  tearDown,
  nextsuite 
)
Value:
\
extern VTEST_TEST_SUITE *get_vtest_##nextsuite (); \
\
extern VTEST_TEST_SUITE *get_vtest_##name () \
{ \
  VTEST_ACTION argSetUp = (VTEST_ACTION) (setUp), argTearDown = (VTEST_ACTION) (tearDown);\
  \
  VTEST_TEST_SUITE *next_suite = get_vtest_##nextsuite ();\
  \
  const char *suitename = #name ;\
  \
  static VTEST_TEST_SUITE test; \
  \
  static VTEST_TEST test_cases[] = { \

Start declaration of a test suite

Parameters:
namename of test (not string)
setUpfunction is called before start of suite
tearDownfunction is called after completion of suite
nextsuitethe next test suite to follow after this one (not string)
Examples:
example.c.

Definition at line 58 of file vtest.h.

#define VTEST_END_SUITE
Value:
{ 0, 0, 0 } \
};\
  test.test_cases = (VTEST_TEST *) test_cases;\
  test.next_suite = next_suite;\
  test.setUp = argSetUp;\
  test.tearDown = argTearDown;\
  test.name = suitename;\
  \
  return &test;\
}

declarations ends definition of a test suite

Examples:
example.c.

Definition at line 78 of file vtest.h.

#define VTEST_SUITE_DECLARE_GET (   name)    extern VTEST_TEST_SUITE *get_vtest_##name ();

calls function that creates forward declaration for the test suite structure accessor.

Definition at line 142 of file vtest.h.

#define VTEST_SUITE_GET (   name)    (VTEST_TEST_SUITE *)get_vtest_##name ()

calls function that returns the test suite structure for a given test.

Examples:
example.c.

Definition at line 149 of file vtest.h.

#define VTEST_TEST (   tname,
  test_fun 
)    { (tname), (VTEST_ACTION) (test_fun), 1 },

define a new test

Parameters:
tnametest name
test_funtest function of type VTEST_ACTION

Definition at line 104 of file vtest.h.

#define VTEST_TEST_REPEATED (   tname,
  test_fun,
  repeat_count 
)    { (tname), (VTEST_ACTION) (test_fun), (int) (repeat_count) },

define a test that is repeated for a number of times

Parameters:
tnametest name
test_funtest function of type VTEST_ACTION
repeat_countnumber of times that test is repeated
Examples:
example.c.

Definition at line 96 of file vtest.h.

#define VTEST_TESTN (   test_fun)    { #test_fun, (VTEST_ACTION) (test_fun), 1 },

define a new test

Parameters:
test_fun- the function is also the name of the test

Definition at line 112 of file vtest.h.


Typedef Documentation

typedef void(* VTEST_ACTION)(void)

Definition at line 10 of file vtest.h.

typedef struct tagVTEST_TEST VTEST_TEST

Function Documentation

void VFAIL ( const char *  cond,
const char *  file,
int  line 
)

call to this function will signal test failure.

Definition at line 58 of file vtest.c.

{
        vtest_impl->results( vtest_impl->scope_fail, 
                                                 vtest_impl->suite->name, 
                                                 vtest_impl->test ? vtest_impl->test->name : 0,
                                                 0, 
                                                 cond, file, line);

        vtest_impl->current_test_state = 0;

#ifdef WIN32
        if (DynIsDebuggerPresent()) {
                DebugBreak();   
        }
#endif

}