Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c / detail / env_test.c
blob6ebf36c8bbefe8e472a1fff587ee761b7e40e7f0
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 <stdlib.h>
31 #include <string.h>
33 #include <atf-c.h>
35 #include "env.h"
36 #include "test_helpers.h"
37 #include "text.h"
39 /* ---------------------------------------------------------------------
40 * Test cases for the free functions.
41 * --------------------------------------------------------------------- */
43 ATF_TC(has);
44 ATF_TC_HEAD(has, tc)
46 atf_tc_set_md_var(tc, "descr", "Tests the atf_env_has function");
48 ATF_TC_BODY(has, tc)
50 ATF_REQUIRE(atf_env_has("PATH"));
51 ATF_REQUIRE(!atf_env_has("_UNDEFINED_VARIABLE_"));
54 ATF_TC(get);
55 ATF_TC_HEAD(get, tc)
57 atf_tc_set_md_var(tc, "descr", "Tests the atf_env_get function");
59 ATF_TC_BODY(get, tc)
61 const char *val;
63 ATF_REQUIRE(atf_env_has("PATH"));
65 val = atf_env_get("PATH");
66 ATF_REQUIRE(strlen(val) > 0);
67 ATF_REQUIRE(strchr(val, ':') != NULL);
70 ATF_TC(set);
71 ATF_TC_HEAD(set, tc)
73 atf_tc_set_md_var(tc, "descr", "Tests the atf_env_set function");
75 ATF_TC_BODY(set, tc)
77 char *oldval;
79 ATF_REQUIRE(atf_env_has("PATH"));
80 RE(atf_text_format(&oldval, "%s", atf_env_get("PATH")));
81 RE(atf_env_set("PATH", "foo-bar"));
82 ATF_REQUIRE(strcmp(atf_env_get("PATH"), oldval) != 0);
83 ATF_REQUIRE(strcmp(atf_env_get("PATH"), "foo-bar") == 0);
84 free(oldval);
86 ATF_REQUIRE(!atf_env_has("_UNDEFINED_VARIABLE_"));
87 RE(atf_env_set("_UNDEFINED_VARIABLE_", "foo2-bar2"));
88 ATF_REQUIRE(strcmp(atf_env_get("_UNDEFINED_VARIABLE_"),
89 "foo2-bar2") == 0);
92 ATF_TC(unset);
93 ATF_TC_HEAD(unset, tc)
95 atf_tc_set_md_var(tc, "descr", "Tests the atf_env_unset function");
97 ATF_TC_BODY(unset, tc)
99 ATF_REQUIRE(atf_env_has("PATH"));
100 RE(atf_env_unset("PATH"));
101 ATF_REQUIRE(!atf_env_has("PATH"));
104 /* ---------------------------------------------------------------------
105 * Main.
106 * --------------------------------------------------------------------- */
108 ATF_TP_ADD_TCS(tp)
110 ATF_TP_ADD_TC(tp, has);
111 ATF_TP_ADD_TC(tp, get);
112 ATF_TP_ADD_TC(tp, set);
113 ATF_TP_ADD_TC(tp, unset);
115 return atf_no_error();