Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1697)

Side by Side Diff: base/env_var_unittest.cc

Issue 3043018: base: Add UnSetEnv function to EnvVarGetter API. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/env_var.h" 5 #include "base/env_var.h"
6 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/platform_test.h" 8 #include "testing/platform_test.h"
9 9
10 typedef PlatformTest EnvVarTest; 10 typedef PlatformTest EnvVarTest;
11 11
12 TEST_F(EnvVarTest, GetEnvVar) { 12 TEST_F(EnvVarTest, GetEnvVar) {
13 // Every setup should have non-empty PATH... 13 // Every setup should have non-empty PATH...
14 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); 14 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
15 std::string env_value; 15 std::string env_value;
16 EXPECT_TRUE(env->GetEnv("PATH", &env_value)); 16 EXPECT_TRUE(env->GetEnv("PATH", &env_value));
17 EXPECT_NE(env_value, ""); 17 EXPECT_NE(env_value, "");
18 } 18 }
19 19
20 TEST_F(EnvVarTest, HasEnvVar) { 20 TEST_F(EnvVarTest, HasEnvVar) {
21 // Every setup should have PATH... 21 // Every setup should have PATH...
22 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); 22 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
23 EXPECT_TRUE(env->HasEnv("PATH")); 23 EXPECT_TRUE(env->HasEnv("PATH"));
24 } 24 }
25 25
26 TEST_F(EnvVarTest, SetEnvVar) { 26 TEST_F(EnvVarTest, SetEnvVar) {
27 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
28
27 const char kFooUpper[] = "FOO"; 29 const char kFooUpper[] = "FOO";
28 const char kFooLower[] = "foo"; 30 const char kFooLower[] = "foo";
29 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
30 EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower)); 31 EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower));
31 32
32 // Now verify that the environment has the new variable. 33 // Now verify that the environment has the new variable.
33 EXPECT_TRUE(env->HasEnv(kFooUpper)); 34 EXPECT_TRUE(env->HasEnv(kFooUpper));
34 35
35 std::string var_value; 36 std::string var_value;
36 EXPECT_TRUE(env->GetEnv(kFooUpper, &var_value)); 37 EXPECT_TRUE(env->GetEnv(kFooUpper, &var_value));
37 EXPECT_EQ(var_value, kFooLower); 38 EXPECT_EQ(var_value, kFooLower);
38 } 39 }
40
41 TEST_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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698