2 * Copyright (C) 2006-2009 Brian Aker
5 * Use and distribution licensed under the BSD license. See
6 * the COPYING file in the parent directory for full text.
10 Structures for generic tests.
22 typedef struct world_st world_st
;
23 typedef struct collection_st collection_st
;
24 typedef struct test_st test_st
;
27 TEST_SUCCESS
= 0, /* Backwards compatibility */
29 TEST_MEMORY_ALLOCATION_FAILURE
,
31 TEST_MAXIMUM_RETURN
/* Always add new error code before */
34 typedef void *(*test_callback_create_fn
)(test_return_t
*error
);
35 typedef test_return_t (*test_callback_fn
)(void *);
36 typedef test_return_t (*test_callback_runner_fn
)(test_callback_fn
, void *);
37 typedef test_return_t (*test_callback_error_fn
)(test_return_t
, void *);
41 A structure describing the test case.
46 test_callback_fn test_fn
;
51 A structure which describes a collection of test cases.
53 struct collection_st
{
56 test_callback_fn post
;
62 Structure which houses the actual callers for the test cases contained in
66 test_callback_runner_fn pre
;
67 test_callback_runner_fn run
;
68 test_callback_runner_fn post
;
73 world_st is the structure which is passed to the test implementation to be filled.
74 This must be implemented in order for the test framework to load the tests. We call
75 get_world() in order to fill this structure.
79 collection_st
*collections
;
81 /* These methods are called outside of any collection call. */
82 test_callback_create_fn create
;
83 test_callback_fn destroy
;
85 /* This is called a the beginning of any test run. */
86 test_callback_fn test_startup
;
88 /* This is called a the beginning of any collection run. */
89 test_callback_fn collection_startup
;
91 /* This is called a the beginning of any collection run. */
92 test_callback_fn collection_shutdown
;
94 /* This called on a test if the test requires a flush call (the bool is from test_st) */
95 test_callback_fn flush
;
98 These are run before/after the test. If implemented. Their execution is not controlled
101 test_callback_fn pre_run
;
102 test_callback_fn post_run
;
105 If an error occurs during the test, this is called.
107 test_callback_error_fn on_error
;
110 Runner represents the callers for the tests. If not implemented we will use
111 a set of default implementations.
113 world_runner_st
*runner
;
119 @note world_stats_st is a simple structure for tracking test successes.
122 uint32_t collection_success
;
123 uint32_t collection_skipped
;
124 uint32_t collection_failed
;
125 uint32_t collection_total
;
132 /* How we make all of this work :) */
133 void get_world(world_st
*world
);
135 void create_core(void);
138 @note Friendly print function for errors.
140 const char *test_strerror(test_return_t code
);
142 #define test_truth(A) \
146 fprintf(stderr, "\nAssertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\
148 return TEST_FAILURE; \
152 #define test_false(A) \
156 fprintf(stderr, "\nAssertion failed in %s:%d: %s\n", __FILE__, __LINE__, #A);\
158 return TEST_FAILURE; \
162 #define test_strcmp(A,B) \
165 if (strcmp((A), (B))) \
167 fprintf(stderr, "\n%s:%d: %s -> %s\n", __FILE__, __LINE__, (A), (B)); \
169 return TEST_FAILURE; \