OLD | NEW |
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/environment.h" | 5 #include "base/environment.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 EnvironmentTest; | 10 typedef PlatformTest EnvironmentTest; |
11 | 11 |
12 TEST_F(EnvironmentTest, GetVar) { | 12 TEST_F(EnvironmentTest, GetVar) { |
13 // Every setup should have non-empty PATH... | 13 // Every setup should have non-empty PATH... |
14 scoped_ptr<base::Environment> env(base::Environment::Create()); | 14 scoped_ptr<base::Environment> env(base::Environment::Create()); |
15 std::string env_value; | 15 std::string env_value; |
16 EXPECT_TRUE(env->GetVar("PATH", &env_value)); | 16 EXPECT_TRUE(env->GetVar("PATH", &env_value)); |
17 EXPECT_NE(env_value, ""); | 17 EXPECT_NE(env_value, ""); |
18 } | 18 } |
19 | 19 |
| 20 TEST_F(EnvironmentTest, GetVarReverse) { |
| 21 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 22 const char* kFooUpper = "FOO"; |
| 23 const char* kFooLower = "foo"; |
| 24 |
| 25 // Set a variable in UPPER case. |
| 26 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower)); |
| 27 |
| 28 // And then try to get this variable passing the lower case. |
| 29 std::string env_value; |
| 30 EXPECT_TRUE(env->GetVar(kFooLower, &env_value)); |
| 31 |
| 32 EXPECT_STREQ(env_value.c_str(), kFooLower); |
| 33 |
| 34 EXPECT_TRUE(env->UnSetVar(kFooUpper)); |
| 35 |
| 36 const char* kBar = "bar"; |
| 37 // Now do the opposite, set the variable in the lower case. |
| 38 EXPECT_TRUE(env->SetVar(kFooLower, kBar)); |
| 39 |
| 40 // And then try to get this variable passing the UPPER case. |
| 41 EXPECT_TRUE(env->GetVar(kFooUpper, &env_value)); |
| 42 |
| 43 EXPECT_STREQ(env_value.c_str(), kBar); |
| 44 |
| 45 EXPECT_TRUE(env->UnSetVar(kFooLower)); |
| 46 } |
| 47 |
20 TEST_F(EnvironmentTest, HasVar) { | 48 TEST_F(EnvironmentTest, HasVar) { |
21 // Every setup should have PATH... | 49 // Every setup should have PATH... |
22 scoped_ptr<base::Environment> env(base::Environment::Create()); | 50 scoped_ptr<base::Environment> env(base::Environment::Create()); |
23 EXPECT_TRUE(env->HasVar("PATH")); | 51 EXPECT_TRUE(env->HasVar("PATH")); |
24 } | 52 } |
25 | 53 |
26 TEST_F(EnvironmentTest, SetVar) { | 54 TEST_F(EnvironmentTest, SetVar) { |
27 scoped_ptr<base::Environment> env(base::Environment::Create()); | 55 scoped_ptr<base::Environment> env(base::Environment::Create()); |
28 | 56 |
29 const char* kFooUpper = "FOO"; | 57 const char* kFooUpper = "FOO"; |
(...skipping 18 matching lines...) Expand all Loading... |
48 | 76 |
49 // Now verify that the environment has the new variable. | 77 // Now verify that the environment has the new variable. |
50 EXPECT_TRUE(env->HasVar(kFooUpper)); | 78 EXPECT_TRUE(env->HasVar(kFooUpper)); |
51 | 79 |
52 // Finally verify that the environment variable was erased. | 80 // Finally verify that the environment variable was erased. |
53 EXPECT_TRUE(env->UnSetVar(kFooUpper)); | 81 EXPECT_TRUE(env->UnSetVar(kFooUpper)); |
54 | 82 |
55 // And check that the variable has been unset. | 83 // And check that the variable has been unset. |
56 EXPECT_FALSE(env->HasVar(kFooUpper)); | 84 EXPECT_FALSE(env->HasVar(kFooUpper)); |
57 } | 85 } |
OLD | NEW |