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

Side by Side Diff: base/environment_unittest.cc

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/environment.cc ('k') | base/feature_list.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/memory/scoped_ptr.h" 6
7 #include <memory>
8
7 #include "build/build_config.h" 9 #include "build/build_config.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 #include "testing/platform_test.h" 11 #include "testing/platform_test.h"
10 12
11 typedef PlatformTest EnvironmentTest; 13 typedef PlatformTest EnvironmentTest;
12 14
13 namespace base { 15 namespace base {
14 16
15 TEST_F(EnvironmentTest, GetVar) { 17 TEST_F(EnvironmentTest, GetVar) {
16 // Every setup should have non-empty PATH... 18 // Every setup should have non-empty PATH...
17 scoped_ptr<Environment> env(Environment::Create()); 19 std::unique_ptr<Environment> env(Environment::Create());
18 std::string env_value; 20 std::string env_value;
19 EXPECT_TRUE(env->GetVar("PATH", &env_value)); 21 EXPECT_TRUE(env->GetVar("PATH", &env_value));
20 EXPECT_NE(env_value, ""); 22 EXPECT_NE(env_value, "");
21 } 23 }
22 24
23 TEST_F(EnvironmentTest, GetVarReverse) { 25 TEST_F(EnvironmentTest, GetVarReverse) {
24 scoped_ptr<Environment> env(Environment::Create()); 26 std::unique_ptr<Environment> env(Environment::Create());
25 const char kFooUpper[] = "FOO"; 27 const char kFooUpper[] = "FOO";
26 const char kFooLower[] = "foo"; 28 const char kFooLower[] = "foo";
27 29
28 // Set a variable in UPPER case. 30 // Set a variable in UPPER case.
29 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower)); 31 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
30 32
31 // And then try to get this variable passing the lower case. 33 // And then try to get this variable passing the lower case.
32 std::string env_value; 34 std::string env_value;
33 EXPECT_TRUE(env->GetVar(kFooLower, &env_value)); 35 EXPECT_TRUE(env->GetVar(kFooLower, &env_value));
34 36
35 EXPECT_STREQ(env_value.c_str(), kFooLower); 37 EXPECT_STREQ(env_value.c_str(), kFooLower);
36 38
37 EXPECT_TRUE(env->UnSetVar(kFooUpper)); 39 EXPECT_TRUE(env->UnSetVar(kFooUpper));
38 40
39 const char kBar[] = "bar"; 41 const char kBar[] = "bar";
40 // Now do the opposite, set the variable in the lower case. 42 // Now do the opposite, set the variable in the lower case.
41 EXPECT_TRUE(env->SetVar(kFooLower, kBar)); 43 EXPECT_TRUE(env->SetVar(kFooLower, kBar));
42 44
43 // And then try to get this variable passing the UPPER case. 45 // And then try to get this variable passing the UPPER case.
44 EXPECT_TRUE(env->GetVar(kFooUpper, &env_value)); 46 EXPECT_TRUE(env->GetVar(kFooUpper, &env_value));
45 47
46 EXPECT_STREQ(env_value.c_str(), kBar); 48 EXPECT_STREQ(env_value.c_str(), kBar);
47 49
48 EXPECT_TRUE(env->UnSetVar(kFooLower)); 50 EXPECT_TRUE(env->UnSetVar(kFooLower));
49 } 51 }
50 52
51 TEST_F(EnvironmentTest, HasVar) { 53 TEST_F(EnvironmentTest, HasVar) {
52 // Every setup should have PATH... 54 // Every setup should have PATH...
53 scoped_ptr<Environment> env(Environment::Create()); 55 std::unique_ptr<Environment> env(Environment::Create());
54 EXPECT_TRUE(env->HasVar("PATH")); 56 EXPECT_TRUE(env->HasVar("PATH"));
55 } 57 }
56 58
57 TEST_F(EnvironmentTest, SetVar) { 59 TEST_F(EnvironmentTest, SetVar) {
58 scoped_ptr<Environment> env(Environment::Create()); 60 std::unique_ptr<Environment> env(Environment::Create());
59 61
60 const char kFooUpper[] = "FOO"; 62 const char kFooUpper[] = "FOO";
61 const char kFooLower[] = "foo"; 63 const char kFooLower[] = "foo";
62 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower)); 64 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
63 65
64 // Now verify that the environment has the new variable. 66 // Now verify that the environment has the new variable.
65 EXPECT_TRUE(env->HasVar(kFooUpper)); 67 EXPECT_TRUE(env->HasVar(kFooUpper));
66 68
67 std::string var_value; 69 std::string var_value;
68 EXPECT_TRUE(env->GetVar(kFooUpper, &var_value)); 70 EXPECT_TRUE(env->GetVar(kFooUpper, &var_value));
69 EXPECT_EQ(var_value, kFooLower); 71 EXPECT_EQ(var_value, kFooLower);
70 } 72 }
71 73
72 TEST_F(EnvironmentTest, UnSetVar) { 74 TEST_F(EnvironmentTest, UnSetVar) {
73 scoped_ptr<Environment> env(Environment::Create()); 75 std::unique_ptr<Environment> env(Environment::Create());
74 76
75 const char kFooUpper[] = "FOO"; 77 const char kFooUpper[] = "FOO";
76 const char kFooLower[] = "foo"; 78 const char kFooLower[] = "foo";
77 // First set some environment variable. 79 // First set some environment variable.
78 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower)); 80 EXPECT_TRUE(env->SetVar(kFooUpper, kFooLower));
79 81
80 // Now verify that the environment has the new variable. 82 // Now verify that the environment has the new variable.
81 EXPECT_TRUE(env->HasVar(kFooUpper)); 83 EXPECT_TRUE(env->HasVar(kFooUpper));
82 84
83 // Finally verify that the environment variable was erased. 85 // Finally verify that the environment variable was erased.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 e = AlterEnvironment(a2, changes); 123 e = AlterEnvironment(a2, changes);
122 EXPECT_EQ(string16(L"\0\0", 2), e); 124 EXPECT_EQ(string16(L"\0\0", 2), e);
123 } 125 }
124 126
125 #else 127 #else
126 128
127 TEST_F(EnvironmentTest, AlterEnvironment) { 129 TEST_F(EnvironmentTest, AlterEnvironment) {
128 const char* const empty[] = { NULL }; 130 const char* const empty[] = { NULL };
129 const char* const a2[] = { "A=2", NULL }; 131 const char* const a2[] = { "A=2", NULL };
130 EnvironmentMap changes; 132 EnvironmentMap changes;
131 scoped_ptr<char*[]> e; 133 std::unique_ptr<char* []> e;
132 134
133 e = AlterEnvironment(empty, changes); 135 e = AlterEnvironment(empty, changes);
134 EXPECT_TRUE(e[0] == NULL); 136 EXPECT_TRUE(e[0] == NULL);
135 137
136 changes["A"] = "1"; 138 changes["A"] = "1";
137 e = AlterEnvironment(empty, changes); 139 e = AlterEnvironment(empty, changes);
138 EXPECT_EQ(std::string("A=1"), e[0]); 140 EXPECT_EQ(std::string("A=1"), e[0]);
139 EXPECT_TRUE(e[1] == NULL); 141 EXPECT_TRUE(e[1] == NULL);
140 142
141 changes.clear(); 143 changes.clear();
(...skipping 14 matching lines...) Expand all
156 158
157 changes.clear(); 159 changes.clear();
158 changes["A"] = std::string(); 160 changes["A"] = std::string();
159 e = AlterEnvironment(a2, changes); 161 e = AlterEnvironment(a2, changes);
160 EXPECT_TRUE(e[0] == NULL); 162 EXPECT_TRUE(e[0] == NULL);
161 } 163 }
162 164
163 #endif 165 #endif
164 166
165 } // namespace base 167 } // namespace base
OLDNEW
« no previous file with comments | « base/environment.cc ('k') | base/feature_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698