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

Side by Side Diff: base/command_line_unittest.cc

Issue 7866036: micro optimize CommandLine.GetSwitchPrefixLength (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ' Created 9 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « 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) 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 <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 16 matching lines...) Expand all
27 FILE_PATH_LITERAL("program"), 27 FILE_PATH_LITERAL("program"),
28 FILE_PATH_LITERAL("--foo="), 28 FILE_PATH_LITERAL("--foo="),
29 FILE_PATH_LITERAL("-bAr"), 29 FILE_PATH_LITERAL("-bAr"),
30 FILE_PATH_LITERAL("-spaetzel=pierogi"), 30 FILE_PATH_LITERAL("-spaetzel=pierogi"),
31 FILE_PATH_LITERAL("-baz"), 31 FILE_PATH_LITERAL("-baz"),
32 FILE_PATH_LITERAL("flim"), 32 FILE_PATH_LITERAL("flim"),
33 FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"), 33 FILE_PATH_LITERAL("--other-switches=--dog=canine --cat=feline"),
34 FILE_PATH_LITERAL("-spaetzle=Crepe"), 34 FILE_PATH_LITERAL("-spaetzle=Crepe"),
35 FILE_PATH_LITERAL("-=loosevalue"), 35 FILE_PATH_LITERAL("-=loosevalue"),
36 FILE_PATH_LITERAL("FLAN"), 36 FILE_PATH_LITERAL("FLAN"),
37 FILE_PATH_LITERAL("a"),
37 FILE_PATH_LITERAL("--input-translation=45--output-rotation"), 38 FILE_PATH_LITERAL("--input-translation=45--output-rotation"),
38 FILE_PATH_LITERAL("--"), 39 FILE_PATH_LITERAL("--"),
39 FILE_PATH_LITERAL("--"), 40 FILE_PATH_LITERAL("--"),
40 FILE_PATH_LITERAL("--not-a-switch"), 41 FILE_PATH_LITERAL("--not-a-switch"),
41 FILE_PATH_LITERAL("\"in the time of submarines...\""), 42 FILE_PATH_LITERAL("\"in the time of submarines...\""),
42 FILE_PATH_LITERAL("unquoted arg-with-space")}; 43 FILE_PATH_LITERAL("unquoted arg-with-space")};
43 CommandLine cl(arraysize(argv), argv); 44 CommandLine cl(arraysize(argv), argv);
44 45
45 EXPECT_FALSE(cl.GetCommandLineString().empty()); 46 EXPECT_FALSE(cl.GetCommandLineString().empty());
46 EXPECT_FALSE(cl.HasSwitch("cruller")); 47 EXPECT_FALSE(cl.HasSwitch("cruller"));
(...skipping 20 matching lines...) Expand all
67 68
68 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle")); 69 EXPECT_EQ("Crepe", cl.GetSwitchValueASCII("spaetzle"));
69 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo")); 70 EXPECT_EQ("", cl.GetSwitchValueASCII("Foo"));
70 EXPECT_EQ("", cl.GetSwitchValueASCII("bar")); 71 EXPECT_EQ("", cl.GetSwitchValueASCII("bar"));
71 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller")); 72 EXPECT_EQ("", cl.GetSwitchValueASCII("cruller"));
72 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII( 73 EXPECT_EQ("--dog=canine --cat=feline", cl.GetSwitchValueASCII(
73 "other-switches")); 74 "other-switches"));
74 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation")); 75 EXPECT_EQ("45--output-rotation", cl.GetSwitchValueASCII("input-translation"));
75 76
76 const CommandLine::StringVector& args = cl.GetArgs(); 77 const CommandLine::StringVector& args = cl.GetArgs();
77 ASSERT_EQ(6U, args.size()); 78 ASSERT_EQ(7U, args.size());
78 79
79 std::vector<CommandLine::StringType>::const_iterator iter = args.begin(); 80 std::vector<CommandLine::StringType>::const_iterator iter = args.begin();
80 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter); 81 EXPECT_EQ(FILE_PATH_LITERAL("flim"), *iter);
81 ++iter; 82 ++iter;
82 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter); 83 EXPECT_EQ(FILE_PATH_LITERAL("FLAN"), *iter);
83 ++iter; 84 ++iter;
85 EXPECT_EQ(FILE_PATH_LITERAL("a"), *iter);
86 ++iter;
84 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter); 87 EXPECT_EQ(FILE_PATH_LITERAL("--"), *iter);
85 ++iter; 88 ++iter;
86 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter); 89 EXPECT_EQ(FILE_PATH_LITERAL("--not-a-switch"), *iter);
87 ++iter; 90 ++iter;
88 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter); 91 EXPECT_EQ(FILE_PATH_LITERAL("\"in the time of submarines...\""), *iter);
89 ++iter; 92 ++iter;
90 EXPECT_EQ(FILE_PATH_LITERAL("unquoted arg-with-space"), *iter); 93 EXPECT_EQ(FILE_PATH_LITERAL("unquoted arg-with-space"), *iter);
91 ++iter; 94 ++iter;
92 EXPECT_TRUE(iter == args.end()); 95 EXPECT_TRUE(iter == args.end());
93 } 96 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 } 288 }
286 #endif 289 #endif
287 290
288 // Calling Init multiple times should not modify the previous CommandLine. 291 // Calling Init multiple times should not modify the previous CommandLine.
289 TEST(CommandLineTest, Init) { 292 TEST(CommandLineTest, Init) {
290 CommandLine* initial = CommandLine::ForCurrentProcess(); 293 CommandLine* initial = CommandLine::ForCurrentProcess();
291 CommandLine::Init(0, NULL); 294 CommandLine::Init(0, NULL);
292 CommandLine* current = CommandLine::ForCurrentProcess(); 295 CommandLine* current = CommandLine::ForCurrentProcess();
293 EXPECT_EQ(initial, current); 296 EXPECT_EQ(initial, current);
294 } 297 }
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698