1 /* $NetBSD: simple_unittest.c,v 1.1.1.2 2014/07/12 11:58:17 spz Exp $ */
2 /*
3 * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
4 *
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.
8 *
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.
16 */
17
18 #include <config.h>
19 #include <atf-c.h>
20
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. */
23
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:
26
27 - Initialization: ATF_TC_HEAD()
28 - Main body: ATF_TC_BODY()
29 - Cleanup: ATF_TC_CLEANUP()
30
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);
34
35
ATF_TC_HEAD(simple_test_case,tc)36 ATF_TC_HEAD(simple_test_case, tc)
37 {
38 atf_tc_set_md_var(tc, "descr", "This test case is a simple DHCP test.");
39 }
ATF_TC_BODY(simple_test_case,tc)40 ATF_TC_BODY(simple_test_case, tc)
41 {
42 int condition = 1;
43 int this_is_linux = 1;
44 /* Failing condition will fail the test, but the code
45 itself will continue */
46 ATF_CHECK( 2 > 1 );
47
48 /* assert style check. Test will abort if the condition is not met. */
49 ATF_REQUIRE( 5 > 4 );
50
51 ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
52 ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
53
54 /* tests can also explicitly report test result */
55 if (!condition) {
56 atf_tc_fail("Condition not met!"); /* Explicit failure. */
57 }
58
59 if (!this_is_linux) {
60 atf_tc_skip("Skipping test. This Linux-only test.");
61 }
62
63 if (condition && this_is_linux) {
64 /* no extra comments for pass needed. It just passed. */
65 atf_tc_pass();
66 }
67
68 }
69
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. */
ATF_TP_ADD_TCS(tp)73 ATF_TP_ADD_TCS(tp)
74 {
75 ATF_TP_ADD_TC(tp, simple_test_case);
76
77 return (atf_no_error());
78 }
79