diff options
Diffstat (limited to 'Source/charon/utils')
-rw-r--r-- | Source/charon/utils/tester.c | 24 | ||||
-rw-r--r-- | Source/charon/utils/tester.h | 59 |
2 files changed, 51 insertions, 32 deletions
diff --git a/Source/charon/utils/tester.c b/Source/charon/utils/tester.c index 76a0bc7e6..20dea2e82 100644 --- a/Source/charon/utils/tester.c +++ b/Source/charon/utils/tester.c @@ -42,9 +42,9 @@ typedef struct private_tester_t private_tester_t; struct private_tester_t { /** - * Public interface of tester_t. + * Protected interface of tester_t. */ - tester_t public; + protected_tester_t protected; /** * Runs a specific test. @@ -53,7 +53,7 @@ struct private_tester_t { * @param test_function test function to perform * @param test_name name for the given test */ - void (*run_test) (private_tester_t *tester, void (*test_function) (tester_t * tester), char * test_name); + void (*run_test) (private_tester_t *tester, void (*test_function) (protected_tester_t * tester), char * test_name); /** * Returns the difference of to timeval structs in microseconds. @@ -159,7 +159,7 @@ static long time_difference(private_tester_t *this,struct timeval *end_time, str /** * Implementation of private_tester_t.run_test. */ -static void run_test(private_tester_t *this, void (*test_function) (tester_t * tester), char * test_name) +static void run_test(private_tester_t *this, void (*test_function) (protected_tester_t * tester), char * test_name) { struct timeval start_time, end_time; long timediff; @@ -167,7 +167,7 @@ static void run_test(private_tester_t *this, void (*test_function) (tester_t * t this->failed_asserts_count = 0; fprintf(this->output,"%-55s\n", test_name); gettimeofday(&start_time,NULL); - test_function(&(this->public)); + test_function(&(this->protected)); gettimeofday(&end_time,NULL); timediff = this->time_difference(this,&end_time, &start_time); @@ -215,7 +215,7 @@ static void assert_true(private_tester_t *this, bool to_be_true,char * assert_na */ static void assert_false(private_tester_t *this, bool to_be_false,char * assert_name) { - this->public.assert_true(&(this->public),(!to_be_false),assert_name); + this->protected.assert_true(&(this->protected),(!to_be_false),assert_name); } /** @@ -236,11 +236,11 @@ tester_t *tester_create(FILE *output, bool display_succeeded_asserts) private_tester_t *this = allocator_alloc_thing(private_tester_t); /* public functions */ - this->public.destroy = (void (*) (tester_t *))destroy; - this->public.perform_tests = (void (*) (tester_t *, test_t**)) perform_tests; - this->public.perform_test = (void (*) (tester_t *, test_t*))perform_test; - this->public.assert_true = (void (*) (tester_t *, bool, char*)) assert_true; - this->public.assert_false = (void (*) (tester_t *, bool, char*)) assert_false; + this->protected.public.destroy = (void (*) (tester_t *))destroy; + this->protected.public.perform_tests = (void (*) (tester_t *, test_t**)) perform_tests; + this->protected.public.perform_test = (void (*) (tester_t *, test_t*))perform_test; + this->protected.assert_true = (void (*) (protected_tester_t *, bool, char*)) assert_true; + this->protected.assert_false = (void (*) (protected_tester_t *, bool, char*)) assert_false; /* private functions */ this->run_test = run_test; @@ -253,5 +253,5 @@ tester_t *tester_create(FILE *output, bool display_succeeded_asserts) this->output = output; pthread_mutex_init(&(this->mutex),NULL); - return &(this->public); + return &(this->protected.public); } diff --git a/Source/charon/utils/tester.h b/Source/charon/utils/tester.h index 3da6f9fb7..3decb2039 100644 --- a/Source/charon/utils/tester.h +++ b/Source/charon/utils/tester.h @@ -28,10 +28,10 @@ #include <types.h> -typedef struct test_t test_t; - /* must be defined here cause it is used in test_t */ -typedef struct tester_t tester_t; +typedef struct protected_tester_t protected_tester_t; + +typedef struct test_t test_t; /** * @brief Representing a specified test. @@ -44,7 +44,7 @@ struct test_t { * * @param tester associated tester_t object */ - void (*test_function) (tester_t * tester); + void (*test_function) (protected_tester_t * tester); /** * Name of the test. @@ -52,6 +52,9 @@ struct test_t { char * test_name; }; + +typedef struct tester_t tester_t; + /** * @brief A class to perform tests. * @@ -61,7 +64,6 @@ struct test_t { * @ingroup utils */ struct tester_t { - /** * @brief Test all testcases in array tests with specific tester_t object. * @@ -80,39 +82,56 @@ struct tester_t { void (*perform_test) (tester_t *tester, test_t *test); /** - * Is called in a testcase to check a specific situation for TRUE. + * @brief Destroys a tester_t object. * - * Log-Values to the tester output are protected from multiple access. + * @param tester tester_t object + */ + void (*destroy) (tester_t *tester); +}; + + +/** + * @brief A class used in a specific testcase. + * + * For each testcase an object of this type is passed to the testfunction. The testfunction uses this + * object to check specific asserts with protected_tester_t.assert_true and protected_tester_t.assert_false. + * + * @b Constructors: + * - tester_create() + * + * @ingroup utils + */ +struct protected_tester_t { + + /** + * Public functions of a tester_t object + */ + tester_t public; + + /** + * @brief Is called in a testcase to check a specific situation for TRUE. * - * @warning This function should only be called in a test_function. + * Log-Values to the tester output are protected from multiple access. * * @param this tester_t object * @param to_be_true assert which has to be TRUE * @param assert_name name of the assertion */ - void (*assert_true) (tester_t *tester, bool to_be_true, char *assert_name); + void (*assert_true) (protected_tester_t *tester, bool to_be_true, char *assert_name); /** - * Is called in a testcase to check a specific situation for FALSE. + * @brief Is called in a testcase to check a specific situation for FALSE. * * Log-Values to the tester output are protected from multiple access. * - * @warning This function should only be called in a test_function. - * * @param this tester_t object * @param to_be_false assert which has to be FALSE * @param assert_name name of the assertion */ - void (*assert_false) (tester_t *tester, bool to_be_false, char *assert_name); - - /** - * @brief Destroys a tester_t object. - * - * @param tester tester_t object - */ - void (*destroy) (tester_t *tester); + void (*assert_false) (protected_tester_t *tester, bool to_be_false, char *assert_name); }; + /** * @brief Creates a tester_t object used to perform tests with. * |