aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2012-10-16 12:01:20 +0200
committerAndreas Schneider <asn@cryptomilk.org>2012-10-16 12:01:20 +0200
commita2c8bdcbd2fe299c5415d6b6a739d65deb607f99 (patch)
treea229aca53f4f4cae919dd87f651418e648723d79 /example
parente8d5479e47226de1c4388c24f4305861b80e786c (diff)
downloadcmocka-a2c8bdcbd2fe299c5415d6b6a739d65deb607f99.tar.gz
cmocka-a2c8bdcbd2fe299c5415d6b6a739d65deb607f99.tar.xz
cmocka-a2c8bdcbd2fe299c5415d6b6a739d65deb607f99.zip
tests: Extend the run_tests example.
Diffstat (limited to 'example')
-rw-r--r--example/run_tests.c24
1 files changed, 23 insertions, 1 deletions
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 <setjmp.h>
#include <cmocka.h>
-// 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);