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

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: some more quotes working only on OS_WIN 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
« 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) 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 static const char kThirdArgName[] = "arg with space";
190 static const char kFourthArgName[] = "nospace";
191
192 CommandLine cl(CommandLine::NO_PROGRAM);
193 cl.AppendSwitchPath(kFirstArgName, FilePath(kPath1));
194 cl.AppendSwitchPath(kSecondArgName, FilePath(kPath2));
195 cl.AppendArg(kThirdArgName);
196 cl.AppendArg(kFourthArgName);
197
198 #if defined(OS_WIN)
199 CommandLine::StringType expected_first_arg(UTF8ToUTF16(kFirstArgName));
200 CommandLine::StringType expected_second_arg(UTF8ToUTF16(kSecondArgName));
201 CommandLine::StringType expected_third_arg(UTF8ToUTF16(kThirdArgName));
202 CommandLine::StringType expected_fourth_arg(UTF8ToUTF16(kFourthArgName));
203 #elif defined(OS_POSIX)
204 CommandLine::StringType expected_first_arg(kFirstArgName);
205 CommandLine::StringType expected_second_arg(kSecondArgName);
206 CommandLine::StringType expected_third_arg(kThirdArgName);
207 CommandLine::StringType expected_fourth_arg(kFourthArgName);
208 #endif
209
210 #if defined(OS_WIN)
211 #define QUOTE_ON_WIN FILE_PATH_LITERAL("\"")
212 #else
213 #define QUOTE_ON_WIN FILE_PATH_LITERAL("")
214 #endif // OS_WIN
215
216 CommandLine::StringType expected_str;
217 expected_str.append(FILE_PATH_LITERAL("--"))
218 .append(expected_first_arg)
219 .append(FILE_PATH_LITERAL("="))
220 .append(QUOTE_ON_WIN)
221 .append(kPath1)
222 .append(QUOTE_ON_WIN)
223 .append(FILE_PATH_LITERAL(" "))
224 .append(FILE_PATH_LITERAL("--"))
225 .append(expected_second_arg)
226 .append(FILE_PATH_LITERAL("="))
227 .append(QUOTE_ON_WIN)
228 .append(kPath2)
229 .append(QUOTE_ON_WIN)
230 .append(FILE_PATH_LITERAL(" "))
231 .append(QUOTE_ON_WIN)
232 .append(expected_third_arg)
233 .append(QUOTE_ON_WIN)
234 .append(FILE_PATH_LITERAL(" "))
235 .append(expected_fourth_arg);
236 EXPECT_EQ(expected_str, cl.GetArgumentsString());
237 }
238
181 // Test methods for appending switches to a command line. 239 // Test methods for appending switches to a command line.
182 TEST(CommandLineTest, AppendSwitches) { 240 TEST(CommandLineTest, AppendSwitches) {
183 std::string switch1 = "switch1"; 241 std::string switch1 = "switch1";
184 std::string switch2 = "switch2"; 242 std::string switch2 = "switch2";
185 std::string value2 = "value"; 243 std::string value2 = "value";
186 std::string switch3 = "switch3"; 244 std::string switch3 = "switch3";
187 std::string value3 = "a value with spaces"; 245 std::string value3 = "a value with spaces";
188 std::string switch4 = "switch4"; 246 std::string switch4 = "switch4";
189 std::string value4 = "\"a value with quotes\""; 247 std::string value4 = "\"a value with quotes\"";
190 std::string switch5 = "quotes"; 248 std::string switch5 = "quotes";
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 349 }
292 #endif 350 #endif
293 351
294 // Calling Init multiple times should not modify the previous CommandLine. 352 // Calling Init multiple times should not modify the previous CommandLine.
295 TEST(CommandLineTest, Init) { 353 TEST(CommandLineTest, Init) {
296 CommandLine* initial = CommandLine::ForCurrentProcess(); 354 CommandLine* initial = CommandLine::ForCurrentProcess();
297 EXPECT_FALSE(CommandLine::Init(0, NULL)); 355 EXPECT_FALSE(CommandLine::Init(0, NULL));
298 CommandLine* current = CommandLine::ForCurrentProcess(); 356 CommandLine* current = CommandLine::ForCurrentProcess();
299 EXPECT_EQ(initial, current); 357 EXPECT_EQ(initial, current);
300 } 358 }
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