1 /* Copyright (c) 2008 The NetBSD Foundation, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
33 #include "atf-c/detail/test_helpers.h"
35 /* ---------------------------------------------------------------------
36 * Auxiliary test cases.
37 * --------------------------------------------------------------------- */
39 ATF_TC_HEAD(empty, tc)
43 ATF_TC_BODY(empty, tc)
47 ATF_TC_HEAD(test_var, tc)
49 atf_tc_set_md_var(tc, "test-var", "Test text");
52 /* ---------------------------------------------------------------------
53 * Test cases for the "atf_tc_t" type.
54 * --------------------------------------------------------------------- */
59 atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init function");
61 ATF_TC_BODY(init, tcin)
65 RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
66 ATF_TC_BODY_NAME(empty), NULL, NULL));
67 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
68 ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
71 RE(atf_tc_init(&tc, "test2", ATF_TC_HEAD_NAME(test_var),
72 ATF_TC_BODY_NAME(empty), NULL, NULL));
73 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
74 ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
79 ATF_TC_HEAD(init_pack, tc)
81 atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init_pack function");
83 ATF_TC_BODY(init_pack, tcin)
86 atf_tc_pack_t tcp1 = {
88 .m_head = ATF_TC_HEAD_NAME(empty),
89 .m_body = ATF_TC_BODY_NAME(empty),
92 atf_tc_pack_t tcp2 = {
94 .m_head = ATF_TC_HEAD_NAME(test_var),
95 .m_body = ATF_TC_BODY_NAME(empty),
99 RE(atf_tc_init_pack(&tc, &tcp1, NULL));
100 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
101 ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
104 RE(atf_tc_init_pack(&tc, &tcp2, NULL));
105 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
106 ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
111 ATF_TC_HEAD(vars, tc)
113 atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_md_var, "
114 "atf_tc_has_md_var and atf_tc_set_md_var functions");
116 ATF_TC_BODY(vars, tcin)
120 RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
121 ATF_TC_BODY_NAME(empty), NULL, NULL));
122 ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
123 RE(atf_tc_set_md_var(&tc, "test-var", "Test value"));
124 ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
125 ATF_REQUIRE(strcmp(atf_tc_get_md_var(&tc, "test-var"), "Test value") == 0);
130 ATF_TC_HEAD(config, tc)
132 atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_config_var, "
133 "atf_tc_get_config_var_wd and atf_tc_has_config_var "
136 ATF_TC_BODY(config, tcin)
139 const char *const config[] = { "test-var", "test-value", NULL };
141 RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
142 ATF_TC_BODY_NAME(empty), NULL, NULL));
143 ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var"));
144 ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
147 RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
148 ATF_TC_BODY_NAME(empty), NULL, config));
149 ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var"));
150 ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"),
152 ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
153 ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2"));
154 ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"),
159 /* ---------------------------------------------------------------------
160 * Test cases for the free functions.
161 * --------------------------------------------------------------------- */
163 /* TODO: Add test cases for atf_tc_run. This is going to be very tough,
164 * but good tests here could allow us to avoid much of the indirect
165 * testing done later on. */
167 /* ---------------------------------------------------------------------
169 * --------------------------------------------------------------------- */
173 /* Add the test cases for the "atf_tcr_t" type. */
174 ATF_TP_ADD_TC(tp, init);
175 ATF_TP_ADD_TC(tp, init_pack);
176 ATF_TP_ADD_TC(tp, vars);
177 ATF_TP_ADD_TC(tp, config);
179 /* Add the test cases for the free functions. */
182 return atf_no_error();