ATF_TC_BODY(init, tcin) { atf_tc_t tc; RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty), ATF_TC_BODY_NAME(empty), NULL, NULL)); ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0); ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var")); atf_tc_fini(&tc); RE(atf_tc_init(&tc, "test2", ATF_TC_HEAD_NAME(test_var), ATF_TC_BODY_NAME(empty), NULL, NULL)); ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0); ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var")); atf_tc_fini(&tc); }
ATF_TC_BODY(init_pack, tcin) { atf_tc_t tc; atf_tc_pack_t tcp1 = { .m_ident = "test1", .m_head = ATF_TC_HEAD_NAME(empty), .m_body = ATF_TC_BODY_NAME(empty), .m_cleanup = NULL, }; atf_tc_pack_t tcp2 = { .m_ident = "test2", .m_head = ATF_TC_HEAD_NAME(test_var), .m_body = ATF_TC_BODY_NAME(empty), .m_cleanup = NULL, }; RE(atf_tc_init_pack(&tc, &tcp1, NULL)); ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0); ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var")); atf_tc_fini(&tc); RE(atf_tc_init_pack(&tc, &tcp2, NULL)); ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0); ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var")); atf_tc_fini(&tc); } ATF_TC(vars); ATF_TC_HEAD(vars, tc) { atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_md_var, " "atf_tc_has_md_var and atf_tc_set_md_var functions"); } ATF_TC_BODY(vars, tcin) { atf_tc_t tc; RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty), ATF_TC_BODY_NAME(empty), NULL, NULL)); ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var")); RE(atf_tc_set_md_var(&tc, "test-var", "Test value")); ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var")); ATF_REQUIRE(strcmp(atf_tc_get_md_var(&tc, "test-var"), "Test value") == 0); atf_tc_fini(&tc); }
ATF_TC_BODY(config, tcin) { atf_tc_t tc; const char *const config[] = { "test-var", "test-value", NULL }; RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty), ATF_TC_BODY_NAME(empty), NULL, NULL)); ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var")); ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var")); atf_tc_fini(&tc); RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty), ATF_TC_BODY_NAME(empty), NULL, config)); ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var")); ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"), "test-value") == 0); ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var")); ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2")); ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"), "def-value") == 0); atf_tc_fini(&tc); }
atf_require_errno_semicolons(void) { /* Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would * cause an empty-statement that confuses some compilers. */ ATF_REQUIRE_ERRNO(1, 1 == 1); ATF_REQUIRE_ERRNO(2, 2 == 2); } /* Test case names should not be expanded during instatiation so that they * can have the exact same name as macros. */ #define TEST_MACRO_1 invalid + name #define TEST_MACRO_2 invalid + name #define TEST_MACRO_3 invalid + name ATF_TC(TEST_MACRO_1); ATF_TC_HEAD(TEST_MACRO_1, tc) { if (tc != NULL) {} } ATF_TC_BODY(TEST_MACRO_1, tc) { if (tc != NULL) {} } atf_tc_t *test_name_1 = &ATF_TC_NAME(TEST_MACRO_1); void (*head_1)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_1); void (*body_1)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_1); ATF_TC_WITH_CLEANUP(TEST_MACRO_2); ATF_TC_HEAD(TEST_MACRO_2, tc) { if (tc != NULL) {} } ATF_TC_BODY(TEST_MACRO_2, tc) { if (tc != NULL) {} } ATF_TC_CLEANUP(TEST_MACRO_2, tc) { if (tc != NULL) {} } atf_tc_t *test_name_2 = &ATF_TC_NAME(TEST_MACRO_2); void (*head_2)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_2); void (*body_2)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_2); void (*cleanup_2)(const atf_tc_t *) = ATF_TC_CLEANUP_NAME(TEST_MACRO_2); ATF_TC_WITHOUT_HEAD(TEST_MACRO_3); ATF_TC_BODY(TEST_MACRO_3, tc) { if (tc != NULL) {} } atf_tc_t *test_name_3 = &ATF_TC_NAME(TEST_MACRO_3); void (*body_3)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_3);