env_test.cpp revision 256281
1177633Sdfr// 2177633Sdfr// Automated Testing Framework (atf) 3261046Smav// 4261046Smav// Copyright (c) 2007 The NetBSD Foundation, Inc. 5261046Smav// All rights reserved. 6261046Smav// 7261046Smav// Redistribution and use in source and binary forms, with or without 8261046Smav// modification, are permitted provided that the following conditions 9261046Smav// are met: 10261046Smav// 1. Redistributions of source code must retain the above copyright 11261046Smav// notice, this list of conditions and the following disclaimer. 12261046Smav// 2. Redistributions in binary form must reproduce the above copyright 13261046Smav// notice, this list of conditions and the following disclaimer in the 14261046Smav// documentation and/or other materials provided with the distribution. 15261046Smav// 16261046Smav// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 17177633Sdfr// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 18261046Smav// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19261046Smav// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20261046Smav// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 21261046Smav// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22261046Smav// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 23261046Smav// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24261046Smav// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 25261046Smav// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 26261046Smav// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27261046Smav// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28261046Smav// 29177633Sdfr 30177633Sdfr#include "../macros.hpp" 31177633Sdfr 32177633Sdfr#include "env.hpp" 33177633Sdfr 34177633Sdfr// ------------------------------------------------------------------------ 35177633Sdfr// Test cases for the free functions. 36177633Sdfr// ------------------------------------------------------------------------ 37177633Sdfr 38177633SdfrATF_TEST_CASE(has_get); 39177633SdfrATF_TEST_CASE_HEAD(has_get) 40177633Sdfr{ 41177633Sdfr set_md_var("descr", "Tests the has and get functions"); 42177633Sdfr} 43177633SdfrATF_TEST_CASE_BODY(has_get) 44177633Sdfr{ 45177633Sdfr ATF_REQUIRE(atf::env::has("PATH")); 46177662Sdfr ATF_REQUIRE(!atf::env::get("PATH").empty()); 47177633Sdfr 48184588Sdfr ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_")); 49177662Sdfr} 50177633Sdfr 51177633SdfrATF_TEST_CASE(set); 52177633SdfrATF_TEST_CASE_HEAD(set) 53177633Sdfr{ 54177633Sdfr set_md_var("descr", "Tests the set function"); 55177633Sdfr} 56177633SdfrATF_TEST_CASE_BODY(set) 57177633Sdfr{ 58196503Szec ATF_REQUIRE(atf::env::has("PATH")); 59196503Szec const std::string& oldval = atf::env::get("PATH"); 60177633Sdfr atf::env::set("PATH", "foo-bar"); 61177633Sdfr ATF_REQUIRE(atf::env::get("PATH") != oldval); 62223309Srmacklem ATF_REQUIRE_EQ(atf::env::get("PATH"), "foo-bar"); 63177633Sdfr 64177685Sdfr ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_")); 65177633Sdfr atf::env::set("_UNDEFINED_VARIABLE_", "foo2-bar2"); 66213756Srmacklem ATF_REQUIRE_EQ(atf::env::get("_UNDEFINED_VARIABLE_"), "foo2-bar2"); 67213756Srmacklem} 68177685Sdfr 69177685SdfrATF_TEST_CASE(unset); 70177685SdfrATF_TEST_CASE_HEAD(unset) 71177685Sdfr{ 72223309Srmacklem set_md_var("descr", "Tests the unset function"); 73223309Srmacklem} 74223309SrmacklemATF_TEST_CASE_BODY(unset) 75177633Sdfr{ 76177633Sdfr ATF_REQUIRE(atf::env::has("PATH")); 77177633Sdfr atf::env::unset("PATH"); 78177633Sdfr ATF_REQUIRE(!atf::env::has("PATH")); 79177633Sdfr} 80177633Sdfr 81177633Sdfr// ------------------------------------------------------------------------ 82177633Sdfr// Main. 83177633Sdfr// ------------------------------------------------------------------------ 84177633Sdfr 85177633SdfrATF_INIT_TEST_CASES(tcs) 86177633Sdfr{ 87177633Sdfr // Add the test cases for the free functions. 88177633Sdfr ATF_ADD_TEST_CASE(tcs, has_get); 89177633Sdfr ATF_ADD_TEST_CASE(tcs, set); 90177633Sdfr ATF_ADD_TEST_CASE(tcs, unset); 91177633Sdfr} 92177633Sdfr