1 /* $NetBSD: config_test.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */
4 * Automated Testing Framework (atf)
6 * Copyright (c) 2007 The NetBSD Foundation, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 #include "atf-c/config.h"
39 #include "detail/env.h"
40 #include "detail/test_helpers.h"
42 static const char *test_value
= "env-value";
44 static struct varnames
{
49 { "atf_arch", "ATF_ARCH", false },
50 { "atf_build_cc", "ATF_BUILD_CC", false },
51 { "atf_build_cflags", "ATF_BUILD_CFLAGS", true },
52 { "atf_build_cpp", "ATF_BUILD_CPP", false },
53 { "atf_build_cppflags", "ATF_BUILD_CPPFLAGS", true },
54 { "atf_build_cxx", "ATF_BUILD_CXX", false },
55 { "atf_build_cxxflags", "ATF_BUILD_CXXFLAGS", true },
56 { "atf_confdir", "ATF_CONFDIR", false },
57 { "atf_includedir", "ATF_INCLUDEDIR", false },
58 { "atf_libdir", "ATF_LIBDIR", false },
59 { "atf_libexecdir", "ATF_LIBEXECDIR", false },
60 { "atf_machine", "ATF_MACHINE", false },
61 { "atf_pkgdatadir", "ATF_PKGDATADIR", false },
62 { "atf_shell", "ATF_SHELL", false },
63 { "atf_workdir", "ATF_WORKDIR", false },
67 /* ---------------------------------------------------------------------
68 * Auxiliary functions.
69 * --------------------------------------------------------------------- */
71 void __atf_config_reinit(void);
77 const struct varnames
*v
;
78 for (v
= all_vars
; v
->lc
!= NULL
; v
++)
79 RE(atf_env_unset(v
->uc
));
84 compare_one(const char *var
, const char *expvalue
)
86 const struct varnames
*v
;
88 printf("Checking that %s is set to %s\n", var
, expvalue
);
90 for (v
= all_vars
; v
->lc
!= NULL
; v
++) {
91 if (strcmp(v
->lc
, var
) == 0)
92 ATF_CHECK_STREQ(atf_config_get(v
->lc
), test_value
);
94 ATF_CHECK(strcmp(atf_config_get(v
->lc
), test_value
) != 0);
98 /* ---------------------------------------------------------------------
99 * Test cases for the free functions.
100 * --------------------------------------------------------------------- */
105 atf_tc_set_md_var(tc
, "descr", "Tests the atf_config_get function");
109 const struct varnames
*v
;
111 /* Unset all known environment variables and make sure the built-in
112 * values do not match the bogus value we will use for testing. */
114 __atf_config_reinit();
115 for (v
= all_vars
; v
->lc
!= NULL
; v
++)
116 ATF_CHECK(strcmp(atf_config_get(v
->lc
), test_value
) != 0);
118 /* Test the behavior of empty values. */
119 for (v
= all_vars
; v
->lc
!= NULL
; v
++) {
121 if (strcmp(atf_config_get(v
->lc
), "") != 0) {
122 RE(atf_env_set(v
->uc
, ""));
123 __atf_config_reinit();
125 ATF_CHECK(strlen(atf_config_get(v
->lc
)) == 0);
127 ATF_CHECK(strlen(atf_config_get(v
->lc
)) > 0);
131 /* Check if every variable is recognized individually. */
132 for (v
= all_vars
; v
->lc
!= NULL
; v
++) {
134 RE(atf_env_set(v
->uc
, test_value
));
135 __atf_config_reinit();
136 compare_one(v
->lc
, test_value
);
140 /* ---------------------------------------------------------------------
141 * Tests cases for the header file.
142 * --------------------------------------------------------------------- */
144 HEADER_TC(include
, "atf-c/config.h");
146 /* ---------------------------------------------------------------------
148 * --------------------------------------------------------------------- */
152 ATF_TP_ADD_TC(tp
, get
);
154 /* Add the test cases for the header file. */
155 ATF_TP_ADD_TC(tp
, include
);
157 return atf_no_error();