Apache2
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
httpdunit.h File Reference
#include "apr.h"
#include "check.h"
Include dependency graph for httpdunit.h:

Go to the source code of this file.

Macros

#define HTTPD_BEGIN_TEST_CASE(NAME)
 
#define HTTPD_BEGIN_TEST_CASE_WITH_FIXTURE(NAME, SETUP, TEARDOWN)
 
#define HTTPD_END_TEST_CASE
 
#define HTTPD_START_LOOP_TEST(NAME, NUM_ITERATIONS)   START_TEST(NAME)
 

Macro Definition Documentation

#define HTTPD_BEGIN_TEST_CASE (   NAME)
Value:
TCase * NAME##_test_case(void); \
TCase * NAME##_test_case(void) \
{ \
TCase *testcase = tcase_create(#NAME);

Declares a test case. The build system uses this macro to generate a stub, which will automatically pull the new test case into the main suite.

After beginning a test case, you must #include the autogenerated testcase stub ("test/unit/<filename>.tests") and then end the test case with HTTPD_END_TEST_CASE. For example, for a test case called foobar.c:

HTTPD_BEGIN_TEST_CASE(foobar) #include "test/unit/foobar.tests" HTTPD_END_TEST_CASE

The NAME identifying the test case must be globally unique within the test suite; if in doubt, just use the filename (minus extension).

#define HTTPD_BEGIN_TEST_CASE_WITH_FIXTURE (   NAME,
  SETUP,
  TEARDOWN 
)
Value:
tcase_add_checked_fixture(testcase, (SETUP), (TEARDOWN));
#define HTTPD_BEGIN_TEST_CASE(NAME)
Definition: httpdunit.h:77

Like HTTPD_BEGIN_TEST_CASE, but additionally declares a pair of setup and teardown functions for the test case. The setup function is run once before every test function, and the teardown function is run directly after. Keep in mind that expensive fixtures will heavily impact test runtime.

Both setup and teardown take no parameters and return void.

These functions are passed to Check's tcase_add_checked_fixture(). See the Check documentation for details; the gist is that checked fixures run after Check forks the test process, and therefore they cannot influence each other even if something smashes the heap.

#define HTTPD_END_TEST_CASE
Value:
return testcase; \
}

Bookend for HTTPD_BEGIN_TEST_CASE[_WITH_FIXTURE], which finishes the test case function.

#define HTTPD_START_LOOP_TEST (   NAME,
  NUM_ITERATIONS 
)    START_TEST(NAME)

Use this macro instead of Check's START_TEST when you want to run a test function multiple times. The build system will add the test function to the test case using Check's tcase_add_loop_test().

The loop index is available to the test function as the special variable _i. _i will start at 0 and increment to a maximum of (NUM_ITERATIONS - 1).