OLD | NEW |
---|---|
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/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/basictypes.h" | |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 // To test Windows quoting behavior, we use a string that has some backslashes | 14 // To test Windows quoting behavior, we use a string that has some backslashes |
15 // and quotes. | 15 // and quotes. |
16 // Consider the command-line argument: q\"bs1\bs2\\bs3q\\\" | 16 // Consider the command-line argument: q\"bs1\bs2\\bs3q\\\" |
17 // Here it is with C-style escapes. | 17 // Here it is with C-style escapes. |
18 #define TRICKY_QUOTED L"q\\\"bs1\\bs2\\\\bs3q\\\\\\\"" | 18 #define TRICKY_QUOTED L"q\\\"bs1\\bs2\\\\bs3q\\\\\\\"" |
19 // It should be parsed by Windows as: q"bs1\bs2\\bs3q\" | 19 // It should be parsed by Windows as: q"bs1\bs2\\bs3q\" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
148 EXPECT_EQ(L"\"Program\" " | 148 EXPECT_EQ(L"\"Program\" " |
149 L"--switch1 " | 149 L"--switch1 " |
150 L"--switch2=value " | 150 L"--switch2=value " |
151 L"--switch3=\"a value with spaces\" " | 151 L"--switch3=\"a value with spaces\" " |
152 L"--switch4=\"\\\"a value with quotes\\\"\" " | 152 L"--switch4=\"\\\"a value with quotes\\\"\" " |
153 L"--quotes=\"" TRICKY_QUOTED L"\"", | 153 L"--quotes=\"" TRICKY_QUOTED L"\"", |
154 cl.command_line_string()); | 154 cl.command_line_string()); |
155 #endif | 155 #endif |
156 } | 156 } |
157 | |
158 // Tests that when AppendArguments is called that both the program and | |
159 // command line strings are equal. | |
160 TEST(CommandLineTest, AppendArguments) { | |
161 CommandLine cl1(FilePath(FILE_PATH_LITERAL("Program"))); | |
162 cl1.AppendSwitch("switch1"); | |
163 cl1.AppendSwitchASCII("switch2", "foo"); | |
164 | |
165 CommandLine cl2(CommandLine::NO_PROGRAM); | |
166 cl2.AppendArguments(cl1, true); | |
167 EXPECT_EQ(cl1.GetProgram().value(), cl2.GetProgram().value()); | |
168 EXPECT_EQ(cl1.command_line_string(), cl2.command_line_string()); | |
robertshield
2010/11/14 15:21:31
Could you also test the new replacement behaviour
tommi (sloooow) - chröme
2010/11/14 21:28:07
Done.
| |
169 } | |
170 | |
OLD | NEW |