OLD | NEW |
1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 23 matching lines...) Expand all Loading... |
34 | 34 |
35 static void Free(HLOCAL memory) { | 35 static void Free(HLOCAL memory) { |
36 PLOG_IF(ERROR, LocalFree(memory) != nullptr) << "LocalFree"; | 36 PLOG_IF(ERROR, LocalFree(memory) != nullptr) << "LocalFree"; |
37 } | 37 } |
38 }; | 38 }; |
39 using ScopedLocalAlloc = base::ScopedGeneric<HLOCAL, LocalAllocTraits>; | 39 using ScopedLocalAlloc = base::ScopedGeneric<HLOCAL, LocalAllocTraits>; |
40 | 40 |
41 // Calls AppendCommandLineArgument() for every argument in argv, then calls | 41 // Calls AppendCommandLineArgument() for every argument in argv, then calls |
42 // CommandLineToArgvW() to decode the string into a vector again, and compares | 42 // CommandLineToArgvW() to decode the string into a vector again, and compares |
43 // the input and output. | 43 // the input and output. |
44 void AppendCommandLineArgumentTest(size_t argc, const wchar_t* argv[]) { | 44 void AppendCommandLineArgumentTest(size_t argc, const wchar_t* const argv[]) { |
45 std::wstring command_line; | 45 std::wstring command_line; |
46 for (size_t index = 0; index < argc; ++index) { | 46 for (size_t index = 0; index < argc; ++index) { |
47 AppendCommandLineArgument(argv[index], &command_line); | 47 AppendCommandLineArgument(argv[index], &command_line); |
48 } | 48 } |
49 | 49 |
50 int test_argc; | 50 int test_argc; |
51 wchar_t** test_argv = CommandLineToArgvW(command_line.c_str(), &test_argc); | 51 wchar_t** test_argv = CommandLineToArgvW(command_line.c_str(), &test_argc); |
52 | 52 |
53 ASSERT_TRUE(test_argv) << ErrorMessage("CommandLineToArgvW"); | 53 ASSERT_TRUE(test_argv) << ErrorMessage("CommandLineToArgvW"); |
54 ScopedLocalAlloc test_argv_owner(test_argv); | 54 ScopedLocalAlloc test_argv_owner(test_argv); |
55 ASSERT_EQ(argc, test_argc); | 55 ASSERT_EQ(argc, test_argc); |
56 | 56 |
57 for (size_t index = 0; index < argc; ++index) { | 57 for (size_t index = 0; index < argc; ++index) { |
58 EXPECT_STREQ(argv[index], test_argv[index]) << "index " << index; | 58 EXPECT_STREQ(argv[index], test_argv[index]) << "index " << index; |
59 } | 59 } |
60 EXPECT_FALSE(test_argv[argc]); | 60 EXPECT_FALSE(test_argv[argc]); |
61 } | 61 } |
62 | 62 |
63 TEST(CommandLine, AppendCommandLineArgument) { | 63 TEST(CommandLine, AppendCommandLineArgument) { |
64 // Most of these test cases come from | 64 // Most of these test cases come from |
65 // http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/eve
ryone-quotes-arguments-the-wrong-way.aspx, | 65 // http://blogs.msdn.com/b/twistylittlepassagesallalike/archive/2011/04/23/eve
ryone-quotes-arguments-the-wrong-way.aspx, |
66 // which was also a reference for the implementation of | 66 // which was also a reference for the implementation of |
67 // AppendCommandLineArgument(). | 67 // AppendCommandLineArgument(). |
68 | 68 |
69 { | 69 { |
70 SCOPED_TRACE("simple"); | 70 SCOPED_TRACE("simple"); |
71 | 71 |
72 const wchar_t* kArguments[] = { | 72 const wchar_t* const kArguments[] = { |
73 L"child.exe", | 73 L"child.exe", |
74 L"argument 1", | 74 L"argument 1", |
75 L"argument 2", | 75 L"argument 2", |
76 }; | 76 }; |
77 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 77 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
78 } | 78 } |
79 | 79 |
80 { | 80 { |
81 SCOPED_TRACE("path with spaces"); | 81 SCOPED_TRACE("path with spaces"); |
82 | 82 |
83 const wchar_t* kArguments[] = { | 83 const wchar_t* const kArguments[] = { |
84 L"child.exe", | 84 L"child.exe", |
85 L"argument1", | 85 L"argument1", |
86 L"argument 2", | 86 L"argument 2", |
87 L"\\some\\path with\\spaces", | 87 L"\\some\\path with\\spaces", |
88 }; | 88 }; |
89 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 89 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
90 } | 90 } |
91 | 91 |
92 { | 92 { |
93 SCOPED_TRACE("argument with embedded quotation marks"); | 93 SCOPED_TRACE("argument with embedded quotation marks"); |
94 | 94 |
95 const wchar_t* kArguments[] = { | 95 const wchar_t* const kArguments[] = { |
96 L"child.exe", | 96 L"child.exe", |
97 L"argument1", | 97 L"argument1", |
98 L"she said, \"you had me at hello\"", | 98 L"she said, \"you had me at hello\"", |
99 L"\\some\\path with\\spaces", | 99 L"\\some\\path with\\spaces", |
100 }; | 100 }; |
101 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 101 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
102 } | 102 } |
103 | 103 |
104 { | 104 { |
105 SCOPED_TRACE("argument with unbalanced quotation marks"); | 105 SCOPED_TRACE("argument with unbalanced quotation marks"); |
106 | 106 |
107 const wchar_t* kArguments[] = { | 107 const wchar_t* const kArguments[] = { |
108 L"child.exe", | 108 L"child.exe", |
109 L"argument1", | 109 L"argument1", |
110 L"argument\"2", | 110 L"argument\"2", |
111 L"argument3", | 111 L"argument3", |
112 L"argument4", | 112 L"argument4", |
113 }; | 113 }; |
114 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 114 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
115 } | 115 } |
116 | 116 |
117 { | 117 { |
118 SCOPED_TRACE("argument ending with backslash"); | 118 SCOPED_TRACE("argument ending with backslash"); |
119 | 119 |
120 const wchar_t* kArguments[] = { | 120 const wchar_t* const kArguments[] = { |
121 L"child.exe", | 121 L"child.exe", |
122 L"\\some\\directory with\\spaces\\", | 122 L"\\some\\directory with\\spaces\\", |
123 L"argument2", | 123 L"argument2", |
124 }; | 124 }; |
125 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 125 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
126 } | 126 } |
127 | 127 |
128 { | 128 { |
129 SCOPED_TRACE("empty argument"); | 129 SCOPED_TRACE("empty argument"); |
130 | 130 |
131 const wchar_t* kArguments[] = { | 131 const wchar_t* const kArguments[] = { |
132 L"child.exe", | 132 L"child.exe", |
133 L"", | 133 L"", |
134 L"argument2", | 134 L"argument2", |
135 }; | 135 }; |
136 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 136 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
137 } | 137 } |
138 | 138 |
139 { | 139 { |
140 SCOPED_TRACE("funny nonprintable characters"); | 140 SCOPED_TRACE("funny nonprintable characters"); |
141 | 141 |
142 const wchar_t* kArguments[] = { | 142 const wchar_t* const kArguments[] = { |
143 L"child.exe", | 143 L"child.exe", |
144 L"argument 1", | 144 L"argument 1", |
145 L"argument\t2", | 145 L"argument\t2", |
146 L"argument\n3", | 146 L"argument\n3", |
147 L"argument\v4", | 147 L"argument\v4", |
148 L"argument\"5", | 148 L"argument\"5", |
149 L" ", | 149 L" ", |
150 L"\t", | 150 L"\t", |
151 L"\n", | 151 L"\n", |
152 L"\v", | 152 L"\v", |
(...skipping 15 matching lines...) Expand all Loading... |
168 L"\"\"", | 168 L"\"\"", |
169 L" \t\n\v\"", | 169 L" \t\n\v\"", |
170 }; | 170 }; |
171 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); | 171 AppendCommandLineArgumentTest(arraysize(kArguments), kArguments); |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 } // namespace | 175 } // namespace |
176 } // namespace test | 176 } // namespace test |
177 } // namespace crashpad | 177 } // namespace crashpad |
OLD | NEW |