Simple XUnit test library / objects in plain C Snapshot
example.c
Go to the documentation of this file.
00001 /* Copyright (c) Michael Moser (2011) . 3-clause BSD License applies */
00002 
00003 #include "vtest.h"
00004 #include "vtestcui.h"
00005 
00006 void always_fails()
00007 { 
00008         VASSERT( 1 == 0 );
00009 }
00010 
00011 void always_pass()
00012 {
00013 }
00014 
00015 void setUpFails()
00016 {
00017         VASSERT(0);
00018 }
00019 
00020 /* define a test suite named FIRSTTEST*/
00021 VTEST_DEFINE_SUITE( FIRSTTEST, 0, 0, SECONDTEST)
00022         VTEST_TEST( "alwayspass", always_pass)
00023         VTEST_TEST( "failtest", always_fails)
00024         VTEST_TEST( "anothertest", always_pass)
00025 VTEST_END_SUITE
00026 
00027 /* define a test suite named SECONDTEST*/
00028 VTEST_DEFINE_SUITE( SECONDTEST, setUpFails, 0, LASTTEST)
00029         VTEST_TEST( "alwayspass", always_pass)
00030         VTEST_TEST( "failtest", always_fails)
00031         VTEST_TEST( "anothertest", always_pass)
00032 VTEST_END_SUITE
00033 
00034 
00035 /* define a test suite named LASTTEST; note that this is the last suite in the chain of suites*/
00036 VTEST_DEFINE_LAST_SUITE( LASTTEST, 0, 0)
00037         /* repeat execution of the same test three times */
00038         VTEST_TEST_REPEATED( "failtest", always_fails, 3)
00039         VTEST_TEST( "alwayspass", always_pass)
00040 VTEST_END_SUITE
00041 
00042 int main(int argc, char *argv[])
00043 {
00044   VTEST_CUI_test_runner_cmdline( VTEST_SUITE_GET(FIRSTTEST), argc-1, argv+1 );
00045   // normally main would return the return value of the function. don't do this in this case so that this test will not fail.
00046   return 0; 
00047 }