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