Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ root = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 4
indent_style = space
tab_width = 8

[makefile,Makefile]
indent_style = tab
142 changes: 127 additions & 15 deletions src/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,30 @@ Suite *suite_create(const char *name)
return s;
}

const char *suite_name(Suite * s)
{
if(s == NULL)
return NULL;

return s->name;
}

int suite_ntcases(Suite * s)
{
if(s == NULL)
return 0;

return check_list_length(s->tclst);
}

TCase **suite_tcases(Suite * s)
{
if(s == NULL)
return NULL;

return (TCase **)check_list_as_array(s->tclst);
}

int suite_tcase(Suite * s, const char *tcname)
{
List *l;
Expand Down Expand Up @@ -199,6 +223,22 @@ void tcase_set_tags(TCase * tc, const char *tags_orig)
tc->tags = tag_string_to_list(tags_orig);
}

int tcase_ntags(TCase * tc)
{
if(tc == NULL)
return 0;

return check_list_length(tc->tags);
}

const char **tcase_tags(TCase * tc)
{
if(tc == NULL)
return NULL;

return (const char **)check_list_as_array(tc->tags);
}

static void tcase_free(TCase * tc)
{
check_list_apply(tc->tflst, free);
Expand Down Expand Up @@ -250,6 +290,7 @@ void suite_add_tcase(Suite * s, TCase * tc)
check_list_add_end(s->tclst, tc);
}


void _tcase_add_test(TCase * tc, const TTest * ttest,
int _signal, int allowed_exit_value,
int start, int end)
Expand Down Expand Up @@ -343,20 +384,84 @@ void tcase_set_timeout(TCase * tc, double timeout)
#endif /* HAVE_FORK */
}

void tcase_fn_start(const char *fname, const char *file,
int line)
void _tcase_fn_start(const char *fname, const char *file,
int line)
{
send_ctx_info(CK_CTX_TEST);
send_loc_info(file, line);

current_test_name = fname;
}

const char* tcase_name(void)
const char* tcase_current_name(void)
{
return current_test_name;
}

const char *tcase_name(TCase * tc)
{
if(tc == NULL)
return NULL;

return tc->name;
}

int tcase_ntests(TCase * tc)
{
if(tc == NULL)
return 0;

return check_list_length(tc->tflst);
}

TF **tcase_tests(TCase * tc)
{
if(tc == NULL)
return NULL;

return (TF **)check_list_as_array(tc->tflst);
}

const TTest *tf_test(TF * tf)
{
if(tf == NULL)
return NULL;

return tf->ttest;
}

int tf_loop_start(TF * tf)
{
if(tf == NULL)
return 0;

return tf->loop_start;
}

int tf_loop_end(TF * tf)
{
if(tf == NULL)
return 0;

return tf->loop_end;
}

int tf_signal(TF * tf)
{
if(tf == NULL)
return 0;

return tf->signal;
}

int tf_allowed_exit_value(TF * tf)
{
if(tf == NULL)
return 0;

return tf->allowed_exit_value;
}

void _mark_point(const char *file, int line)
{
send_loc_info(file, line);
Expand Down Expand Up @@ -436,6 +541,22 @@ void srunner_add_suite(SRunner * sr, Suite * s)
check_list_add_end(sr->slst, s);
}

int srunner_nsuites(SRunner * sr)
{
if(sr == NULL)
return 0;

return check_list_length(sr->slst);
}

Suite **srunner_suites(SRunner * sr)
{
if (sr == NULL)
return NULL;

return (Suite **)check_list_as_array(sr->slst);
}

