13b6cf63jmmv/* Copyright (c) 2008 The NetBSD Foundation, Inc.
245147a9marcel * All rights reserved.
345147a9marcel *
445147a9marcel * Redistribution and use in source and binary forms, with or without
545147a9marcel * modification, are permitted provided that the following conditions
645147a9marcel * are met:
745147a9marcel * 1. Redistributions of source code must retain the above copyright
845147a9marcel *    notice, this list of conditions and the following disclaimer.
945147a9marcel * 2. Redistributions in binary form must reproduce the above copyright
1045147a9marcel *    notice, this list of conditions and the following disclaimer in the
1145147a9marcel *    documentation and/or other materials provided with the distribution.
1245147a9marcel *
1345147a9marcel * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
1445147a9marcel * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
1545147a9marcel * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
1645147a9marcel * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1745147a9marcel * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
1845147a9marcel * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1945147a9marcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
2045147a9marcel * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2145147a9marcel * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
2245147a9marcel * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
2345147a9marcel * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
243b6cf63jmmv * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
253b6cf63jmmv
263b6cf63jmmv#include "atf-c/tc.h"
2745147a9marcel
2845147a9marcel#include <stdbool.h>
2945147a9marcel#include <string.h>
3045147a9marcel
3145147a9marcel#include <atf-c.h>
3245147a9marcel
333b6cf63jmmv#include "atf-c/detail/test_helpers.h"
3445147a9marcel
3545147a9marcel/* ---------------------------------------------------------------------
3645147a9marcel * Auxiliary test cases.
3745147a9marcel * --------------------------------------------------------------------- */
3845147a9marcel
3945147a9marcelATF_TC_HEAD(empty, tc)
4045147a9marcel{
4145147a9marcel    if (tc != NULL) {}
4245147a9marcel}
4345147a9marcelATF_TC_BODY(empty, tc)
4445147a9marcel{
4545147a9marcel}
4645147a9marcel
4745147a9marcelATF_TC_HEAD(test_var, tc)
4845147a9marcel{
4945147a9marcel    atf_tc_set_md_var(tc, "test-var", "Test text");
5045147a9marcel}
5145147a9marcel
5245147a9marcel/* ---------------------------------------------------------------------
5345147a9marcel * Test cases for the "atf_tc_t" type.
5445147a9marcel * --------------------------------------------------------------------- */
5545147a9marcel
5645147a9marcelATF_TC(init);
5745147a9marcelATF_TC_HEAD(init, tc)
5845147a9marcel{
5945147a9marcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init function");
6045147a9marcel}
6145147a9marcelATF_TC_BODY(init, tcin)
6245147a9marcel{
6345147a9marcel    atf_tc_t tc;
6445147a9marcel
6545147a9marcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
6645147a9marcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
6745147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
6845147a9marcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
6945147a9marcel    atf_tc_fini(&tc);
7045147a9marcel
7145147a9marcel    RE(atf_tc_init(&tc, "test2", ATF_TC_HEAD_NAME(test_var),
7245147a9marcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
7345147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
7445147a9marcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
7545147a9marcel    atf_tc_fini(&tc);
7645147a9marcel}
7745147a9marcel
7845147a9marcelATF_TC(init_pack);
7945147a9marcelATF_TC_HEAD(init_pack, tc)
8045147a9marcel{
8145147a9marcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_init_pack function");
8245147a9marcel}
8345147a9marcelATF_TC_BODY(init_pack, tcin)
8445147a9marcel{
8545147a9marcel    atf_tc_t tc;
8645147a9marcel    atf_tc_pack_t tcp1 = {
8745147a9marcel        .m_ident = "test1",
8845147a9marcel        .m_head = ATF_TC_HEAD_NAME(empty),
8945147a9marcel        .m_body = ATF_TC_BODY_NAME(empty),
9045147a9marcel        .m_cleanup = NULL,
9145147a9marcel    };
9245147a9marcel    atf_tc_pack_t tcp2 = {
9345147a9marcel        .m_ident = "test2",
9445147a9marcel        .m_head = ATF_TC_HEAD_NAME(test_var),
9545147a9marcel        .m_body = ATF_TC_BODY_NAME(empty),
9645147a9marcel        .m_cleanup = NULL,
9745147a9marcel    };
9845147a9marcel
9945147a9marcel    RE(atf_tc_init_pack(&tc, &tcp1, NULL));
10045147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test1") == 0);
10145147a9marcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
10245147a9marcel    atf_tc_fini(&tc);
10345147a9marcel
10445147a9marcel    RE(atf_tc_init_pack(&tc, &tcp2, NULL));
10545147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_ident(&tc), "test2") == 0);
10645147a9marcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
10745147a9marcel    atf_tc_fini(&tc);
10845147a9marcel}
10945147a9marcel
11045147a9marcelATF_TC(vars);
11145147a9marcelATF_TC_HEAD(vars, tc)
11245147a9marcel{
11345147a9marcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_md_var, "
11445147a9marcel                      "atf_tc_has_md_var and atf_tc_set_md_var functions");
11545147a9marcel}
11645147a9marcelATF_TC_BODY(vars, tcin)
11745147a9marcel{
11845147a9marcel    atf_tc_t tc;
11945147a9marcel
12045147a9marcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
12145147a9marcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
12245147a9marcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
12345147a9marcel    RE(atf_tc_set_md_var(&tc, "test-var", "Test value"));
12445147a9marcel    ATF_REQUIRE(atf_tc_has_md_var(&tc, "test-var"));
12545147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_md_var(&tc, "test-var"), "Test value") == 0);
12645147a9marcel    atf_tc_fini(&tc);
12745147a9marcel}
12845147a9marcel
12945147a9marcelATF_TC(config);
13045147a9marcelATF_TC_HEAD(config, tc)
13145147a9marcel{
13245147a9marcel    atf_tc_set_md_var(tc, "descr", "Tests the atf_tc_get_config_var, "
13345147a9marcel                      "atf_tc_get_config_var_wd and atf_tc_has_config_var "
13445147a9marcel                      "functions");
13545147a9marcel}
13645147a9marcelATF_TC_BODY(config, tcin)
13745147a9marcel{
13845147a9marcel    atf_tc_t tc;
13945147a9marcel    const char *const config[] = { "test-var", "test-value", NULL };
14045147a9marcel
14145147a9marcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
14245147a9marcel                   ATF_TC_BODY_NAME(empty), NULL, NULL));
14345147a9marcel    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var"));
14445147a9marcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
14545147a9marcel    atf_tc_fini(&tc);
14645147a9marcel
14745147a9marcel    RE(atf_tc_init(&tc, "test1", ATF_TC_HEAD_NAME(empty),
14845147a9marcel                   ATF_TC_BODY_NAME(empty), NULL, config));
14945147a9marcel    ATF_REQUIRE(atf_tc_has_config_var(&tc, "test-var"));
15045147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_config_var(&tc, "test-var"),
15145147a9marcel                     "test-value") == 0);
15245147a9marcel    ATF_REQUIRE(!atf_tc_has_md_var(&tc, "test-var"));
15345147a9marcel    ATF_REQUIRE(!atf_tc_has_config_var(&tc, "test-var2"));
15445147a9marcel    ATF_REQUIRE(strcmp(atf_tc_get_config_var_wd(&tc, "test-var2", "def-value"),
15545147a9marcel                     "def-value") == 0);
15645147a9marcel    atf_tc_fini(&tc);
15745147a9marcel}
15845147a9marcel
15945147a9marcel/* ---------------------------------------------------------------------
16045147a9marcel * Test cases for the free functions.
16145147a9marcel * --------------------------------------------------------------------- */
16245147a9marcel
16345147a9marcel/* TODO: Add test cases for atf_tc_run.  This is going to be very tough,
16445147a9marcel * but good tests here could allow us to avoid much of the indirect
16545147a9marcel * testing done later on. */
16645147a9marcel
16745147a9marcel/* ---------------------------------------------------------------------
16845147a9marcel * Main.
16945147a9marcel * --------------------------------------------------------------------- */
17045147a9marcel
17145147a9marcelATF_TP_ADD_TCS(tp)
17245147a9marcel{
17345147a9marcel    /* Add the test cases for the "atf_tcr_t" type. */
17445147a9marcel    ATF_TP_ADD_TC(tp, init);
17545147a9marcel    ATF_TP_ADD_TC(tp, init_pack);
17645147a9marcel    ATF_TP_ADD_TC(tp, vars);
17745147a9marcel    ATF_TP_ADD_TC(tp, config);
17845147a9marcel
17945147a9marcel    /* Add the test cases for the free functions. */
18045147a9marcel    /* TODO */
18145147a9marcel
18245147a9marcel    return atf_no_error();
18345147a9marcel}
184