1 /* $NetBSD: simple_unittest.c,v 1.1.1.2 2014/07/12 11:58:17 spz Exp $ */
3 * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
21 /* That is an example ATF test case, tailored to ISC DHCP sources.
22 For detailed description with examples, see man 3 atf-c-api. */
24 /* this macro defines a name of a test case. Typical test case constists
25 of an initial test declaration (ATF_TC()) followed by 3 phases:
27 - Initialization: ATF_TC_HEAD()
28 - Main body: ATF_TC_BODY()
29 - Cleanup: ATF_TC_CLEANUP()
31 In many cases initialization or cleanup are not needed. Use
32 ATF_TC_WITHOUT_HEAD() or ATF_TC_WITH_CLEANUP() as needed. */
33 ATF_TC(simple_test_case
);
36 ATF_TC_HEAD(simple_test_case
, tc
)
38 atf_tc_set_md_var(tc
, "descr", "This test case is a simple DHCP test.");
40 ATF_TC_BODY(simple_test_case
, tc
)
43 int this_is_linux
= 1;
44 /* Failing condition will fail the test, but the code
45 itself will continue */
48 /* assert style check. Test will abort if the condition is not met. */
51 ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
52 ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
54 /* tests can also explicitly report test result */
56 atf_tc_fail("Condition not met!"); /* Explicit failure. */
60 atf_tc_skip("Skipping test. This Linux-only test.");
63 if (condition
&& this_is_linux
) {
64 /* no extra comments for pass needed. It just passed. */
70 /* This macro defines main() method that will call specified
71 test cases. tp and simple_test_case names can be whatever you want
72 as long as it is a valid variable identifier. */
75 ATF_TP_ADD_TC(tp
, simple_test_case
);
77 return (atf_no_error());