Remove building with NOCRYPTO option
[minix.git] / external / bsd / atf / dist / atf-c / config_test.c
blobaed181438b59a1632abfc805e59c5c0c4c24a34f
1 /*
2 * Automated Testing Framework (atf)
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
30 #include <stdio.h>
31 #include <string.h>
33 #include <atf-c.h>
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 {
43 const char *lc;
44 const char *uc;
45 bool can_be_empty;
46 } all_vars[] = {
47 { "atf_build_cc", "ATF_BUILD_CC", false },
48 { "atf_build_cflags", "ATF_BUILD_CFLAGS", true },
49 { "atf_build_cpp", "ATF_BUILD_CPP", false },
50 { "atf_build_cppflags", "ATF_BUILD_CPPFLAGS", true },
51 { "atf_build_cxx", "ATF_BUILD_CXX", false },
52 { "atf_build_cxxflags", "ATF_BUILD_CXXFLAGS", true },
53 { "atf_includedir", "ATF_INCLUDEDIR", false },
54 { "atf_libexecdir", "ATF_LIBEXECDIR", false },
55 { "atf_pkgdatadir", "ATF_PKGDATADIR", false },
56 { "atf_shell", "ATF_SHELL", false },
57 { "atf_workdir", "ATF_WORKDIR", false },
58 { NULL, NULL, false }
61 /* ---------------------------------------------------------------------
62 * Auxiliary functions.
63 * --------------------------------------------------------------------- */
65 void __atf_config_reinit(void);
67 static
68 void
69 unset_all(void)
71 const struct varnames *v;
72 for (v = all_vars; v->lc != NULL; v++)
73 RE(atf_env_unset(v->uc));
76 static
77 void
78 compare_one(const char *var, const char *expvalue)
80 const struct varnames *v;
82 printf("Checking that %s is set to %s\n", var, expvalue);
84 for (v = all_vars; v->lc != NULL; v++) {
85 if (strcmp(v->lc, var) == 0)
86 ATF_CHECK_STREQ(atf_config_get(v->lc), test_value);
87 else
88 ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0);
92 /* ---------------------------------------------------------------------
93 * Test cases for the free functions.
94 * --------------------------------------------------------------------- */
96 ATF_TC(get);
97 ATF_TC_HEAD(get, tc)
99 atf_tc_set_md_var(tc, "descr", "Tests the atf_config_get function");
101 ATF_TC_BODY(get, tc)
103 const struct varnames *v;
105 /* Unset all known environment variables and make sure the built-in
106 * values do not match the bogus value we will use for testing. */
107 unset_all();
108 __atf_config_reinit();
109 for (v = all_vars; v->lc != NULL; v++)
110 ATF_CHECK(strcmp(atf_config_get(v->lc), test_value) != 0);
112 /* Test the behavior of empty values. */
113 for (v = all_vars; v->lc != NULL; v++) {
114 unset_all();
115 if (strcmp(atf_config_get(v->lc), "") != 0) {
116 RE(atf_env_set(v->uc, ""));
117 __atf_config_reinit();
118 if (v->can_be_empty)
119 ATF_CHECK(strlen(atf_config_get(v->lc)) == 0);
120 else
121 ATF_CHECK(strlen(atf_config_get(v->lc)) > 0);
125 /* Check if every variable is recognized individually. */
126 for (v = all_vars; v->lc != NULL; v++) {
127 unset_all();
128 RE(atf_env_set(v->uc, test_value));
129 __atf_config_reinit();
130 compare_one(v->lc, test_value);
134 /* ---------------------------------------------------------------------
135 * Tests cases for the header file.
136 * --------------------------------------------------------------------- */
138 HEADER_TC(include, "atf-c/config.h");
140 /* ---------------------------------------------------------------------
141 * Main.
142 * --------------------------------------------------------------------- */
144 ATF_TP_ADD_TCS(tp)
146 ATF_TP_ADD_TC(tp, get);
148 /* Add the test cases for the header file. */
149 ATF_TP_ADD_TC(tp, include);
151 return atf_no_error();