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

Side by Side Diff: base/command_line_unittest.cc

Issue 645133002: Prefix CommandLine usege with base namespace (Part 1: base/) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated #3 Created 6 years, 2 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 | « no previous file | base/i18n/build_utf8_validator_tables.cc » ('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) 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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using base::FilePath; 14 namespace base {
15 15
16 // To test Windows quoting behavior, we use a string that has some backslashes 16 // To test Windows quoting behavior, we use a string that has some backslashes
17 // and quotes. 17 // and quotes.
18 // Consider the command-line argument: q\"bs1\bs2\\bs3q\\\" 18 // Consider the command-line argument: q\"bs1\bs2\\bs3q\\\"
19 // Here it is with C-style escapes. 19 // Here it is with C-style escapes.
20 static const CommandLine::StringType kTrickyQuoted = 20 static const CommandLine::StringType kTrickyQuoted =
21 FILE_PATH_LITERAL("q\\\"bs1\\bs2\\\\bs3q\\\\\\\""); 21 FILE_PATH_LITERAL("q\\\"bs1\\bs2\\\\bs3q\\\\\\\"");
22 // It should be parsed by Windows as: q"bs1\bs2\\bs3q\" 22 // It should be parsed by Windows as: q"bs1\bs2\\bs3q\"
23 // Here that is with C-style escapes. 23 // Here that is with C-style escapes.
24 static const CommandLine::StringType kTricky = 24 static const CommandLine::StringType kTricky =
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 static const char kFifthArgName[] = "%1"; 193 static const char kFifthArgName[] = "%1";
194 194
195 CommandLine cl(CommandLine::NO_PROGRAM); 195 CommandLine cl(CommandLine::NO_PROGRAM);
196 cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1)); 196 cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1));
197 cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2)); 197 cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2));
198 cl.AppendArg(kThirdArgName); 198 cl.AppendArg(kThirdArgName);
199 cl.AppendArg(kFourthArgName); 199 cl.AppendArg(kFourthArgName);
200 cl.AppendArg(kFifthArgName); 200 cl.AppendArg(kFifthArgName);
201 201
202 #if defined(OS_WIN) 202 #if defined(OS_WIN)
203 CommandLine::StringType expected_first_arg( 203 CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName));
204 base::UTF8ToUTF16(kFirstArgName)); 204 CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName));
205 CommandLine::StringType expected_second_arg( 205 CommandLine::StringType expected_third_arg(UTF8ToUTF16(kThirdArgName));
206 base::UTF8ToUTF16(kSecondArgName)); 206 CommandLine::StringType expected_fourth_arg(UTF8ToUTF16(kFourthArgName));
207 CommandLine::StringType expected_third_arg( 207 CommandLine::StringType expected_fifth_arg(UTF8ToUTF16(kFifthArgName));
208 base::UTF8ToUTF16(kThirdArgName));
209 CommandLine::StringType expected_fourth_arg(
210 base::UTF8ToUTF16(kFourthArgName));
211 CommandLine::StringType expected_fifth_arg(base::UTF8ToUTF16(kFifthArgName));
212 #elif defined(OS_POSIX) 208 #elif defined(OS_POSIX)
213 CommandLine::StringType expected_first_arg(kFirstArgName); 209 CommandLine::StringType expected_first_arg(kFirstArgName);
214 CommandLine::StringType expected_second_arg(kSecondArgName); 210 CommandLine::StringType expected_second_arg(kSecondArgName);
215 CommandLine::StringType expected_third_arg(kThirdArgName); 211 CommandLine::StringType expected_third_arg(kThirdArgName);
216 CommandLine::StringType expected_fourth_arg(kFourthArgName); 212 CommandLine::StringType expected_fourth_arg(kFourthArgName);
217 CommandLine::StringType expected_fifth_arg(kFifthArgName); 213 CommandLine::StringType expected_fifth_arg(kFifthArgName);
218 #endif 214 #endif
219 215
220 #if defined(OS_WIN) 216 #if defined(OS_WIN)
221 #define QUOTE_ON_WIN FILE_PATH_LITERAL("\"") 217 #define QUOTE_ON_WIN FILE_PATH_LITERAL("\"")
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 357
362 // Check that quotes are not returned from GetProgram(). 358 // Check that quotes are not returned from GetProgram().
363 CommandLine cl_program_path(kProgramPath); 359 CommandLine cl_program_path(kProgramPath);
364 EXPECT_EQ(kProgramPath.value(), cl_program_path.GetProgram().value()); 360 EXPECT_EQ(kProgramPath.value(), cl_program_path.GetProgram().value());
365 361
366 // Check that quotes are added to command line string paths containing spaces. 362 // Check that quotes are added to command line string paths containing spaces.
367 CommandLine::StringType cmd_string(cl_program_path.GetCommandLineString()); 363 CommandLine::StringType cmd_string(cl_program_path.GetCommandLineString());
368 EXPECT_EQ(L"\"Program Path\"", cmd_string); 364 EXPECT_EQ(L"\"Program Path\"", cmd_string);
369 365
370 // Check the optional quoting of placeholders in programs. 366 // Check the optional quoting of placeholders in programs.
371 CommandLine cl_quote_placeholder(base::FilePath(L"%1")); 367 CommandLine cl_quote_placeholder(FilePath(L"%1"));
372 EXPECT_EQ(L"%1", cl_quote_placeholder.GetCommandLineString()); 368 EXPECT_EQ(L"%1", cl_quote_placeholder.GetCommandLineString());
373 EXPECT_EQ(L"\"%1\"", 369 EXPECT_EQ(L"\"%1\"",
374 cl_quote_placeholder.GetCommandLineStringWithPlaceholders()); 370 cl_quote_placeholder.GetCommandLineStringWithPlaceholders());
375 } 371 }
376 #endif 372 #endif
377 373
378 // Calling Init multiple times should not modify the previous CommandLine. 374 // Calling Init multiple times should not modify the previous CommandLine.
379 TEST(CommandLineTest, Init) { 375 TEST(CommandLineTest, Init) {
380 CommandLine* initial = CommandLine::ForCurrentProcess(); 376 CommandLine* initial = CommandLine::ForCurrentProcess();
381 EXPECT_FALSE(CommandLine::Init(0, NULL)); 377 EXPECT_FALSE(CommandLine::Init(0, NULL));
382 CommandLine* current = CommandLine::ForCurrentProcess(); 378 CommandLine* current = CommandLine::ForCurrentProcess();
383 EXPECT_EQ(initial, current); 379 EXPECT_EQ(initial, current);
384 } 380 }
381
382 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/i18n/build_utf8_validator_tables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698