Simple XUnit test library / objects in plain C Snapshot
Classes | Typedefs | Enumerations | Functions
vtestrunner.h File Reference
#include <sys/time.h>

Go to the source code of this file.

Classes

struct  tagVTEST_RUNNER_IMPL

Typedefs

typedef void(* VTEST_RUNNER_report_suite_start )(const char *suite_name)
typedef void(* VTEST_RUNNER_report_test_start )(const char *suite_name, const char *test_name, int iteration, int maxiteration)
typedef void(* VTEST_RUNNER_report_results )(VTEST_STATUS status, const char *suite_name, const char *test_name, struct timeval *duration, const char *fail_cond, const char *fail_file, int fail_line)
typedef void(* VTEST_RUNNER_report_wrapup )(int suitesinitfailed, int suitesteardownfailed, int tests_passed, int tests_failed, int testnotrun)
typedef struct tagVTEST_RUNNER_IMPL VTEST_RUNNER_IMPL

Enumerations

enum  VTEST_STATUS {
  VTEST_TEST_FAILED = 0, VTEST_TEST_OK, VTEST_SUITE_SETUP_FAILED, VTEST_SUITE_SETUP_OK,
  VTEST_SUITE_TEARDOWN_FAILED, VTEST_SUITE_TEARDOWN_OK
}

Functions

int VTEST_test_runner (VTEST_TEST_SUITE *suite, VTEST_RUNNER_IMPL *impl)
 run all test suites.
int VTEST_test_runner_cmdline (VTEST_TEST_SUITE *suite, VTEST_RUNNER_IMPL *impl, int argc, char *argv[])
 run selected list of suites and tests; selection is specified via command line
void VTEST_goto_next_suite (const char *suite_name)

Typedef Documentation

typedef void(* VTEST_RUNNER_report_results)(VTEST_STATUS status, const char *suite_name, const char *test_name, struct timeval *duration, const char *fail_cond, const char *fail_file, int fail_line)

Definition at line 30 of file vtestrunner.h.

typedef void(* VTEST_RUNNER_report_suite_start)(const char *suite_name)

Definition at line 25 of file vtestrunner.h.

typedef void(* VTEST_RUNNER_report_test_start)(const char *suite_name, const char *test_name, int iteration, int maxiteration)

Definition at line 27 of file vtestrunner.h.

typedef void(* VTEST_RUNNER_report_wrapup)(int suitesinitfailed, int suitesteardownfailed, int tests_passed, int tests_failed, int testnotrun)

Definition at line 35 of file vtestrunner.h.


Enumeration Type Documentation

Enumerator:
VTEST_TEST_FAILED 
VTEST_TEST_OK 
VTEST_SUITE_SETUP_FAILED 
VTEST_SUITE_SETUP_OK 
VTEST_SUITE_TEARDOWN_FAILED 
VTEST_SUITE_TEARDOWN_OK 

Definition at line 12 of file vtestrunner.h.


Function Documentation

void VTEST_goto_next_suite ( const char *  suite_name)

Definition at line 199 of file vtest.c.

{
        if (suite_name) {
                g_suite_name = strdup(suite_name);
        }
}
int VTEST_test_runner ( VTEST_TEST_SUITE suite,
VTEST_RUNNER_IMPL impl 
)

run all test suites.

Parameters:
suite(in) the first test suite out of a chain of test suites.
impl(in) class that implements a test runner.

Definition at line 408 of file vtest.c.

{
        return VTEST_test_runner_cmdline(suite, impl,0,0);
}
int VTEST_test_runner_cmdline ( VTEST_TEST_SUITE suite,
VTEST_RUNNER_IMPL impl,
int  argc,
char *  argv[] 
)

run selected list of suites and tests; selection is specified via command line

run all test suites.

Parameters:
suite(in) the first test suite out of a chain of test suites.
impl(in) class that implements a test runner.
argc(in) number of strings in command line
argv(in) command line strings.

command line specified by arguments argv and argc.

<cmd_line> ::= <cmd_line> SPACE <build_spec> | <build_spec>

<build_spec> ::= SUITENAME | SUITENAME/<test_list>

<test_list> ::= <test_list>,TESTNAME | TESTNAME

SUITENAME name of a test suite TESTNAME name of a test suite.

If a SUITENAME or TESTNAME does not exist, then it does not match and is not run; (no error are reported for these conditions).

Explanation: Empty command line means - run all tests.

Test suites are always run in the order of their declaration.

Can select execution of individual suite, and suites with selected set of list.

Definition at line 242 of file vtest.c.

