summaryrefslogtreecommitdiffstats
path: root/base/environment_unittest.cc
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 03:00:50 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-03 03:00:50 +0000
commit76b90d310def447b7b5f10d92a69813308150778 (patch)
tree24c61fdccf94360913bfa8f7ac67c24a27bcfb38 /base/environment_unittest.cc
parent7f2a9dbe56bfa6189271af808c53ccaee193a961 (diff)
downloadchromium_src-76b90d310def447b7b5f10d92a69813308150778.zip
chromium_src-76b90d310def447b7b5f10d92a69813308150778.tar.gz
chromium_src-76b90d310def447b7b5f10d92a69813308150778.tar.bz2
base: Rename EnvVarGetter to Environment.
Now EnvVarGetter do much more than getting environment variables. Per suggestion from Pawel in http://codereview.chromium.org/3043018/. BUG=None TEST=trybots Signed-off-by: Thiago Farina <tfarina@chromium.org> Review URL: http://codereview.chromium.org/3052034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54696 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/environment_unittest.cc')
-rw-r--r--base/environment_unittest.cc57
1 files changed, 57 insertions, 0 deletions
diff --git a/base/environment_unittest.cc b/base/environment_unittest.cc
new file mode 100644
index 0000000..5b4ddc3
--- /dev/null
+++ b/base/environment_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/environment.h"
+#include "base/scoped_ptr.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+typedef PlatformTest EnvironmentTest;
+
+TEST_F(EnvironmentTest, GetEnvVar) {
+ // Every setup should have non-empty PATH...
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ std::string env_value;
+ EXPECT_TRUE(env->GetEnv("PATH", &env_value));
+ EXPECT_NE(env_value, "");
+}
+
+TEST_F(EnvironmentTest, HasEnvVar) {
+ // Every setup should have PATH...
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+ EXPECT_TRUE(env->HasEnv("PATH"));
+}
+
+TEST_F(EnvironmentTest, SetEnvVar) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+
+ const char kFooUpper[] = "FOO";
+ const char kFooLower[] = "foo";
+ EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower));
+
+ // Now verify that the environment has the new variable.
+ EXPECT_TRUE(env->HasEnv(kFooUpper));
+
+ std::string var_value;
+ EXPECT_TRUE(env->GetEnv(kFooUpper, &var_value));
+ EXPECT_EQ(var_value, kFooLower);
+}
+
+TEST_F(EnvironmentTest, UnSetEnvVar) {
+ scoped_ptr<base::Environment> env(base::Environment::Create());
+
+ const char kFooUpper[] = "FOO";
+ const char kFooLower[] = "foo";
+ // First set some environment variable.
+ EXPECT_TRUE(env->SetEnv(kFooUpper, kFooLower));
+
+ // Now verify that the environment has the new variable.
+ EXPECT_TRUE(env->HasEnv(kFooUpper));
+
+ // Finally verify that the environment variable was erased.
+ EXPECT_TRUE(env->UnSetEnv(kFooUpper));
+
+ // And check that the variable has been unset.
+ EXPECT_FALSE(env->HasEnv(kFooUpper));
+}