env_test.cpp revision 240116
155682Smarkm// 255682Smarkm// Automated Testing Framework (atf) 3178825Sdfr// 455682Smarkm// Copyright (c) 2007 The NetBSD Foundation, Inc. 555682Smarkm// All rights reserved. 655682Smarkm// 755682Smarkm// Redistribution and use in source and binary forms, with or without 855682Smarkm// modification, are permitted provided that the following conditions 955682Smarkm// are met: 1055682Smarkm// 1. Redistributions of source code must retain the above copyright 1155682Smarkm// notice, this list of conditions and the following disclaimer. 1255682Smarkm// 2. Redistributions in binary form must reproduce the above copyright 1355682Smarkm// notice, this list of conditions and the following disclaimer in the 1455682Smarkm// documentation and/or other materials provided with the distribution. 1555682Smarkm// 1655682Smarkm// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND 1755682Smarkm// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 1855682Smarkm// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1955682Smarkm// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2055682Smarkm// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY 2155682Smarkm// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2255682Smarkm// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 2355682Smarkm// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2455682Smarkm// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 2555682Smarkm// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 2655682Smarkm// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2755682Smarkm// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2855682Smarkm// 2955682Smarkm 3055682Smarkm#include "../macros.hpp" 3155682Smarkm 3255682Smarkm#include "env.hpp" 3355682Smarkm 3455682Smarkm// ------------------------------------------------------------------------ 35178825Sdfr// Test cases for the free functions. 3655682Smarkm// ------------------------------------------------------------------------ 3755682Smarkm 3855682SmarkmATF_TEST_CASE(has_get); 3955682SmarkmATF_TEST_CASE_HEAD(has_get) 40178825Sdfr{ 41178825Sdfr set_md_var("descr", "Tests the has and get functions"); 42178825Sdfr} 4355682SmarkmATF_TEST_CASE_BODY(has_get) 4455682Smarkm{ 4572445Sassar ATF_REQUIRE(atf::env::has("PATH")); 4672445Sassar ATF_REQUIRE(!atf::env::get("PATH").empty()); 4772445Sassar 4872445Sassar ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_")); 4972445Sassar} 5055682Smarkm 5155682SmarkmATF_TEST_CASE(set); 5255682SmarkmATF_TEST_CASE_HEAD(set) 5378527Sassar{ 5478527Sassar set_md_var("descr", "Tests the set function"); 5578527Sassar} 5655682SmarkmATF_TEST_CASE_BODY(set) 5755682Smarkm{ 5855682Smarkm ATF_REQUIRE(atf::env::has("PATH")); 5978527Sassar const std::string& oldval = atf::env::get("PATH"); 6078527Sassar atf::env::set("PATH", "foo-bar"); 6178527Sassar ATF_REQUIRE(atf::env::get("PATH") != oldval); 6278527Sassar ATF_REQUIRE_EQ(atf::env::get("PATH"), "foo-bar"); 6378527Sassar 6478527Sassar ATF_REQUIRE(!atf::env::has("_UNDEFINED_VARIABLE_")); 6578527Sassar atf::env::set("_UNDEFINED_VARIABLE_", "foo2-bar2"); 6678527Sassar ATF_REQUIRE_EQ(atf::env::get("_UNDEFINED_VARIABLE_"), "foo2-bar2"); 6778527Sassar} 6855682Smarkm 6955682SmarkmATF_TEST_CASE(unset); 7055682SmarkmATF_TEST_CASE_HEAD(unset) 7155682Smarkm{ 7255682Smarkm set_md_var("descr", "Tests the unset function"); 7355682Smarkm} 7455682SmarkmATF_TEST_CASE_BODY(unset) 7555682Smarkm{ 7655682Smarkm ATF_REQUIRE(atf::env::has("PATH")); 7755682Smarkm atf::env::unset("PATH"); 7855682Smarkm ATF_REQUIRE(!atf::env::has("PATH")); 7955682Smarkm} 8055682Smarkm 8155682Smarkm// ------------------------------------------------------------------------ 8255682Smarkm// Main. 8355682Smarkm// ------------------------------------------------------------------------ 8455682Smarkm 8555682SmarkmATF_INIT_TEST_CASES(tcs) 8655682Smarkm{ 8755682Smarkm // Add the test cases for the free functions. 8855682Smarkm ATF_ADD_TEST_CASE(tcs, has_get); 8955682Smarkm ATF_ADD_TEST_CASE(tcs, set); 9055682Smarkm ATF_ADD_TEST_CASE(tcs, unset); 9155682Smarkm} 9255682Smarkm