aboutsummaryrefslogtreecommitdiff
path: root/tests/test_setup_fail.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2014-09-12 17:18:57 +0200
committerAndreas Schneider <asn@cryptomilk.org>2015-02-08 10:29:16 +0100
commit5e8c5d90db2c55e203c11dbbec91c3e44bcb2023 (patch)
tree81d89f4749a9e51a26912502317ffc32fac9190f /tests/test_setup_fail.c
parent05c73e1d3d7693b2ff0f1a5f8c39a6e32c7a2f38 (diff)
downloadcmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.tar.gz
cmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.tar.xz
cmocka-5e8c5d90db2c55e203c11dbbec91c3e44bcb2023.zip
tests: Use new cmocka test runner in our tests and examples
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'tests/test_setup_fail.c')
-rw-r--r--tests/test_setup_fail.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/tests/test_setup_fail.c b/tests/test_setup_fail.c
index 923886c..e3f8df8 100644
--- a/tests/test_setup_fail.c
+++ b/tests/test_setup_fail.c
@@ -5,11 +5,11 @@
#include <setjmp.h>
#include <cmocka.h>
-static void setup_fail(void **state) {
+static int setup_fail(void **state) {
*state = NULL;
/* We need to fail in setup */
- assert_non_null(NULL);
+ return -1;
}
static void int_test_ignored(void **state) {
@@ -17,13 +17,18 @@ static void int_test_ignored(void **state) {
assert_non_null(*state);
}
-static void setup_ok(void **state) {
- int *answer = malloc(sizeof(int));
+static int setup_ok(void **state) {
+ int *answer;
- assert_non_null(answer);
+ answer = malloc(sizeof(int));
+ if (answer == NULL) {
+ return -1;
+ }
*answer = 42;
*state = answer;
+
+ return 0;
}
/* A test case that does check if an int is equal. */
@@ -33,15 +38,17 @@ static void int_test_success(void **state) {
assert_int_equal(*answer, 42);
}
-static void teardown(void **state) {
+static int teardown(void **state) {
free(*state);
+
+ return 0;
}
int main(void) {
- const UnitTest tests[] = {
- unit_test_setup_teardown(int_test_ignored, setup_fail, teardown),
- unit_test_setup_teardown(int_test_success, setup_ok, teardown),
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test_setup_teardown(int_test_ignored, setup_fail, teardown),
+ cmocka_unit_test_setup_teardown(int_test_success, setup_ok, teardown),
};
- return run_tests(tests);
+ return cmocka_run_group_tests(tests, NULL, NULL);
}