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

Side by Side Diff: base/command_line_unittest.cc

Issue 270062: Use ASCII strings for switch names. (Closed)
Patch Set: victory Created 11 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 | « base/command_line.cc ('k') | base/debug_on_start.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) 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/string_util.h" 10 #include "base/string_util.h"
(...skipping 12 matching lines...) Expand all
23 #elif defined(OS_POSIX) 23 #elif defined(OS_POSIX)
24 const char* argv[] = {"program", "--foo=", "-bar", 24 const char* argv[] = {"program", "--foo=", "-bar",
25 "-spaetzel=pierogi", "-baz", "flim", 25 "-spaetzel=pierogi", "-baz", "flim",
26 "--other-switches=--dog=canine --cat=feline", 26 "--other-switches=--dog=canine --cat=feline",
27 "-spaetzle=Crepe", "-=loosevalue", "flan", 27 "-spaetzle=Crepe", "-=loosevalue", "flan",
28 "--input-translation=45--output-rotation", 28 "--input-translation=45--output-rotation",
29 "--", "--", "--not-a-switch", 29 "--", "--", "--not-a-switch",
30 "in the time of submarines..."}; 30 "in the time of submarines..."};
31 CommandLine cl(arraysize(argv), argv); 31 CommandLine cl(arraysize(argv), argv);
32 #endif 32 #endif
33 EXPECT_FALSE(cl.HasSwitch(L"cruller")); 33 EXPECT_FALSE(cl.HasSwitch("cruller"));
34 EXPECT_FALSE(cl.HasSwitch(L"flim")); 34 EXPECT_FALSE(cl.HasSwitch("flim"));
35 EXPECT_FALSE(cl.HasSwitch(L"program")); 35 EXPECT_FALSE(cl.HasSwitch("program"));
36 EXPECT_FALSE(cl.HasSwitch(L"dog")); 36 EXPECT_FALSE(cl.HasSwitch("dog"));
37 EXPECT_FALSE(cl.HasSwitch(L"cat")); 37 EXPECT_FALSE(cl.HasSwitch("cat"));
38 EXPECT_FALSE(cl.HasSwitch(L"output-rotation")); 38 EXPECT_FALSE(cl.HasSwitch("output-rotation"));
39 EXPECT_FALSE(cl.HasSwitch(L"not-a-switch")); 39 EXPECT_FALSE(cl.HasSwitch("not-a-switch"));
40 EXPECT_FALSE(cl.HasSwitch(L"--")); 40 EXPECT_FALSE(cl.HasSwitch("--"));
41 41
42 EXPECT_EQ(L"program", cl.program()); 42 EXPECT_EQ(L"program", cl.program());
43 43
44 EXPECT_TRUE(cl.HasSwitch(L"foo")); 44 EXPECT_TRUE(cl.HasSwitch("foo"));
45 EXPECT_TRUE(cl.HasSwitch(L"bar")); 45 EXPECT_TRUE(cl.HasSwitch("bar"));
46 EXPECT_TRUE(cl.HasSwitch(L"baz")); 46 EXPECT_TRUE(cl.HasSwitch("baz"));
47 EXPECT_TRUE(cl.HasSwitch(L"spaetzle")); 47 EXPECT_TRUE(cl.HasSwitch("spaetzle"));
48 #if defined(OS_WIN) 48 #if defined(OS_WIN)
49 EXPECT_TRUE(cl.HasSwitch(L"SPAETZLE")); 49 EXPECT_TRUE(cl.HasSwitch("SPAETZLE"));
50 #endif 50 #endif
51 EXPECT_TRUE(cl.HasSwitch(L"other-switches")); 51 EXPECT_TRUE(cl.HasSwitch("other-switches"));
52 EXPECT_TRUE(cl.HasSwitch(L"input-translation")); 52 EXPECT_TRUE(cl.HasSwitch("input-translation"));
53 53
54 EXPECT_EQ(L"Crepe", cl.GetSwitchValue(L"spaetzle")); 54 EXPECT_EQ(L"Crepe", cl.GetSwitchValue("spaetzle"));
55 EXPECT_EQ(L"", cl.GetSwitchValue(L"Foo")); 55 EXPECT_EQ(L"", cl.GetSwitchValue("Foo"));
56 EXPECT_EQ(L"", cl.GetSwitchValue(L"bar")); 56 EXPECT_EQ(L"", cl.GetSwitchValue("bar"));
57 EXPECT_EQ(L"", cl.GetSwitchValue(L"cruller")); 57 EXPECT_EQ(L"", cl.GetSwitchValue("cruller"));
58 EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue(L"other-switches")); 58 EXPECT_EQ(L"--dog=canine --cat=feline", cl.GetSwitchValue("other-switches"));
59 EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue(L"input-translation")); 59 EXPECT_EQ(L"45--output-rotation", cl.GetSwitchValue("input-translation"));
60 60
61 std::vector<std::wstring> loose_values = cl.GetLooseValues(); 61 std::vector<std::wstring> loose_values = cl.GetLooseValues();
62 ASSERT_EQ(5U, loose_values.size()); 62 ASSERT_EQ(5U, loose_values.size());
63 63
64 std::vector<std::wstring>::const_iterator iter = loose_values.begin(); 64 std::vector<std::wstring>::const_iterator iter = loose_values.begin();
65 EXPECT_EQ(L"flim", *iter); 65 EXPECT_EQ(L"flim", *iter);
66 ++iter; 66 ++iter;
67 EXPECT_EQ(L"flan", *iter); 67 EXPECT_EQ(L"flan", *iter);
68 ++iter; 68 ++iter;
69 EXPECT_EQ(L"--", *iter); 69 EXPECT_EQ(L"--", *iter);
(...skipping 20 matching lines...) Expand all
90 EXPECT_TRUE(cl.program().empty()); 90 EXPECT_TRUE(cl.program().empty());
91 #elif defined(OS_POSIX) 91 #elif defined(OS_POSIX)
92 CommandLine cl(0, NULL); 92 CommandLine cl(0, NULL);
93 EXPECT_TRUE(cl.argv().size() == 0); 93 EXPECT_TRUE(cl.argv().size() == 0);
94 #endif 94 #endif
95 EXPECT_EQ(0U, cl.GetLooseValues().size()); 95 EXPECT_EQ(0U, cl.GetLooseValues().size());
96 } 96 }
97 97
98 // Test methods for appending switches to a command line. 98 // Test methods for appending switches to a command line.
99 TEST(CommandLineTest, AppendSwitches) { 99 TEST(CommandLineTest, AppendSwitches) {
100 std::wstring switch1 = L"switch1"; 100 std::string switch1 = "switch1";
101 std::wstring switch2 = L"switch2"; 101 std::string switch2 = "switch2";
102 std::wstring value = L"value"; 102 std::wstring value = L"value";
103 std::wstring switch3 = L"switch3"; 103 std::string switch3 = "switch3";
104 std::wstring value3 = L"a value with spaces"; 104 std::wstring value3 = L"a value with spaces";
105 std::wstring switch4 = L"switch4"; 105 std::string switch4 = "switch4";
106 std::wstring value4 = L"\"a value with quotes\""; 106 std::wstring value4 = L"\"a value with quotes\"";
107 107
108 #if defined(OS_WIN) 108 #if defined(OS_WIN)
109 CommandLine cl(L"Program"); 109 CommandLine cl(L"Program");
110 #elif defined(OS_POSIX) 110 #elif defined(OS_POSIX)
111 std::vector<std::string> argv; 111 std::vector<std::string> argv;
112 argv.push_back(std::string("Program")); 112 argv.push_back(std::string("Program"));
113 CommandLine cl(argv); 113 CommandLine cl(argv);
114 #endif 114 #endif
115 115
116 cl.AppendSwitch(switch1); 116 cl.AppendSwitch(switch1);
117 cl.AppendSwitchWithValue(switch2, value); 117 cl.AppendSwitchWithValue(switch2, value);
118 cl.AppendSwitchWithValue(switch3, value3); 118 cl.AppendSwitchWithValue(switch3, value3);
119 cl.AppendSwitchWithValue(switch4, value4); 119 cl.AppendSwitchWithValue(switch4, value4);
120 120
121 EXPECT_TRUE(cl.HasSwitch(switch1)); 121 EXPECT_TRUE(cl.HasSwitch(switch1));
122 EXPECT_TRUE(cl.HasSwitch(switch2)); 122 EXPECT_TRUE(cl.HasSwitch(switch2));
123 EXPECT_EQ(value, cl.GetSwitchValue(switch2)); 123 EXPECT_EQ(value, cl.GetSwitchValue(switch2));
124 EXPECT_TRUE(cl.HasSwitch(switch3)); 124 EXPECT_TRUE(cl.HasSwitch(switch3));
125 EXPECT_EQ(value3, cl.GetSwitchValue(switch3)); 125 EXPECT_EQ(value3, cl.GetSwitchValue(switch3));
126 EXPECT_TRUE(cl.HasSwitch(switch4)); 126 EXPECT_TRUE(cl.HasSwitch(switch4));
127 EXPECT_EQ(value4, cl.GetSwitchValue(switch4)); 127 EXPECT_EQ(value4, cl.GetSwitchValue(switch4));
128 } 128 }
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | base/debug_on_start.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698