void srunner_free(SRunner * sr)
{
List *l;
Expand Down Expand Up @@ -495,19 +616,10 @@ TestResult **srunner_failures(SRunner * sr)

TestResult **srunner_results(SRunner * sr)
{
int i = 0;
TestResult **trarray;
List *rlst;

trarray =(TestResult **) emalloc(sizeof(trarray[0]) * srunner_ntests_run(sr));
if(sr == NULL)
return NULL;

rlst = sr->resultlst;
for(check_list_front(rlst); !check_list_at_end(rlst);
check_list_advance(rlst))
{
trarray[i++] = (TestResult *)check_list_val(rlst);
}
return trarray;
return (TestResult **)check_list_as_array(sr->resultlst);
}

static int non_pass(enum test_result val)
Expand Down
136 changes: 132 additions & 4 deletions src/check.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ typedef struct TTest {
int line;
} TTest;

/**
* Type for a test fixture, which wraps a test.
*/
typedef struct TF TF;

/**
* Creates a test suite with the given name.
*
Expand Down Expand Up @@ -212,6 +217,50 @@ CK_DLL_EXP Suite *CK_EXPORT suite_create(const char *name);
*/
CK_DLL_EXP int CK_EXPORT suite_tcase(Suite * s, const char *tcname);

/**
* Get the name of a suite.
*
* @param s suite to get the name of
*
* @return the name of the suite
*
* @since 0.15.3
*/
CK_DLL_EXP const char * CK_EXPORT suite_name(Suite * s);

/**
* Get the number of test cases in a suite.
*
* This call returns the number of test cases currently in the
* suite.
*
* @param s suite to get the number of test cases from
*
* @return the number of test cases in the suite
*
* @since 0.15.3
*/
CK_DLL_EXP int CK_EXPORT suite_ntcases(Suite * s);

/**
* Get the test cases from the suite.
*
* Number of test cases is equal to srunner_ntcases().
*
* Information about individual test cases can be queried using:
* tcase_name(), tcase_ntags(), tcase_tags().
*
* Memory is malloc'd and must be freed; however, free the entire
* structure instead of individual test cases.
*
* @param s suite to get the test cases from
*
* @return array of test case objects
*
* @since 0.15.3
*/
CK_DLL_EXP TCase ** CK_EXPORT suite_tcases(Suite * s);

/**
* Add a test case to a suite.
*
Expand Down Expand Up @@ -253,6 +302,32 @@ CK_DLL_EXP TCase *CK_EXPORT tcase_create(const char *name);
* */
CK_DLL_EXP void CK_EXPORT tcase_set_tags(TCase * tc,
const char *tags);

/**
* Get the number of tags associated with a test case.
*
* @param tc the test case
*
* @return the number of tags associated with the test case
*
* @since 0.15.3
*/
CK_DLL_EXP int CK_EXPORT tcase_ntags(TCase * tc);

/**
* Get the tags associated with the test case.
*
* Memory is malloc'd and must be freed; however, free the entire
* structure instead of individual tags.
*
* @param tc the test case
*
* @return the array of string tags associated with the test case
*
* @since 0.15.3
*/
CK_DLL_EXP const char ** CK_EXPORT tcase_tags(TCase * tc);

/**
* Add a test function to a test case
*
Expand Down Expand Up @@ -439,8 +514,8 @@ CK_DLL_EXP void CK_EXPORT tcase_add_checked_fixture(TCase * tc, SFun setup,
CK_DLL_EXP void CK_EXPORT tcase_set_timeout(TCase * tc, double timeout);

/* Internal function to mark the start of a test function */
CK_DLL_EXP void CK_EXPORT tcase_fn_start(const char *fname, const char *file,
int line);
CK_DLL_EXP void CK_EXPORT _tcase_fn_start(const char *fname, const char *file,
int line);

/**
* Retreive the name of the current running test. This is the name
Expand All @@ -450,7 +525,27 @@ CK_DLL_EXP void CK_EXPORT tcase_fn_start(const char *fname, const char *file,
*
* @since 0.11.0
*/
CK_DLL_EXP const char* CK_EXPORT tcase_name(void);
CK_DLL_EXP const char* CK_EXPORT tcase_current_name(void);

/**
* Retreive the name of a test case.
*
* @param tc test case to get the name of
*
* @return the name of the test case
*
* @since 0.15.3
*/
CK_DLL_EXP const char * CK_EXPORT tcase_name(TCase * tc);

CK_DLL_EXP int CK_EXPORT tcase_ntests(TCase * tc);
CK_DLL_EXP TF ** CK_EXPORT tcase_tests(TCase * tc);

CK_DLL_EXP const TTest * CK_EXPORT tf_test(TF * tf);
CK_DLL_EXP int CK_EXPORT tf_loop_start(TF * tf);
CK_DLL_EXP int CK_EXPORT tf_loop_end(TF * tf);
CK_DLL_EXP int CK_EXPORT tf_signal(TF * tf);
CK_DLL_EXP int CK_EXPORT tf_allowed_exit_value(TF * tf);

/**
* Start a unit test with START_TEST(unit_name), end with END_TEST.
Expand Down Expand Up @@ -1972,7 +2067,7 @@ CK_DLL_EXP SRunner *CK_EXPORT srunner_create(Suite * s);
/**
* Add an additional suite to a suite runner.
*
* The first suite in a suite runner is always added in srunner_create().
* An initial suite in a suite runner may be added in srunner_create().
* This call adds additional suites to a suite runner.
*
* @param sr suite runner to add the given suite
Expand All @@ -1982,6 +2077,39 @@ CK_DLL_EXP SRunner *CK_EXPORT srunner_create(Suite * s);
*/
CK_DLL_EXP void CK_EXPORT srunner_add_suite(SRunner * sr, Suite * s);

/**
* Get the number of suites in the suite runner.
*
* A suite runner may have zero or more suites, this call returns
* the number of suites currently present in the runner.
*
* @param sr suite runner to examine
*
* @return the number of suites currently in the suite runner
*
* @since 0.15.3
*/
CK_DLL_EXP int CK_EXPORT srunner_nsuites(SRunner * sr);

/**
* Get an array of suites currently in the suite runner.
*
* Number of suites is equal to srunner_nsuites().
*
* Information about individual suites can be queried using:
* suite_name(), suite_ntcases(), suite_tcases().
*
* Memory is malloc'd and must be freed; however, free the entire
* structure instead of individual test suites.
*
* @param sr suite runner to retrieve suites from
*
* @return array of Suite objects
*
* @since 0.15.3
*/
CK_DLL_EXP Suite ** CK_EXPORT srunner_suites(SRunner * sr);

/**
* Frees a suite runner, including all contained suite and test cases.
*
Expand Down
Loading
Loading