tests: Migrate to new cmocka API
authorAndreas Schneider <asn@cryptomilk.org>
Wed, 12 Aug 2015 14:07:27 +0000 (16:07 +0200)
committerAndreas Schneider <asn@samba.org>
Mon, 17 Aug 2015 08:27:37 +0000 (10:27 +0200)
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
tests/test_dns_fake.c
tests/test_real_res_query.c
tests/test_res_init.c
tests/test_res_query_search.c

index 527ea71..9bc92cd 100644 (file)
@@ -563,21 +563,21 @@ int main(void)
 {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_res_fake_a_query),
-               unit_test(test_res_fake_a_query_case_insensitive),
-               unit_test(test_res_fake_a_query_trailing_dot),
-               unit_test(test_res_fake_a_query_notfound),
-               unit_test(test_res_fake_aaaa_query),
-               unit_test(test_res_fake_aaaa_query_notfound),
-               unit_test(test_res_fake_srv_query),
-               unit_test(test_res_fake_srv_query_minimal),
-               unit_test(test_res_fake_soa_query),
-               unit_test(test_res_fake_cname_query),
-               unit_test(test_res_fake_a_via_cname),
+       const struct CMUnitTest fake_tests[] = {
+               cmocka_unit_test(test_res_fake_a_query),
+               cmocka_unit_test(test_res_fake_a_query_case_insensitive),
+               cmocka_unit_test(test_res_fake_a_query_trailing_dot),
+               cmocka_unit_test(test_res_fake_a_query_notfound),
+               cmocka_unit_test(test_res_fake_aaaa_query),
+               cmocka_unit_test(test_res_fake_aaaa_query_notfound),
+               cmocka_unit_test(test_res_fake_srv_query),
+               cmocka_unit_test(test_res_fake_srv_query_minimal),
+               cmocka_unit_test(test_res_fake_soa_query),
+               cmocka_unit_test(test_res_fake_cname_query),
+               cmocka_unit_test(test_res_fake_a_via_cname),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(fake_tests, NULL, NULL);
 
        return rc;
 }
index 9c8132a..04ade89 100644 (file)
@@ -189,12 +189,12 @@ int main(void)
 {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_res_query_a_record),
-               unit_test(test_res_query_srv_record),
+       const struct CMUnitTest real_tests[] = {
+               cmocka_unit_test(test_res_query_a_record),
+               cmocka_unit_test(test_res_query_srv_record),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(real_tests, NULL, NULL);
 
        return rc;
 }
index e42b8a4..5cd3591 100644 (file)
@@ -23,7 +23,7 @@ struct resolv_conf_test_state {
        char *resolv_conf_path;
 };
 
-static void setup(void **state)
+static int setup(void **state)
 {
        struct resolv_conf_test_state *test_state;
 
@@ -40,15 +40,17 @@ static void setup(void **state)
        assert_non_null(test_state->resolv_conf);
 
        *state = test_state;
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        struct resolv_conf_test_state *test_state;
 
        test_state = (struct resolv_conf_test_state *) *state;
 
-       if (test_state == NULL) return;
+       if (test_state == NULL) return -1;
 
        if (test_state->resolv_conf) {
                fclose(test_state->resolv_conf);
@@ -64,6 +66,8 @@ static void teardown(void **state)
        }
 
        free(test_state);
+
+       return 0;
 }
 
 static void test_res_ninit(void **state)
@@ -195,11 +199,12 @@ static void test_res_ninit_enoent(void **state)
 int main(void) {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_res_ninit, setup, teardown),
-               unit_test(test_res_ninit_enoent),
+       const struct CMUnitTest init_tests[] = {
+               cmocka_unit_test_setup_teardown(test_res_ninit, setup, teardown),
+               cmocka_unit_test(test_res_ninit_enoent),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(init_tests, NULL, NULL);
+
        return rc;
 }
index 9eef6e4..395cb0c 100644 (file)
 
 #define ANSIZE 256
 
-static void setup_dns_srv_ipv4(void **state)
+static int setup_dns_srv_ipv4(void **state)
 {
        torture_setup_dns_srv_ipv4(state);
        setenv("RESOLV_WRAPPER_CONF", torture_server_resolv_conf(state), 1);
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        torture_teardown_dns_srv(state);
+
+       return 0;
 }
 
 static void test_res_query(void **state)
@@ -137,16 +141,16 @@ int main(void)
 {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test_setup_teardown(test_res_query,
-                                        setup_dns_srv_ipv4,
-                                        teardown),
-               unit_test_setup_teardown(test_res_search,
-                                        setup_dns_srv_ipv4,
-                                        teardown),
+       const struct CMUnitTest res_tests[] = {
+               cmocka_unit_test_setup_teardown(test_res_query,
+                                               setup_dns_srv_ipv4,
+                                               teardown),
+               cmocka_unit_test_setup_teardown(test_res_search,
+                                               setup_dns_srv_ipv4,
+                                               teardown),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(res_tests, NULL, NULL);
 
        return rc;
 }