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

Side by Side Diff: base/command_line_unittest.cc

Issue 11305010: Extract arguments reconstruction logic out of GetCommandLineString() into GetArgumentsString(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« base/command_line.h ('K') | « base/command_line.cc ('k') | no next file » | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 EXPECT_EQ(1U, cl_from_string.argv().size()); 171 EXPECT_EQ(1U, cl_from_string.argv().size());
172 EXPECT_TRUE(cl_from_string.GetArgs().empty()); 172 EXPECT_TRUE(cl_from_string.GetArgs().empty());
173 #endif 173 #endif
174 CommandLine cl_from_argv(0, NULL); 174 CommandLine cl_from_argv(0, NULL);
175 EXPECT_TRUE(cl_from_argv.GetCommandLineString().empty()); 175 EXPECT_TRUE(cl_from_argv.GetCommandLineString().empty());
176 EXPECT_TRUE(cl_from_argv.GetProgram().empty()); 176 EXPECT_TRUE(cl_from_argv.GetProgram().empty());
177 EXPECT_EQ(1U, cl_from_argv.argv().size()); 177 EXPECT_EQ(1U, cl_from_argv.argv().size());
178 EXPECT_TRUE(cl_from_argv.GetArgs().empty()); 178 EXPECT_TRUE(cl_from_argv.GetArgs().empty());
179 } 179 }
180 180
181 TEST(CommandLineTest, GetArgumentsString) {
182 static const FilePath::CharType kPath1[] =
183 FILE_PATH_LITERAL("C:\\Some File\\With Spaces.ggg");
184 static const FilePath::CharType kPath2[] =
185 FILE_PATH_LITERAL("C:\\no\\spaces.ggg");
186
187 static const char kFirstArgName[] = "first-arg";
188 static const char kSecondArgName[] = "arg2";
189
190 CommandLine cl(CommandLine::NO_PROGRAM);
191 cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1));
192 cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2));
robertshield 2012/10/29 02:04:43 should have something in this test that exercises
gab 2012/10/29 15:50:44 Done.
193
194 #if defined(OS_WIN)
195 CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName));
196 CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName));
197 #elif defined(OS_POSIX)
198 CommandLine::StringType expected_first_arg(kFirstArgName);
199 CommandLine::StringType expected_second_arg(kSecondArgName);
200 #endif
201
202 #if defined(OS_WIN)
203 #define QUOTE_ON_WIN FILE_PATH_LITERAL("\"")
204 #else
205 #define QUOTE_ON_WIN FILE_PATH_LITERAL("")
206 #endif // OS_WIN
207
208 CommandLine::StringType expected_str;
209 expected_str.append(FILE_PATH_LITERAL("--"))
210 .append(expected_first_arg)
211 .append(FILE_PATH_LITERAL("="))
212 .append(QUOTE_ON_WIN)
213 .append(kPath1)
214 .append(QUOTE_ON_WIN)
215 .append(FILE_PATH_LITERAL(" "))
216 .append(FILE_PATH_LITERAL("--"))
217 .append(expected_second_arg)
218 .append(FILE_PATH_LITERAL("="))
219 .append(QUOTE_ON_WIN)
220 .append(kPath2)
221 .append(QUOTE_ON_WIN);
222 EXPECT_EQ(expected_str, cl.GetArgumentsString());
223 }
224
181 // Test methods for appending switches to a command line. 225 // Test methods for appending switches to a command line.
182 TEST(CommandLineTest, AppendSwitches) { 226 TEST(CommandLineTest, AppendSwitches) {
183 std::string switch1 = "switch1"; 227 std::string switch1 = "switch1";
184 std::string switch2 = "switch2"; 228 std::string switch2 = "switch2";
185 std::string value2 = "value"; 229 std::string value2 = "value";
186 std::string switch3 = "switch3"; 230 std::string switch3 = "switch3";
187 std::string value3 = "a value with spaces"; 231 std::string value3 = "a value with spaces";
188 std::string switch4 = "switch4"; 232 std::string switch4 = "switch4";
189 std::string value4 = "\"a value with quotes\""; 233 std::string value4 = "\"a value with quotes\"";
190 std::string switch5 = "quotes"; 234 std::string switch5 = "quotes";
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 335 }
292 #endif 336 #endif
293 337
294 // Calling Init multiple times should not modify the previous CommandLine. 338 // Calling Init multiple times should not modify the previous CommandLine.
295 TEST(CommandLineTest, Init) { 339 TEST(CommandLineTest, Init) {
296 CommandLine* initial = CommandLine::ForCurrentProcess(); 340 CommandLine* initial = CommandLine::ForCurrentProcess();
297 EXPECT_FALSE(CommandLine::Init(0, NULL)); 341 EXPECT_FALSE(CommandLine::Init(0, NULL));
298 CommandLine* current = CommandLine::ForCurrentProcess(); 342 CommandLine* current = CommandLine::ForCurrentProcess();
299 EXPECT_EQ(initial, current); 343 EXPECT_EQ(initial, current);
300 } 344 }
OLDNEW
« base/command_line.h ('K') | « base/command_line.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698