blob: 5081459ce9b47f053a2222d6cfbd98c1602f16ca [file] [log] [blame]
[email protected]8d80d2d62010-07-08 03:19:081// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]76b90d312010-08-03 03:00:505#include "base/environment.h"
[email protected]8d80d2d62010-07-08 03:19:086#include "base/scoped_ptr.h"
7#include "testing/gtest/include/gtest/gtest.h"
8#include "testing/platform_test.h"
9
[email protected]76b90d312010-08-03 03:00:5010typedef PlatformTest EnvironmentTest;
[email protected]8d80d2d62010-07-08 03:19:0811
[email protected]3ba7e082010-08-07 02:57:5912TEST_F(EnvironmentTest, GetVar) {
[email protected]8d80d2d62010-07-08 03:19:0813 // Every setup should have non-empty PATH...
[email protected]76b90d312010-08-03 03:00:5014 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]8d80d2d62010-07-08 03:19:0815 std::string env_value;
[email protected]3ba7e082010-08-07 02:57:5916 EXPECT_TRUE(env->GetVar("PATH", &env_value));
[email protected]8d80d2d62010-07-08 03:19:0817 EXPECT_NE(env_value, "");
18}
19
[email protected]9432ade2010-08-04 23:43:2020TEST_F(EnvironmentTest, HasVar) {
[email protected]8d80d2d62010-07-08 03:19:0821 // Every setup should have PATH...
[email protected]76b90d312010-08-03 03:00:5022 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]9432ade2010-08-04 23:43:2023 EXPECT_TRUE(env->HasVar("PATH"));
[email protected]8d80d2d62010-07-08 03:19:0824}
[email protected]9c55d6c2010-07-09 23:31:2125
[email protected]c87bcf002010-08-06 01:03:3726TEST_F(EnvironmentTest, SetVar) {
[email protected]76b90d312010-08-03 03:00:5027 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]fc586c72010-07-31 16:55:4028
[email protected]c3b3e062010-08-20 02:49:4929 const char* kFooUpper = "FOO";
30 const char* kFooLower = "foo";
[email protected]c87bcf002010-08-06 01:03:3731 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
[email protected]9c55d6c2010-07-09 23:31:2132
33 // Now verify that the environment has the new variable.
[email protected]9432ade2010-08-04 23:43:2034 EXPECT_TRUE(env->HasVar(kFooUpper));
[email protected]9c55d6c2010-07-09 23:31:2135
36 std::string var_value;
[email protected]3ba7e082010-08-07 02:57:5937 EXPECT_TRUE(env->GetVar(kFooUpper, &var_value));
[email protected]9c55d6c2010-07-09 23:31:2138 EXPECT_EQ(var_value, kFooLower);
39}
[email protected]fc586c72010-07-31 16:55:4040
[email protected]4fae3162010-08-04 02:13:3441TEST_F(EnvironmentTest, UnSetVar) {
[email protected]76b90d312010-08-03 03:00:5042 scoped_ptr<base::Environment> env(base::Environment::Create());
[email protected]fc586c72010-07-31 16:55:4043
[email protected]c3b3e062010-08-20 02:49:4944 const char* kFooUpper = "FOO";
45 const char* kFooLower = "foo";
[email protected]fc586c72010-07-31 16:55:4046 // First set some environment variable.
[email protected]c87bcf002010-08-06 01:03:3747 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
[email protected]fc586c72010-07-31 16:55:4048
49 // Now verify that the environment has the new variable.
[email protected]9432ade2010-08-04 23:43:2050 EXPECT_TRUE(env->HasVar(kFooUpper));
[email protected]fc586c72010-07-31 16:55:4051
52 // Finally verify that the environment variable was erased.
[email protected]4fae3162010-08-04 02:13:3453 EXPECT_TRUE(env->UnSetVar(kFooUpper));
[email protected]fc586c72010-07-31 16:55:4054
55 // And check that the variable has been unset.
[email protected]9432ade2010-08-04 23:43:2056 EXPECT_FALSE(env->HasVar(kFooUpper));
[email protected]fc586c72010-07-31 16:55:4057}