Simple XUnit test library / objects in plain C Snapshot
vtestrunner.h
Go to the documentation of this file.
00001 /* Copyright (c) Michael Moser (2011) . 3-clause BSD License applies */
00002 
00003 #ifndef _VTESTRUNNER_H_
00004 #define _VTESTRUNNER_H_
00005 
00006 #ifdef  __cplusplus
00007 extern "C" {
00008 #endif
00009 
00010 #include <sys/time.h>
00011 
00012 typedef enum {
00013   VTEST_TEST_FAILED = 0,
00014   VTEST_TEST_OK,
00015 
00016   VTEST_SUITE_SETUP_FAILED,
00017   VTEST_SUITE_SETUP_OK,
00018 
00019   VTEST_SUITE_TEARDOWN_FAILED,
00020   VTEST_SUITE_TEARDOWN_OK,
00021   
00022 }
00023   VTEST_STATUS;
00024 
00025 typedef void (*VTEST_RUNNER_report_suite_start) (const char *suite_name);
00026 
00027 typedef void (*VTEST_RUNNER_report_test_start)  (const char *suite_name, const char *test_name, 
00028                                                                                                  int iteration, int maxiteration);
00029 
00030 typedef void (*VTEST_RUNNER_report_results)        (VTEST_STATUS status, 
00031                                                         const char *suite_name, const char *test_name, 
00032                                                         struct timeval *duration,
00033                                                         const char *fail_cond, const char *fail_file,int fail_line);
00034 
00035 typedef void (*VTEST_RUNNER_report_wrapup)         (int suitesinitfailed, 
00036                                                                                                 int suitesteardownfailed, 
00037                                                                                                 int tests_passed, 
00038                                                                                                 int tests_failed, 
00039                                                                                                 int testnotrun);
00040 
00041 
00042 typedef struct tagVTEST_RUNNER_IMPL {
00043         
00044         VTEST_RUNNER_report_suite_start suite_start;
00045         VTEST_RUNNER_report_test_start  test_start;
00046         VTEST_RUNNER_report_results     results;
00047         VTEST_RUNNER_report_wrapup      wrapup;
00048 
00049         int                               current_test_state;
00050         VTEST_STATUS      scope_fail;
00051         VTEST_TEST_SUITE *suite;
00052         VTEST_TEST               *test;
00053 
00054 } VTEST_RUNNER_IMPL;
00055 
00056 /**
00057   @brief run all test suites.
00058   @param suite (in) the first test suite out of a chain of test suites.
00059   @param impl (in) class that implements a test runner.
00060  */
00061 
00062 int VTEST_test_runner(VTEST_TEST_SUITE *suite, VTEST_RUNNER_IMPL *impl);
00063 
00064 /**
00065   @brief run selected list of suites and tests; selection is specified via command line
00066 
00067   @brief run all test suites.
00068   @param suite (in) the first test suite out of a chain of test suites.
00069   @param impl (in) class that implements a test runner.
00070   @param argc (in) number of strings in command line
00071   @param argv (in) command line strings.
00072 
00073   command line specified by arguments argv and argc.
00074                 
00075                 <cmd_line>   ::= <cmd_line> SPACE <build_spec>  | <build_spec>
00076                 
00077                 <build_spec> ::= SUITENAME | SUITENAME/<test_list>
00078 
00079                 <test_list>  ::= <test_list>,TESTNAME | TESTNAME
00080 
00081                 SUITENAME        name of a test suite
00082                 TESTNAME         name of a test suite.
00083 
00084   If a SUITENAME or TESTNAME does not exist, then it does not match and is not run; (no error are reported for these conditions).
00085 
00086   Explanation:
00087                 Empty command line means - run all tests.
00088                 
00089                 Test suites are always run in the order of their declaration.
00090 
00091                 Can select execution of individual suite, and suites with selected set of list.
00092 
00093  */     
00094 int VTEST_test_runner_cmdline(VTEST_TEST_SUITE *suite, VTEST_RUNNER_IMPL *impl, int argc, char *argv[]);
00095 
00096 
00097 /* 
00098         A unit test can call this function in order to set the next test suite to execute.
00099         Good for implementation of test loops.
00100         
00101         Scenario: run a series of test, the last test changes global environment and goes to first test suite;
00102                       Test series is now run with modified global environment.
00103  */
00104 void VTEST_goto_next_suite(const char *suite_name);
00105 
00106 #ifdef  __cplusplus
00107 }
00108 #endif
00109 
00110 #endif
00111