Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c / tc_test.c
blob4aaf9a54c242f3d152e5477d0583083ba5ba5f29
1 /*
2 * Automated Testing Framework (atf)
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
30 #include <stdbool.h>
31 #include <string.h>
33 #include <atf-c.h>
35 #include "detail/test_helpers.h"
37 /* ---------------------------------------------------------------------
38 * Auxiliary test cases.
39 * --------------------------------------------------------------------- */
41 ATF_TC_HEAD(empty, tc)
43 if (tc != NULL) {}
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 * --------------------------------------------------------------------- */
58 ATF_TC(init);
59 ATF_TC_HEAD(init, tc)
61 atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init function");
63 ATF_TC_BODY(init, tcin)
65 atf_tc_t tc;
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"));
71 atf_tc_fini(&tc);
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"));
77 atf_tc_fini(&tc);
80 ATF_TC(init_pack);
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)
87 atf_tc_t tc;
88 atf_tc_pack_t tcp1 = {
89 .m_ident = "test1",
90 .m_head = ATF_TC_HEAD_NAME(empty),
91 .m_body = ATF_TC_BODY_NAME(empty),
92 .m_cleanup = NULL,
94 atf_tc_pack_t tcp2 = {
95 .m_ident = "test2",
96 .m_head = ATF_TC_HEAD_NAME(test_var),
97 .m_body = ATF_TC_BODY_NAME(empty),
98 .m_cleanup = NULL,
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"));
104 atf_tc_fini(&tc);
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"));
109 atf_tc_fini(&tc);
112 ATF_TC(vars);
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)
120 atf_tc_t tc;
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);
128 atf_tc_fini(&tc);
131 ATF_TC(config);
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 "
136 "functions");
138 ATF_TC_BODY(config, tcin)
140 atf_tc_t tc;
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"));
147 atf_tc_fini(&tc);
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"),
153 "test-value") == 0);
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"),
157 "def-value") == 0);
158 atf_tc_fini(&tc);
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 /* ---------------------------------------------------------------------
176 * Main.
177 * --------------------------------------------------------------------- */
179 ATF_TP_ADD_TCS(tp)
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. */
188 /* TODO */
190 /* Add the test cases for the header file. */
191 ATF_TP_ADD_TC(tp, include);
193 return atf_no_error();