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

Side by Side Diff: base/command_line_unittest.cc

Issue 4949004: Add a unit test for CommandLine that makes sure that GetProgram will not retu... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
« base/command_line.cc ('K') | « 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 c1.AppendSwitch("switch1"); 172 c1.AppendSwitch("switch1");
173 CommandLine c2(FilePath(FILE_PATH_LITERAL("Program2"))); 173 CommandLine c2(FilePath(FILE_PATH_LITERAL("Program2")));
174 c2.AppendSwitch("switch2"); 174 c2.AppendSwitch("switch2");
175 175
176 c1.AppendArguments(c2, true); 176 c1.AppendArguments(c2, true);
177 EXPECT_EQ(c1.GetProgram().value(), c2.GetProgram().value()); 177 EXPECT_EQ(c1.GetProgram().value(), c2.GetProgram().value());
178 EXPECT_TRUE(c1.HasSwitch("switch1")); 178 EXPECT_TRUE(c1.HasSwitch("switch1"));
179 EXPECT_TRUE(c1.HasSwitch("switch2")); 179 EXPECT_TRUE(c1.HasSwitch("switch2"));
180 } 180 }
181 181
182 #if defined(OS_WIN)
183 // Make sure that the program part of a command line is always quoted.
184 // Only makes sense on Windows.
185 TEST(CommandLineTest, ProgramQuotes) {
186 const FilePath kProgram(FILE_PATH_LITERAL("Program"));
187 const FilePath kProgramQuoted(FILE_PATH_LITERAL("\"Program\""));
188
189 // Check that quotes are not returned from GetProgram().
190 CommandLine cl1(kProgram);
191 EXPECT_EQ(kProgram.value(), cl1.GetProgram().value());
192
193 CommandLine cl2(kProgramQuoted);
194 EXPECT_EQ(kProgram.value(), cl2.GetProgram().value());
195
196 CommandLine cl3(CommandLine::FromString(kProgramQuoted.value()));
197 EXPECT_EQ(kProgram.value(), cl3.GetProgram().value());
198
199 // Verify that in the command line string, the program part is always quoted.
200 CommandLine* check[] = {&cl1, &cl2, &cl3};
201 for (int i = 0; i < arraysize(check); ++i) {
202 CommandLine::StringType c(check[i]->command_line_string());
203 CommandLine::StringType p(check[i]->GetProgram().value());
204 EXPECT_EQ('"', c[0]);
205 EXPECT_EQ(p, c.substr(1, p.length()));
206 EXPECT_EQ('"', c[p.length() + 1]);
207 }
208 }
209 #endif
OLDNEW
« base/command_line.cc ('K') | « base/command_line.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698