]> git.ipfire.org Git - thirdparty/dhcp.git/blame - server/tests/simple_unittest.c
[25901_atf] First test for client-id hash table implemented.
[thirdparty/dhcp.git] / server / tests / simple_unittest.c
CommitLineData
a1a15031 1/*
db81cc0c 2 * Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
a1a15031
TM
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14 * PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <config.h>
18#include <atf-c.h>
19
db81cc0c
TM
20/* That is an example ATF test case, tailored to ISC DHCP sources.
21 For detailed description with examples, see man 3 atf-c-api. */
22
23/* this macro defines a name of a test case. Typical test case constists
24 of an initial test declaration (ATF_TC()) followed by 3 phases:
25
26 - Initialization: ATF_TC_HEAD()
27 - Main body: ATF_TC_BODY()
28 - Cleanup: ATF_TC_CLEANUP()
29
30 In many cases initialization or cleanup are not needed. Use
31 ATF_TC_WITHOUT_HEAD() or ATF_TC_WITH_CLEANUP() as needed. */
a1a15031 32ATF_TC(simple_test_case);
db81cc0c
TM
33
34
a1a15031
TM
35ATF_TC_HEAD(simple_test_case, tc)
36{
37 atf_tc_set_md_var(tc, "descr", "This test case is a simple DHCP test.");
38}
39ATF_TC_BODY(simple_test_case, tc)
40{
db81cc0c
TM
41 int condition = 1;
42 int this_is_linux = 1;
43 /* Failing condition will fail the test, but the code
44 itself will continue */
45 ATF_CHECK( 2 > 1 );
a1a15031 46
db81cc0c
TM
47 /* assert style check. Test will abort if the condition is not met. */
48 ATF_REQUIRE( 5 > 4 );
49
50 ATF_CHECK_EQ(4, 2 + 2); /* Non-fatal test. */
51 ATF_REQUIRE_EQ(4, 2 + 2); /* Fatal test. */
52
53 /* tests can also explicitly report test result */
54 if (!condition) {
55 atf_tc_fail("Condition not met!"); /* Explicit failure. */
56 }
57
58 if (!this_is_linux) {
59 atf_tc_skip("Skipping test. This Linux-only test.");
60 }
61
9f89d01e 62 if (condition && this_is_linux) {
db81cc0c
TM
63 /* no extra comments for pass needed. It just passed. */
64 atf_tc_pass();
65 }
a1a15031 66
a1a15031
TM
67}
68
db81cc0c
TM
69/* This macro defines main() method that will call specified
70 test cases. tp and simple_test_case names can be whatever you want
71 as long as it is a valid variable identifier. */
a1a15031
TM
72ATF_TP_ADD_TCS(tp)
73{
74 ATF_TP_ADD_TC(tp, simple_test_case);
75
76 return (atf_no_error());
77}