Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / test-programs / cpp_helpers.cpp
blobd8a495e7c67e3419512fb6dd4851a8827a915c48
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
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 extern "C" {
31 #include <signal.h>
32 #include <unistd.h>
35 #include <cstdlib>
36 #include <fstream>
37 #include <iostream>
39 #include <atf-c++.hpp>
41 #include "atf-c++/detail/fs.hpp"
43 // ------------------------------------------------------------------------
44 // Helper tests for "t_config".
45 // ------------------------------------------------------------------------
47 ATF_TEST_CASE(config_unset);
48 ATF_TEST_CASE_HEAD(config_unset)
50 set_md_var("descr", "Helper test case for the t_config test program");
52 ATF_TEST_CASE_BODY(config_unset)
54 ATF_REQUIRE(!has_config_var("test"));
57 ATF_TEST_CASE(config_empty);
58 ATF_TEST_CASE_HEAD(config_empty)
60 set_md_var("descr", "Helper test case for the t_config test program");
62 ATF_TEST_CASE_BODY(config_empty)
64 ATF_REQUIRE_EQ(get_config_var("test"), "");
67 ATF_TEST_CASE(config_value);
68 ATF_TEST_CASE_HEAD(config_value)
70 set_md_var("descr", "Helper test case for the t_config test program");
72 ATF_TEST_CASE_BODY(config_value)
74 ATF_REQUIRE_EQ(get_config_var("test"), "foo");
77 ATF_TEST_CASE(config_multi_value);
78 ATF_TEST_CASE_HEAD(config_multi_value)
80 set_md_var("descr", "Helper test case for the t_config test program");
82 ATF_TEST_CASE_BODY(config_multi_value)
84 ATF_REQUIRE_EQ(get_config_var("test"), "foo bar");
87 // ------------------------------------------------------------------------
88 // Helper tests for "t_expect".
89 // ------------------------------------------------------------------------
91 ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_and_pass);
92 ATF_TEST_CASE_BODY(expect_pass_and_pass)
94 expect_pass();
97 ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_but_fail_requirement);
98 ATF_TEST_CASE_BODY(expect_pass_but_fail_requirement)
100 expect_pass();
101 fail("Some reason");
104 ATF_TEST_CASE_WITHOUT_HEAD(expect_pass_but_fail_check);
105 ATF_TEST_CASE_BODY(expect_pass_but_fail_check)
107 expect_pass();
108 fail_nonfatal("Some reason");
111 ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_and_fail_requirement);
112 ATF_TEST_CASE_BODY(expect_fail_and_fail_requirement)
114 expect_fail("Fail reason");
115 fail("The failure");
116 expect_pass();
119 ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_and_fail_check);
120 ATF_TEST_CASE_BODY(expect_fail_and_fail_check)
122 expect_fail("Fail first");
123 fail_nonfatal("abc");
124 expect_pass();
126 expect_fail("And fail again");
127 fail_nonfatal("def");
128 expect_pass();
131 ATF_TEST_CASE_WITHOUT_HEAD(expect_fail_but_pass);
132 ATF_TEST_CASE_BODY(expect_fail_but_pass)
134 expect_fail("Fail first");
135 fail_nonfatal("abc");
136 expect_pass();
138 expect_fail("Will not fail");
139 expect_pass();
141 expect_fail("And fail again");
142 fail_nonfatal("def");
143 expect_pass();
146 ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_any_and_exit);
147 ATF_TEST_CASE_BODY(expect_exit_any_and_exit)
149 expect_exit(-1, "Call will exit");
150 std::exit(EXIT_SUCCESS);
153 ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_code_and_exit);
154 ATF_TEST_CASE_BODY(expect_exit_code_and_exit)
156 expect_exit(123, "Call will exit");
157 std::exit(123);
160 ATF_TEST_CASE_WITHOUT_HEAD(expect_exit_but_pass);
161 ATF_TEST_CASE_BODY(expect_exit_but_pass)
163 expect_exit(-1, "Call won't exit");
166 ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_any_and_signal);
167 ATF_TEST_CASE_BODY(expect_signal_any_and_signal)
169 expect_signal(-1, "Call will signal");
170 ::kill(getpid(), SIGKILL);
173 ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_no_and_signal);
174 ATF_TEST_CASE_BODY(expect_signal_no_and_signal)
176 expect_signal(SIGHUP, "Call will signal");
177 ::kill(getpid(), SIGHUP);
180 ATF_TEST_CASE_WITHOUT_HEAD(expect_signal_but_pass);
181 ATF_TEST_CASE_BODY(expect_signal_but_pass)
183 expect_signal(-1, "Call won't signal");
186 ATF_TEST_CASE_WITHOUT_HEAD(expect_death_and_exit);
187 ATF_TEST_CASE_BODY(expect_death_and_exit)
189 expect_death("Exit case");
190 std::exit(123);
193 ATF_TEST_CASE_WITHOUT_HEAD(expect_death_and_signal);
194 ATF_TEST_CASE_BODY(expect_death_and_signal)
196 expect_death("Signal case");
197 kill(getpid(), SIGKILL);
200 ATF_TEST_CASE_WITHOUT_HEAD(expect_death_but_pass);
201 ATF_TEST_CASE_BODY(expect_death_but_pass)
203 expect_death("Call won't die");
206 ATF_TEST_CASE(expect_timeout_and_hang);
207 ATF_TEST_CASE_HEAD(expect_timeout_and_hang)
209 set_md_var("timeout", "1");
211 ATF_TEST_CASE_BODY(expect_timeout_and_hang)
213 expect_timeout("Will overrun");
214 ::sleep(5);
217 ATF_TEST_CASE(expect_timeout_but_pass);
218 ATF_TEST_CASE_HEAD(expect_timeout_but_pass)
220 set_md_var("timeout", "1");
222 ATF_TEST_CASE_BODY(expect_timeout_but_pass)
224 expect_timeout("Will just exit");
227 // ------------------------------------------------------------------------
228 // Helper tests for "t_meta_data".
229 // ------------------------------------------------------------------------
231 ATF_TEST_CASE(metadata_no_descr);
232 ATF_TEST_CASE_HEAD(metadata_no_descr)
235 ATF_TEST_CASE_BODY(metadata_no_descr)
239 ATF_TEST_CASE_WITHOUT_HEAD(metadata_no_head);
240 ATF_TEST_CASE_BODY(metadata_no_head)
244 // ------------------------------------------------------------------------
245 // Helper tests for "t_srcdir".
246 // ------------------------------------------------------------------------
248 ATF_TEST_CASE(srcdir_exists);
249 ATF_TEST_CASE_HEAD(srcdir_exists)
251 set_md_var("descr", "Helper test case for the t_srcdir test program");
253 ATF_TEST_CASE_BODY(srcdir_exists)
255 if (!atf::fs::exists(atf::fs::path(get_config_var("srcdir")) /
256 "datafile"))
257 ATF_FAIL("Cannot find datafile");
260 // ------------------------------------------------------------------------
261 // Helper tests for "t_result".
262 // ------------------------------------------------------------------------
264 ATF_TEST_CASE(result_pass);
265 ATF_TEST_CASE_HEAD(result_pass) { }
266 ATF_TEST_CASE_BODY(result_pass)
268 std::cout << "msg\n";
271 ATF_TEST_CASE(result_fail);
272 ATF_TEST_CASE_HEAD(result_fail) { }
273 ATF_TEST_CASE_BODY(result_fail)
275 std::cout << "msg\n";
276 ATF_FAIL("Failure reason");
279 ATF_TEST_CASE(result_skip);
280 ATF_TEST_CASE_HEAD(result_skip) { }
281 ATF_TEST_CASE_BODY(result_skip)
283 std::cout << "msg\n";
284 ATF_SKIP("Skipped reason");
287 ATF_TEST_CASE(result_newlines_fail);
288 ATF_TEST_CASE_HEAD(result_newlines_fail)
290 set_md_var("descr", "Helper test case for the t_result test program");
292 ATF_TEST_CASE_BODY(result_newlines_fail)
294 ATF_FAIL("First line\nSecond line");
297 ATF_TEST_CASE(result_newlines_skip);
298 ATF_TEST_CASE_HEAD(result_newlines_skip)
300 set_md_var("descr", "Helper test case for the t_result test program");
302 ATF_TEST_CASE_BODY(result_newlines_skip)
304 ATF_SKIP("First line\nSecond line");
307 ATF_TEST_CASE(result_exception);
308 ATF_TEST_CASE_HEAD(result_exception) { }
309 ATF_TEST_CASE_BODY(result_exception)
311 throw std::runtime_error("This is unhandled");
314 // ------------------------------------------------------------------------
315 // Main.
316 // ------------------------------------------------------------------------
318 ATF_INIT_TEST_CASES(tcs)
320 // Add helper tests for t_config.
321 ATF_ADD_TEST_CASE(tcs, config_unset);
322 ATF_ADD_TEST_CASE(tcs, config_empty);
323 ATF_ADD_TEST_CASE(tcs, config_value);
324 ATF_ADD_TEST_CASE(tcs, config_multi_value);
326 // Add helper tests for t_expect.
327 ATF_ADD_TEST_CASE(tcs, expect_pass_and_pass);
328 ATF_ADD_TEST_CASE(tcs, expect_pass_but_fail_requirement);
329 ATF_ADD_TEST_CASE(tcs, expect_pass_but_fail_check);
330 ATF_ADD_TEST_CASE(tcs, expect_fail_and_fail_requirement);
331 ATF_ADD_TEST_CASE(tcs, expect_fail_and_fail_check);
332 ATF_ADD_TEST_CASE(tcs, expect_fail_but_pass);
333 ATF_ADD_TEST_CASE(tcs, expect_exit_any_and_exit);
334 ATF_ADD_TEST_CASE(tcs, expect_exit_code_and_exit);
335 ATF_ADD_TEST_CASE(tcs, expect_exit_but_pass);
336 ATF_ADD_TEST_CASE(tcs, expect_signal_any_and_signal);
337 ATF_ADD_TEST_CASE(tcs, expect_signal_no_and_signal);
338 ATF_ADD_TEST_CASE(tcs, expect_signal_but_pass);
339 ATF_ADD_TEST_CASE(tcs, expect_death_and_exit);
340 ATF_ADD_TEST_CASE(tcs, expect_death_and_signal);
341 ATF_ADD_TEST_CASE(tcs, expect_death_but_pass);
342 ATF_ADD_TEST_CASE(tcs, expect_timeout_and_hang);
343 ATF_ADD_TEST_CASE(tcs, expect_timeout_but_pass);
345 // Add helper tests for t_meta_data.
346 ATF_ADD_TEST_CASE(tcs, metadata_no_descr);
347 ATF_ADD_TEST_CASE(tcs, metadata_no_head);
349 // Add helper tests for t_srcdir.
350 ATF_ADD_TEST_CASE(tcs, srcdir_exists);
352 // Add helper tests for t_result.
353 ATF_ADD_TEST_CASE(tcs, result_pass);
354 ATF_ADD_TEST_CASE(tcs, result_fail);
355 ATF_ADD_TEST_CASE(tcs, result_skip);
356 ATF_ADD_TEST_CASE(tcs, result_newlines_fail);
357 ATF_ADD_TEST_CASE(tcs, result_newlines_skip);
358 ATF_ADD_TEST_CASE(tcs, result_exception);