Fix chrome.downloads.onDeterminingFilename
[chromium-blink-merge.git] / base / environment_unittest.cc
blobb6654c99f4ea29346c1798ab5001618f1bc0c55e
1 // Copyright (c) 2011 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.
5 #include "base/environment.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/platform_test.h"
10 typedef PlatformTest EnvironmentTest;
12 TEST_F(EnvironmentTest, GetVar) {
13 // Every setup should have non-empty PATH...
14 scoped_ptr<base::Environment> env(base::Environment::Create());
15 std::string env_value;
16 EXPECT_TRUE(env->GetVar("PATH", &env_value));
17 EXPECT_NE(env_value, "");
20 TEST_F(EnvironmentTest, GetVarReverse) {
21 scoped_ptr<base::Environment> env(base::Environment::Create());
22 const char* kFooUpper = "FOO";
23 const char* kFooLower = "foo";
25 // Set a variable in UPPER case.
26 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
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));
32 EXPECT_STREQ(env_value.c_str(), kFooLower);
34 EXPECT_TRUE(env->UnSetVar(kFooUpper));
36 const char* kBar = "bar";
37 // Now do the opposite, set the variable in the lower case.
38 EXPECT_TRUE(env->SetVar(kFooLower, kBar));
40 // And then try to get this variable passing the UPPER case.
41 EXPECT_TRUE(env->GetVar(kFooUpper, &env_value));
43 EXPECT_STREQ(env_value.c_str(), kBar);
45 EXPECT_TRUE(env->UnSetVar(kFooLower));
48 TEST_F(EnvironmentTest, HasVar) {
49 // Every setup should have PATH...
50 scoped_ptr<base::Environment> env(base::Environment::Create());
51 EXPECT_TRUE(env->HasVar("PATH"));
54 TEST_F(EnvironmentTest, SetVar) {
55 scoped_ptr<base::Environment> env(base::Environment::Create());
57 const char* kFooUpper = "FOO";
58 const char* kFooLower = "foo";
59 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
61 // Now verify that the environment has the new variable.
62 EXPECT_TRUE(env->HasVar(kFooUpper));
64 std::string var_value;
65 EXPECT_TRUE(env->GetVar(kFooUpper, &var_value));
66 EXPECT_EQ(var_value, kFooLower);
69 TEST_F(EnvironmentTest, UnSetVar) {
70 scoped_ptr<base::Environment> env(base::Environment::Create());
72 const char* kFooUpper = "FOO";
73 const char* kFooLower = "foo";
74 // First set some environment variable.
75 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
77 // Now verify that the environment has the new variable.
78 EXPECT_TRUE(env->HasVar(kFooUpper));
80 // Finally verify that the environment variable was erased.
81 EXPECT_TRUE(env->UnSetVar(kFooUpper));
83 // And check that the variable has been unset.
84 EXPECT_FALSE(env->HasVar(kFooUpper));