From: Andreas Schneider Date: Tue, 16 Oct 2012 10:01:20 +0000 (+0200) Subject: tests: Extend the run_tests example. X-Git-Tag: cmocka-1.1.1~280 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a2c8bdcbd2fe299c5415d6b6a739d65deb607f99;p=platform%2Fupstream%2Fcmocka.git tests: Extend the run_tests example. --- diff --git a/example/run_tests.c b/example/run_tests.c index 5a5e5e4..817629b 100644 --- a/example/run_tests.c +++ b/example/run_tests.c @@ -18,14 +18,36 @@ #include #include -// A test case that does nothing and succeeds. +static void setup(void **state) { + int *answer = malloc(sizeof(int)); + + assert_non_null(answer); + *answer = 42; + + *state = answer; +} + +static void teardown(void **state) { + free(*state); +} + +/* A test case that does nothing and succeeds. */ static void null_test_success(void **state) { (void) state; } +/* A test case that does check if an int is equal. */ +static void int_test_success(void **state) { + int *answer = *state; + + assert_int_equal(*answer, 42); +} + + int main(void) { const UnitTest tests[] = { unit_test(null_test_success), + unit_test_setup_teardown(int_test_success, setup, teardown), }; return run_tests(tests);