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

Side by Side Diff: base/command_line_unittest.cc

Issue 19740: Merge r2876 to the 1.0 release branch.... (Closed) Base URL: svn://chrome-svn/chrome/branches/release_154.next/src/
Patch Set: Created 11 years, 10 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace { 13 namespace {
14 class CommandLineTest : public testing::Test { 14 class CommandLineTest : public testing::Test {
15 }; 15 };
16 }; 16 };
17 17
18 TEST(CommandLineTest, CommandLineConstructor) { 18 TEST(CommandLineTest, CommandLineConstructor) {
19 #ifdef OS_WIN 19 #ifdef OS_WIN
20 CommandLine cl(L"program --foo= -bAr /Spaetzel=pierogi /Baz flim " 20 CommandLine cl(L"program --foo= -bAr /Spaetzel=pierogi /Baz flim "
21 L"--other-switches=\"--dog=canine --cat=feline\" " 21 L"--other-switches=\"--dog=canine --cat=feline\" "
22 L"-spaetzle=Crepe -=loosevalue flan " 22 L"-spaetzle=Crepe -=loosevalue flan "
23 L"--input-translation=\"45\"--output-rotation " 23 L"--input-translation=\"45\"--output-rotation "
24 L"-- -- --not-a-switch "
24 L"\"in the time of submarines...\""); 25 L"\"in the time of submarines...\"");
25 #elif defined(OS_POSIX) 26 #elif defined(OS_POSIX)
26 const char* argv[] = {"program", "--foo=", "-bAr", 27 const char* argv[] = {"program", "--foo=", "-bAr",
27 "-Spaetzel=pierogi", "-Baz", "flim", 28 "-Spaetzel=pierogi", "-Baz", "flim",
28 "--other-switches=--dog=canine --cat=feline", 29 "--other-switches=--dog=canine --cat=feline",
29 "-spaetzle=Crepe", "-=loosevalue", "flan", 30 "-spaetzle=Crepe", "-=loosevalue", "flan",
30 "--input-translation=45--output-rotation", 31 "--input-translation=45--output-rotation",
32 "--", "--", "--not-a-switch",
31 "in the time of submarines..."}; 33 "in the time of submarines..."};
32 CommandLine cl(arraysize(argv), argv); 34 CommandLine cl(arraysize(argv), argv);
33 #endif 35 #endif
34 EXPECT_FALSE(cl.command_line_string().empty()); 36 EXPECT_FALSE(cl.command_line_string().empty());
35 EXPECT_FALSE(cl.HasSwitch(L"cruller")); 37 EXPECT_FALSE(cl.HasSwitch(L"cruller"));
36 EXPECT_FALSE(cl.HasSwitch(L"flim")); 38 EXPECT_FALSE(cl.HasSwitch(L"flim"));
37 EXPECT_FALSE(cl.HasSwitch(L"program")); 39 EXPECT_FALSE(cl.HasSwitch(L"program"));
38 EXPECT_FALSE(cl.HasSwitch(L"dog")); 40 EXPECT_FALSE(cl.HasSwitch(L"dog"));
39 EXPECT_FALSE(cl.HasSwitch(L"cat")); 41 EXPECT_FALSE(cl.HasSwitch(L"cat"));
40 EXPECT_FALSE(cl.HasSwitch(L"output-rotation")); 42 EXPECT_FALSE(cl.HasSwitch(L"output-rotation"));
43 EXPECT_FALSE(cl.HasSwitch(L"not-a-switch"));
44 EXPECT_FALSE(cl.HasSwitch(L"--"));
41 45
42 EXPECT_EQ(L"program", cl.program()); 46 EXPECT_EQ(L"program", cl.program());
43 47
44 EXPECT_TRUE(cl.HasSwitch(L"foo")); 48 EXPECT_TRUE(cl.HasSwitch(L"foo"));
45 EXPECT_TRUE(cl.HasSwitch(L"bar")); 49 EXPECT_TRUE(cl.HasSwitch(L"bar"));
46 EXPECT_TRUE(cl.HasSwitch(L"baz")); 50 EXPECT_TRUE(cl.HasSwitch(L"baz"));
47 EXPECT_TRUE(cl.HasSwitch(L"spaetzle")); 51 EXPECT_TRUE(cl.HasSwitch(L"spaetzle"));
48 EXPECT_TRUE(cl.HasSwitch(L"SPAETZLE")); 52 EXPECT_TRUE(cl.HasSwitch(L"SPAETZLE"));
49 EXPECT_TRUE(cl.HasSwitch(L"other-switches")); 53 EXPECT_TRUE(cl.HasSwitch(L"other-switches"));
50 EXPECT_TRUE(cl.HasSwitch(L"input-translation")); 54 EXPECT_TRUE(cl.HasSwitch(L"input-translation"));
51 55
52 EXPECT_EQ(L"Crepe", cl.GetSwitchValue(L"spaetzle")); 56 EXPECT_EQ(L"Crepe", cl.GetSwitchValue(L"spaetzle"));
53 EXPECT_EQ(L"", cl.GetSwitchValue(L"Foo")); 57 EXPECT_EQ(L"", cl.GetSwitchValue(L"Foo"));
54 EXPECT_EQ(L"", cl.GetSwitchValue(L"bar")); 58 EXPECT_EQ(L"", cl.GetSwitchValue(L"bar"));
55 EXPECT_EQ(L"", cl.GetSwitchValue(L"cruller")); 59 EXPECT_EQ(L"", cl.GetSwitchValue(L"cruller"));
56 EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue(L"other-switches")); 60 EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue(L"other-switches"));
57 EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue(L"input-translation")); 61 EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue(L"input-translation"));
58 62
59 EXPECT_EQ(3U, cl.GetLooseValueCount()); 63 EXPECT_EQ(5U, cl.GetLooseValueCount());
60 64
61 CommandLine::LooseValueIterator iter = cl.GetLooseValuesBegin(); 65 CommandLine::LooseValueIterator iter = cl.GetLooseValuesBegin();
62 EXPECT_EQ(L"flim", *iter); 66 EXPECT_EQ(L"flim", *iter);
63 ++iter; 67 ++iter;
64 EXPECT_EQ(L"flan", *iter); 68 EXPECT_EQ(L"flan", *iter);
65 ++iter; 69 ++iter;
70 EXPECT_EQ(L"--", *iter);
71 ++iter;
72 EXPECT_EQ(L"--not-a-switch", *iter);
73 ++iter;
66 EXPECT_EQ(L"in the time of submarines...", *iter); 74 EXPECT_EQ(L"in the time of submarines...", *iter);
67 ++iter; 75 ++iter;
68 EXPECT_TRUE(iter == cl.GetLooseValuesEnd()); 76 EXPECT_TRUE(iter == cl.GetLooseValuesEnd());
69 } 77 }
70 78
71 // These test the command line used to invoke the unit test. 79 // These test the command line used to invoke the unit test.
72 TEST(CommandLineTest, DefaultConstructor) { 80 TEST(CommandLineTest, DefaultConstructor) {
73 CommandLine cl; 81 CommandLine cl;
74 EXPECT_FALSE(cl.command_line_string().empty()); 82 EXPECT_FALSE(cl.command_line_string().empty());
75 EXPECT_FALSE(cl.program().empty()); 83 EXPECT_FALSE(cl.program().empty());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 117
110 EXPECT_TRUE(cl.HasSwitch(switch1)); 118 EXPECT_TRUE(cl.HasSwitch(switch1));
111 EXPECT_TRUE(cl.HasSwitch(switch2)); 119 EXPECT_TRUE(cl.HasSwitch(switch2));
112 EXPECT_EQ(value, cl.GetSwitchValue(switch2)); 120 EXPECT_EQ(value, cl.GetSwitchValue(switch2));
113 EXPECT_TRUE(cl.HasSwitch(switch3)); 121 EXPECT_TRUE(cl.HasSwitch(switch3));
114 EXPECT_EQ(value3, cl.GetSwitchValue(switch3)); 122 EXPECT_EQ(value3, cl.GetSwitchValue(switch3));
115 EXPECT_TRUE(cl.HasSwitch(switch2)); 123 EXPECT_TRUE(cl.HasSwitch(switch2));
116 EXPECT_EQ(value4.substr(1, value4.length() - 2), cl.GetSwitchValue(switch4)); 124 EXPECT_EQ(value4.substr(1, value4.length() - 2), cl.GetSwitchValue(switch4));
117 } 125 }
118 #endif 126 #endif
119
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