{
        int testsfailed = 0;
        int testspassed = 0;
        int testnotrun  = 0;
        int suitesinitfailed = 0;
        int suitesteardownfailed = 0;
        VTEST_TEST_SUITE *first_suite = suite;
#ifdef TIME_TEST_GETTIMEOFDAY
        struct timeval start, end, duration;
#endif



        int i,suite_ok;

        vtest_impl = impl;

        for(;suite; suite = suite->next_suite) {
                VTEST_TEST *test;

                if (g_suite_name) {
                        VTEST_TEST_SUITE *next;

                        next = find_suite_by_name(first_suite, g_suite_name);
                        free(g_suite_name);
                        g_suite_name = 0;
                        
                        if (next) {
                                suite = next;
                        }                       
                }

                vtest_impl->suite = suite;
                vtest_impl->test = 0;


                if (!VTEST_is_run_suite(suite->name, argv, argc)) {
                        continue;
                }

                if (impl->suite_start) {
                  impl->suite_start(suite->name);
                }

                suite_ok = 1;

#if 0
                if (suite->setUp) {
                        
                        vtest_impl->current_test_state = 1; 
                        vtest_impl->scope_fail = VTEST_SUITE_SETUP_FAILED;

                        suite->setUp();

                        if (!vtest_impl->current_test_state) {
                                suite_ok = 0;   
                        }
                }
#endif
                if (suite_ok)  {

                        vtest_impl->results( VTEST_SUITE_SETUP_OK, suite->name, 0, 0, 0, 0, 0);
                
                        for(test = suite->test_cases; test->name != 0; test++) {

                           if (!VTEST_is_run_test(suite->name, test->name, argv, argc)) {
                                continue;
                           }


                           vtest_impl->test = test;


                                
                           for(i = 0; i < test->repeat /*&& !g_suite_name*/ ; i++) {

                                   impl->test_start( suite->name, test->name, i+1, test->repeat);

                                   vtest_impl->current_test_state = 1; 


#ifdef TIME_TEST_GETTIMEOFDAY
                                   gettimeofday( &start, 0 );
#endif
                                   
                                   if (suite->setUp) {
                                        vtest_impl->scope_fail = VTEST_SUITE_SETUP_FAILED;
                                        suite->setUp();
                                   
                                   }

                                   if (vtest_impl->current_test_state) {
                                     vtest_impl->scope_fail = VTEST_TEST_FAILED;
                                     test->function();
                                   }


                                   if (vtest_impl->current_test_state && suite->tearDown) {
                                        vtest_impl->scope_fail = VTEST_SUITE_TEARDOWN_FAILED;
                                        suite->tearDown();
                                   }


                                   if (vtest_impl->current_test_state) {
#ifdef TIME_TEST_GETTIMEOFDAY
                                          gettimeofday( &end, 0 );
                                          timersub_timeval( &end, &start, &duration );

                                          vtest_impl->results( VTEST_TEST_OK, 
                                                                        vtest_impl->suite->name, 
                                                                        vtest_impl->test->name, 
                                                                        &duration,
                                                                        0, 0, 0);
#else
                                          vtest_impl->results( VTEST_TEST_OK,
                                                                        vtest_impl->suite->name, 
                                                                        vtest_impl->test->name, 
                                                                        0,
                                                                        0, 0, 0);
#endif                             
                                   }
                                   if (vtest_impl->current_test_state) {
                                           testspassed++;
                                   } else {
                                           testsfailed++;
                                   }
                           } // eof test
                           
                        } // eof suite

#if 0
                        if (suite->tearDown) {

                                vtest_impl->current_test_state = 1; 
                                vtest_impl->scope_fail = VTEST_SUITE_TEARDOWN_FAILED;
                                vtest_impl->test = 0;

                                suite->tearDown();

                        
                                if (vtest_impl->current_test_state) {
                                        vtest_impl->results( VTEST_SUITE_TEARDOWN_OK, suite->name, 0, 0, 0, 0);
                                        
                                } else {
                                        suitesteardownfailed++;
                                }
                        }
#endif
                } else {
                        /*test setup failed*/
                        for(test = suite->test_cases;test->name != 0;test++) {
                                testnotrun ++;
                        }
                        suitesinitfailed ++;
                }
                
        }

        vtest_impl->wrapup( suitesinitfailed, suitesteardownfailed,
                                            testspassed, testsfailed, testnotrun);

        return suitesinitfailed == 0 && suitesteardownfailed == 0 && testspassed == 0 && testsfailed == 0;
}