2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #include "detail/test_helpers.h"
37 /* ---------------------------------------------------------------------
38 * Auxiliary test cases.
39 * --------------------------------------------------------------------- */
41 ATF_TC_HEAD(empty
, tc
)
45 ATF_TC_BODY(empty
, tc
)
49 ATF_TC_HEAD(test_var
, tc
)
51 atf_tc_set_md_var(tc
, "test-var", "Test text");
54 /* ---------------------------------------------------------------------
55 * Test cases for the "atf_tc_t" type.
56 * --------------------------------------------------------------------- */
61 atf_tc_set_md_var(tc
, "descr", "Tests the atf_tc_init function");
63 ATF_TC_BODY(init
, tcin
)
67 RE(atf_tc_init(&tc
, "test1", ATF_TC_HEAD_NAME(empty
),
68 ATF_TC_BODY_NAME(empty
), NULL
, NULL
));
69 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc
), "test1") == 0);
70 ATF_REQUIRE(!atf_tc_has_md_var(&tc
, "test-var"));
73 RE(atf_tc_init(&tc
, "test2", ATF_TC_HEAD_NAME(test_var
),
74 ATF_TC_BODY_NAME(empty
), NULL
, NULL
));
75 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc
), "test2") == 0);
76 ATF_REQUIRE(atf_tc_has_md_var(&tc
, "test-var"));
81 ATF_TC_HEAD(init_pack
, tc
)
83 atf_tc_set_md_var(tc
, "descr", "Tests the atf_tc_init_pack function");
85 ATF_TC_BODY(init_pack
, tcin
)
88 atf_tc_pack_t tcp1
= {
90 .m_head
= ATF_TC_HEAD_NAME(empty
),
91 .m_body
= ATF_TC_BODY_NAME(empty
),
94 atf_tc_pack_t tcp2
= {
96 .m_head
= ATF_TC_HEAD_NAME(test_var
),
97 .m_body
= ATF_TC_BODY_NAME(empty
),
101 RE(atf_tc_init_pack(&tc
, &tcp1
, NULL
));
102 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc
), "test1") == 0);
103 ATF_REQUIRE(!atf_tc_has_md_var(&tc
, "test-var"));
106 RE(atf_tc_init_pack(&tc
, &tcp2
, NULL
));
107 ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc
), "test2") == 0);
108 ATF_REQUIRE(atf_tc_has_md_var(&tc
, "test-var"));
113 ATF_TC_HEAD(vars
, tc
)
115 atf_tc_set_md_var(tc
, "descr", "Tests the atf_tc_get_md_var, "
116 "atf_tc_has_md_var and atf_tc_set_md_var functions");
118 ATF_TC_BODY(vars
, tcin
)
122 RE(atf_tc_init(&tc
, "test1", ATF_TC_HEAD_NAME(empty
),
123 ATF_TC_BODY_NAME(empty
), NULL
, NULL
));
124 ATF_REQUIRE(!atf_tc_has_md_var(&tc
, "test-var"));
125 RE(atf_tc_set_md_var(&tc
, "test-var", "Test value"));
126 ATF_REQUIRE(atf_tc_has_md_var(&tc
, "test-var"));
127 ATF_REQUIRE(strcmp(atf_tc_get_md_var(&tc
, "test-var"), "Test value") == 0);
132 ATF_TC_HEAD(config
, tc
)
134 atf_tc_set_md_var(tc
, "descr", "Tests the atf_tc_get_config_var, "
135 "atf_tc_get_config_var_wd and atf_tc_has_config_var "
138 ATF_TC_BODY(config
, tcin
)
141 const char *const config
[] = { "test-var", "test-value", NULL
};
143 RE(atf_tc_init(&tc
, "test1", ATF_TC_HEAD_NAME(empty
),
144 ATF_TC_BODY_NAME(empty
), NULL
, NULL
));
145 ATF_REQUIRE(!atf_tc_has_config_var(&tc
, "test-var"));
146 ATF_REQUIRE(!atf_tc_has_md_var(&tc
, "test-var"));
149 RE(atf_tc_init(&tc
, "test1", ATF_TC_HEAD_NAME(empty
),
150 ATF_TC_BODY_NAME(empty
), NULL
, config
));
151 ATF_REQUIRE(atf_tc_has_config_var(&tc
, "test-var"));
152 ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc
, "test-var"),
154 ATF_REQUIRE(!atf_tc_has_md_var(&tc
, "test-var"));
155 ATF_REQUIRE(!atf_tc_has_config_var(&tc
, "test-var2"));
156 ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc
, "test-var2", "def-value"),
161 /* ---------------------------------------------------------------------
162 * Test cases for the free functions.
163 * --------------------------------------------------------------------- */
165 /* TODO: Add test cases for atf_tc_run. This is going to be very tough,
166 * but good tests here could allow us to avoid much of the indirect
167 * testing done later on. */
169 /* ---------------------------------------------------------------------
170 * Tests cases for the header file.
171 * --------------------------------------------------------------------- */
173 HEADER_TC(include
, "atf-c/tc.h");
175 /* ---------------------------------------------------------------------
177 * --------------------------------------------------------------------- */
181 /* Add the test cases for the "atf_tcr_t" type. */
182 ATF_TP_ADD_TC(tp
, init
);
183 ATF_TP_ADD_TC(tp
, init_pack
);
184 ATF_TP_ADD_TC(tp
, vars
);
185 ATF_TP_ADD_TC(tp
, config
);
187 /* Add the test cases for the free functions. */
190 /* Add the test cases for the header file. */
191 ATF_TP_ADD_TC(tp
, include
);
193 return atf_no_error();