Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from fjoncourt/c_unit_testing
C unit testing - excellent, thank you Franck. I'll work on the relative path issue you mentioned as well.
- Loading branch information
Showing
21 changed files
with
737 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#ifndef CUNIT_COMMON_H | ||
#define CUNIT_COMMON_H | ||
|
||
typedef struct c_unit_test | ||
{ | ||
char description[128]; | ||
void (*func)(void); | ||
} c_unit_test_t; | ||
|
||
typedef struct c_unit_test_suite | ||
{ | ||
char description[128]; | ||
int (*init_func)(void); | ||
int (*cleanup_func)(void); | ||
c_unit_test_t test_array[12]; | ||
int nb_c_unit_test; | ||
} c_unit_test_suite_t; | ||
|
||
#define UTEST_DESCR(name) ut_descr_##name | ||
#define UTEST_FCT(name) ut_##name | ||
#define TEST_SUITE(name) ts_##name | ||
#define TEST_SUITE_DESCR(name) ts_descr_##name | ||
#define TEST_SUITE_INIT(name) _ts_init_##name | ||
#define TEST_SUITE_CLEANUP(name) _ts_cleanup_##name | ||
|
||
#define DECLARE_TEST_SUITE(name, description) static const char ts_descr_##name[] = description; \ | ||
static c_unit_test_suite_t ts_##name; | ||
#define DECLARE_TEST_SUITE_INIT(name) int _ts_init_##name(void) | ||
#define DECLARE_TEST_SUITE_CLEANUP(name) int _ts_cleanup_##name(void) | ||
#define DECLARE_UTEST(name, description) static const char ut_descr_##name[] = description; \ | ||
static void ut_##name(void) | ||
|
||
void ts_init(c_unit_test_suite_t* ts, const char* description, int (*init)(void), int (*cleanup)(void)); | ||
void ts_add_utest(c_unit_test_suite_t* ts, void (*utest_func)(void), const char* utest_description); | ||
int register_ts(c_unit_test_suite_t *ts); | ||
|
||
#endif // CUNIT_COMMON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifdef HAVE_C_UNIT_TESTS | ||
|
||
#include "cunit_common.h" | ||
#include "stdlib.h" | ||
#include "stdio.h" | ||
#include "CUnit/Basic.h" | ||
|
||
void ts_init(c_unit_test_suite_t* ts, const char* description, int (*init)(void), int (*cleanup)(void)) | ||
{ | ||
memset(ts, 0x00, sizeof(c_unit_test_suite_t)); | ||
strcpy(ts->description, description); | ||
ts->init_func = init; | ||
ts->cleanup_func = cleanup; | ||
} | ||
|
||
void ts_add_utest(c_unit_test_suite_t* ts, void (*utest_func)(void), const char* utest_description) | ||
{ | ||
c_unit_test_t* utest = &(ts->test_array[ts->nb_c_unit_test]); | ||
|
||
utest->func = utest_func; | ||
strcpy(utest->description, utest_description); | ||
|
||
(ts->nb_c_unit_test)++; | ||
} | ||
|
||
int register_ts(c_unit_test_suite_t *ts) | ||
{ | ||
CU_pSuite pSuite = NULL; | ||
int ix_utest; | ||
|
||
pSuite = CU_add_suite(ts->description, ts->init_func, ts->cleanup_func); | ||
if (NULL == pSuite) { | ||
CU_cleanup_registry(); | ||
return CU_get_error(); | ||
} | ||
|
||
/* add the tests to the suite */ | ||
for (ix_utest=0 ; ix_utest<ts->nb_c_unit_test ; ix_utest++) | ||
{ | ||
c_unit_test_t* utest = &(ts->test_array[ix_utest]); | ||
if (NULL == CU_add_test(pSuite, utest->description, utest->func)) | ||
{ | ||
CU_cleanup_registry(); | ||
return CU_get_error(); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#endif /* HAVE_C_UNIT_TESTS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.