1//
2// Automated Testing Framework (atf)
3//
4// Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
5// All rights reserved.
6//
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.
15//
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.
28//
29
30#include "../macros.hpp"
31
32#include "env.hpp"
33
34// ------------------------------------------------------------------------
35// Test cases for the free functions.
36// ------------------------------------------------------------------------
37
38ATF_TEST_CASE(has_get);
39ATF_TEST_CASE_HEAD(has_get)
40{
41    set_md_var("descr", "Tests the has and get functions");
42}
43ATF_TEST_CASE_BODY(has_get)
44{
45    ATF_REQUIRE(atf::env::has("PATH"));
46    ATF_REQUIRE(!atf::env::get("PATH").empty());
47
48    ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_"));
49}
50
51ATF_TEST_CASE(set);
52ATF_TEST_CASE_HEAD(set)
53{
54    set_md_var("descr", "Tests the set function");
55}
56ATF_TEST_CASE_BODY(set)
57{
58    ATF_REQUIRE(atf::env::has("PATH"));
59    const std::string& oldval = atf::env::get("PATH");
60    atf::env::set("PATH", "foo-bar");
61    ATF_REQUIRE(atf::env::get("PATH") != oldval);
62    ATF_REQUIRE_EQ(atf::env::get("PATH"), "foo-bar");
63
64    ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_"));
65    atf::env::set("_UNDEFINED_VARIABLE_", "foo2-bar2");
66    ATF_REQUIRE_EQ(atf::env::get("_UNDEFINED_VARIABLE_"), "foo2-bar2");
67}
68
69ATF_TEST_CASE(unset);
70ATF_TEST_CASE_HEAD(unset)
71{
72    set_md_var("descr", "Tests the unset function");
73}
74ATF_TEST_CASE_BODY(unset)
75{
76    ATF_REQUIRE(atf::env::has("PATH"));
77    atf::env::unset("PATH");
78    ATF_REQUIRE(!atf::env::has("PATH"));
79}
80
81// ------------------------------------------------------------------------
82// Main.
83// ------------------------------------------------------------------------
84
85ATF_INIT_TEST_CASES(tcs)
86{
87    // Add the test cases for the free functions.
88    ATF_ADD_TEST_CASE(tcs, has_get);
89    ATF_ADD_TEST_CASE(tcs, set);
90    ATF_ADD_TEST_CASE(tcs, unset);
91}
92