blob: f05a9b4d96113a2083705cd68e21fd8514445a08 [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
5#include "base/env_var.h"
6#include "base/scoped_ptr.h"
7#include "testing/gtest/include/gtest/gtest.h"
8#include "testing/platform_test.h"
9
10typedef PlatformTest EnvVarTest;
11
12TEST_F(EnvVarTest, GetEnvVar) {
13 // Every setup should have non-empty PATH...
14 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
15 std::string env_value;
16 EXPECT_TRUE(env->GetEnv("PATH", &env_value));
17 EXPECT_NE(env_value, "");
18}
19
20TEST_F(EnvVarTest, HasEnvVar) {
21 // Every setup should have PATH...
22 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
23 EXPECT_TRUE(env->HasEnv("PATH"));
24}
[email protected]9c55d6c2010-07-09 23:31:2125
26TEST_F(EnvVarTest, SetEnvVar) {
[email protected]fc586c72010-07-31 16:55:4027 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
28
[email protected]9c55d6c2010-07-09 23:31:2129 const char kFooUpper[] = "FOO";
30 const char kFooLower[] = "foo";
[email protected]e9032c62010-07-16 03:34:2531 EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower));
[email protected]9c55d6c2010-07-09 23:31:2132
33 // Now verify that the environment has the new variable.
34 EXPECT_TRUE(env->HasEnv(kFooUpper));
35
36 std::string var_value;
37 EXPECT_TRUE(env->GetEnv(kFooUpper, &var_value));
38 EXPECT_EQ(var_value, kFooLower);
39}
[email protected]fc586c72010-07-31 16:55:4040
41TEST_F(EnvVarTest, UnSetEnvVar) {
42 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
43
44 const char kFooUpper[] = "FOO";
45 const char kFooLower[] = "foo";
46 // First set some environment variable.
47 EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower));
48
49 // Now verify that the environment has the new variable.
50 EXPECT_TRUE(env->HasEnv(kFooUpper));
51
52 // Finally verify that the environment variable was erased.
53 EXPECT_TRUE(env->UnSetEnv(kFooUpper));
54
55 // And check that the variable has been unset.
56 EXPECT_FALSE(env->HasEnv(kFooUpper));
57}