From 64c0e824ee82dbbe329a66eefa92c7a31089a84f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 28 Sep 2010 14:28:34 +0200 Subject: Add subunit_progress() function to child interface. --- c/include/subunit/child.h | 17 +++++++++++++++++ c/lib/child.c | 22 ++++++++++++++++++++++ c/tests/test_child.c | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/c/include/subunit/child.h b/c/include/subunit/child.h index 0a4e601..896d2df 100644 --- a/c/include/subunit/child.h +++ b/c/include/subunit/child.h @@ -74,6 +74,23 @@ extern void subunit_test_skip(char const * const name, char const * const reason); +enum subunit_progress_whence { + SUBUNIT_PROGRESS_SET, + SUBUNIT_PROGRESS_CUR, + SUBUNIT_PROGRESS_POP, + SUBUNIT_PROGRESS_PUSH, +}; + +/** + * subunit_progress: + * + * Report the progress of a test run. + * @whence: The type of progress update to report. + * @offset: Offset of the progress (only for SUBUNIT_PROGRESS_SET + * and SUBUNIT_PROGRESS_CUR). + */ +extern void subunit_progress(enum subunit_progress_whence whence, int offset); + #ifdef __cplusplus } #endif diff --git a/c/lib/child.c b/c/lib/child.c index 2b59747..20f38da 100644 --- a/c/lib/child.c +++ b/c/lib/child.c @@ -80,3 +80,25 @@ subunit_test_skip(char const * const name, char const * const reason) { subunit_send_event("skip", name, reason); } + +void +subunit_progress(enum subunit_progress_whence whence, int offset) +{ + switch (whence) { + case SUBUNIT_PROGRESS_SET: + printf("progress: %d\n", offset); + break; + case SUBUNIT_PROGRESS_CUR: + printf("progress: %+-d\n", offset); + break; + case SUBUNIT_PROGRESS_POP: + printf("progress: pop\n"); + break; + case SUBUNIT_PROGRESS_PUSH: + printf("progress: push\n"); + break; + default: + fprintf(stderr, "Invalid whence %d in subunit_progress()\n", whence); + break; + } +} diff --git a/c/tests/test_child.c b/c/tests/test_child.c index 6399eeb..d0e254a 100644 --- a/c/tests/test_child.c +++ b/c/tests/test_child.c @@ -164,6 +164,25 @@ START_TEST (test_skip) } END_TEST + +static void +call_test_progress(void) +{ + subunit_progress(SUBUNIT_PROGRESS_POP, 0); + subunit_progress(SUBUNIT_PROGRESS_SET, 5); + subunit_progress(SUBUNIT_PROGRESS_PUSH, 0); +} + + +START_TEST (test_progress) +{ + test_stdout_function("progress: pop\n" + "progress: 5\n" + "progress: push\n", + call_test_progress); +} +END_TEST + static Suite * child_suite(void) { @@ -175,6 +194,7 @@ child_suite(void) tcase_add_test (tc_core, test_fail); tcase_add_test (tc_core, test_error); tcase_add_test (tc_core, test_skip); + tcase_add_test (tc_core, test_progress); return s; } -- cgit v1.2.1