summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-09-28 14:28:34 +0200
committerJelmer Vernooij <jelmer@samba.org>2010-09-28 14:28:34 +0200
commit64c0e824ee82dbbe329a66eefa92c7a31089a84f (patch)
tree2e6300a253f322b04efc3db484fca632a549a491
parenta5888feab02f1eef4fa35b8f216479173eba90e3 (diff)
downloadsubunit-git-64c0e824ee82dbbe329a66eefa92c7a31089a84f.tar.gz
Add subunit_progress() function to child interface.
-rw-r--r--c/include/subunit/child.h17
-rw-r--r--c/lib/child.c22
-rw-r--r--c/tests/test_child.c20
3 files changed, 59 insertions, 0 deletions
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;
}