1273929Sjmmv/* Copyright (c) 2008 The NetBSD Foundation, Inc.
2240116Smarcel * All rights reserved.
3240116Smarcel *
4240116Smarcel * Redistribution and use in source and binary forms, with or without
5240116Smarcel * modification, are permitted provided that the following conditions
6240116Smarcel * are met:
7240116Smarcel * 1. Redistributions of source code must retain the above copyright
8240116Smarcel *    notice, this list of conditions and the following disclaimer.
9240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel *    notice, this list of conditions and the following disclaimer in the
11240116Smarcel *    documentation and/or other materials provided with the distribution.
12240116Smarcel *
13240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24273929Sjmmv * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25240116Smarcel
26273929Sjmmv#include "atf-c/tc.h"
27273929Sjmmv
28240116Smarcel#include <stdbool.h>
29240116Smarcel#include <string.h>
30240116Smarcel
31240116Smarcel#include <atf-c.h>
32240116Smarcel
33273929Sjmmv#include "atf-c/detail/test_helpers.h"
34240116Smarcel
35240116Smarcel/* ---------------------------------------------------------------------
36240116Smarcel * Auxiliary test cases.
37240116Smarcel * --------------------------------------------------------------------- */
38240116Smarcel
39240116SmarcelATF_TC_HEAD(empty, tc)
40240116Smarcel{
41240116Smarcel    if (tc != NULL) {}
42240116Smarcel}
43240116SmarcelATF_TC_BODY(empty, tc)
44240116Smarcel{
45240116Smarcel}
46240116Smarcel
47240116SmarcelATF_TC_HEAD(test_var, tc)
48240116Smarcel{
49240116Smarcel    atf_tc_set_md_var(tc, "test-var", "Test text");
50240116Smarcel}
51240116Smarcel
52240116Smarcel/* ---------------------------------------------------------------------
53240116Smarcel * Test cases for the "atf_tc_t" type.
54240116Smarcel * --------------------------------------------------------------------- */
55240116Smarcel
56240116SmarcelATF_TC(init);
57240116SmarcelATF_TC_HEAD(init, tc)
58240116Smarcel{
59240116Smarcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init function");
60240116Smarcel}
61240116SmarcelATF_TC_BODY(init, tcin)
62240116Smarcel{
63240116Smarcel    atf_tc_t tc;
64240116Smarcel
65240116Smarcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
66240116Smarcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
67240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
68240116Smarcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
69240116Smarcel    atf_tc_fini(&tc);
70240116Smarcel
71240116Smarcel    RE(atf_tc_init(&tc, "test2", ATF_TC_HEAD_NAME(test_var),
72240116Smarcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
73240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
74240116Smarcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
75240116Smarcel    atf_tc_fini(&tc);
76240116Smarcel}
77240116Smarcel
78240116SmarcelATF_TC(init_pack);
79240116SmarcelATF_TC_HEAD(init_pack, tc)
80240116Smarcel{
81240116Smarcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init_pack function");
82240116Smarcel}
83240116SmarcelATF_TC_BODY(init_pack, tcin)
84240116Smarcel{
85240116Smarcel    atf_tc_t tc;
86240116Smarcel    atf_tc_pack_t tcp1 = {
87240116Smarcel        .m_ident = "test1",
88240116Smarcel        .m_head = ATF_TC_HEAD_NAME(empty),
89240116Smarcel        .m_body = ATF_TC_BODY_NAME(empty),
90240116Smarcel        .m_cleanup = NULL,
91240116Smarcel    };
92240116Smarcel    atf_tc_pack_t tcp2 = {
93240116Smarcel        .m_ident = "test2",
94240116Smarcel        .m_head = ATF_TC_HEAD_NAME(test_var),
95240116Smarcel        .m_body = ATF_TC_BODY_NAME(empty),
96240116Smarcel        .m_cleanup = NULL,
97240116Smarcel    };
98240116Smarcel
99240116Smarcel    RE(atf_tc_init_pack(&tc, &tcp1, NULL));
100240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
101240116Smarcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
102240116Smarcel    atf_tc_fini(&tc);
103240116Smarcel
104240116Smarcel    RE(atf_tc_init_pack(&tc, &tcp2, NULL));
105240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
106240116Smarcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
107240116Smarcel    atf_tc_fini(&tc);
108240116Smarcel}
109240116Smarcel
110240116SmarcelATF_TC(vars);
111240116SmarcelATF_TC_HEAD(vars, tc)
112240116Smarcel{
113240116Smarcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_md_var, "
114240116Smarcel                      "atf_tc_has_md_var and atf_tc_set_md_var functions");
115240116Smarcel}
116240116SmarcelATF_TC_BODY(vars, tcin)
117240116Smarcel{
118240116Smarcel    atf_tc_t tc;
119240116Smarcel
120240116Smarcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
121240116Smarcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
122240116Smarcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
123240116Smarcel    RE(atf_tc_set_md_var(&tc, "test-var", "Test value"));
124240116Smarcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
125240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_md_var(&tc, "test-var"), "Test value") == 0);
126240116Smarcel    atf_tc_fini(&tc);
127240116Smarcel}
128240116Smarcel
129240116SmarcelATF_TC(config);
130240116SmarcelATF_TC_HEAD(config, tc)
131240116Smarcel{
132240116Smarcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_config_var, "
133240116Smarcel                      "atf_tc_get_config_var_wd and atf_tc_has_config_var "
134240116Smarcel                      "functions");
135240116Smarcel}
136240116SmarcelATF_TC_BODY(config, tcin)
137240116Smarcel{
138240116Smarcel    atf_tc_t tc;
139240116Smarcel    const char *const config[] = { "test-var", "test-value", NULL };
140240116Smarcel
141240116Smarcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
142240116Smarcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
143240116Smarcel    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var"));
144240116Smarcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
145240116Smarcel    atf_tc_fini(&tc);
146240116Smarcel
147240116Smarcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
148240116Smarcel                   ATF_TC_BODY_NAME(empty), NULL, config));
149240116Smarcel    ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var"));
150240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"),
151240116Smarcel                     "test-value") == 0);
152240116Smarcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
153240116Smarcel    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2"));
154240116Smarcel    ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"),
155240116Smarcel                     "def-value") == 0);
156240116Smarcel    atf_tc_fini(&tc);
157240116Smarcel}
158240116Smarcel
159240116Smarcel/* ---------------------------------------------------------------------
160240116Smarcel * Test cases for the free functions.
161240116Smarcel * --------------------------------------------------------------------- */
162240116Smarcel
163240116Smarcel/* TODO: Add test cases for atf_tc_run.  This is going to be very tough,
164240116Smarcel * but good tests here could allow us to avoid much of the indirect
165240116Smarcel * testing done later on. */
166240116Smarcel
167240116Smarcel/* ---------------------------------------------------------------------
168240116Smarcel * Main.
169240116Smarcel * --------------------------------------------------------------------- */
170240116Smarcel
171240116SmarcelATF_TP_ADD_TCS(tp)
172240116Smarcel{
173240116Smarcel    /* Add the test cases for the "atf_tcr_t" type. */
174240116Smarcel    ATF_TP_ADD_TC(tp, init);
175240116Smarcel    ATF_TP_ADD_TC(tp, init_pack);
176240116Smarcel    ATF_TP_ADD_TC(tp, vars);
177240116Smarcel    ATF_TP_ADD_TC(tp, config);
178240116Smarcel
179240116Smarcel    /* Add the test cases for the free functions. */
180240116Smarcel    /* TODO */
181240116Smarcel
182240116Smarcel    return atf_no_error();
183240116Smarcel}
184