Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/UtilProcessQueryStringParameters.cpp

Issue 5921969115496448: Issue 1115 - Some yahoo page not correctly shown on IE8 when ABP enabled (Closed)
Patch Set: x Created Jan. 29, 2015, 3:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <fstream>
19 #include <Windows.h>
20 #include <gtest/gtest.h>
21
22 #include "../src/shared/Utils.h"
23
24 TEST(ProcessQueryStringParametersTest, EmptyParameterHandler)
25 {
26 ProcessQueryStringParameters(L"some=qyery&string", std::function<bool(const st d::wstring&, const std::wstring&)>());
Eric 2015/02/02 18:41:58 Use ASSERT_NO_THROW here to clearly indicate the i
sergei 2015/02/12 14:44:06 I've changed it, now it throws and there is ASSERT
27 }
28
29 TEST(ProcessQueryStringParametersTest, EmptyQueryString)
30 {
31 ProcessQueryStringParameters(L"", [](const std::wstring&, const std::wstring&) ->bool
32 {
33 EXPECT_FALSE(true); // it should not be called
34 return true;
35 });
36 }
37
38 TEST(ProcessQueryStringParametersTest, QueryStringWithOneNormalParameter)
39 {
40 std::wstring parameterName, parameterValue;
41 int callCounter = 0;
42 ProcessQueryStringParameters(L"param=value",
43 [&parameterName, &parameterValue, &callCounter](const std::wstring& name, co nst std::wstring& value)->bool
44 {
45 EXPECT_EQ(1, ++callCounter); // fails on the second call
46 parameterName = name;
47 parameterValue = value;
48 return true;
49 });
50 EXPECT_EQ(L"param", parameterName);
51 EXPECT_EQ(L"value", parameterValue);
52
53 callCounter = 0;
54 ProcessQueryStringParameters(L"param=value",
55 [&parameterName, &parameterValue, &callCounter](const std::wstring& name, co nst std::wstring& value)->bool
56 {
57 EXPECT_EQ(1, ++callCounter); // fails on the second call
58 parameterName = name;
59 parameterValue = value;
60 return false;
61 });
62 EXPECT_EQ(L"param", parameterName);
63 EXPECT_EQ(L"value", parameterValue);
64 }
65
66 TEST(ProcessQueryStringParametersTest, QueryStringWithSeveralNormalParameters)
67 {
68 std::pair<std::wstring, std::wstring> parameters[3];
69 int callCounter = 0;
70 ProcessQueryStringParameters(L"param1=value1&param2=value2&param3=value3",
71 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
72 {
73 parameters[callCounter].first = name;
74 parameters[callCounter].second = value;
75 ++callCounter;
76 return true;
77 });
Eric 2015/02/02 18:41:58 You've got some really horrible code duplication g
78 EXPECT_EQ(L"param1", parameters[0].first);
79 EXPECT_EQ(L"value1", parameters[0].second);
80 EXPECT_EQ(L"param2", parameters[1].first);
81 EXPECT_EQ(L"value2", parameters[1].second);
82 EXPECT_EQ(L"param3", parameters[2].first);
83 EXPECT_EQ(L"value3", parameters[2].second);
84 EXPECT_EQ(3, callCounter);
85 }
86
87 TEST(ProcessQueryStringParametersTest, QueryStringWithEmptyParameterAtTheEnd)
88 {
89 std::pair<std::wstring, std::wstring> parameters[2];
90 int callCounter = 0;
91 ProcessQueryStringParameters(L"param1=value1&",
92 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
93 {
94 parameters[callCounter].first = name;
95 parameters[callCounter].second = value;
96 ++callCounter;
97 return true;
98 });
Eric 2015/02/02 18:41:58 Since you're about to index a vector, you should f
99 EXPECT_EQ(L"param1", parameters[0].first);
100 EXPECT_EQ(L"value1", parameters[0].second);
101 EXPECT_EQ(L"", parameters[1].first);
102 EXPECT_EQ(L"", parameters[1].second);
103 EXPECT_EQ(2, callCounter);
104 }
105
106 TEST(ProcessQueryStringParametersTest, QueryStringWithEmptyParameterAtTheBeginni ng)
107 {
108 std::pair<std::wstring, std::wstring> parameters[2];
109 int callCounter = 0;
110 ProcessQueryStringParameters(L"&param1=value1",
111 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
112 {
113 parameters[callCounter].first = name;
114 parameters[callCounter].second = value;
115 ++callCounter;
116 return true;
117 });
118 EXPECT_EQ(L"", parameters[0].first);
119 EXPECT_EQ(L"", parameters[0].second);
120 EXPECT_EQ(L"param1", parameters[1].first);
121 EXPECT_EQ(L"value1", parameters[1].second);
122 EXPECT_EQ(2, callCounter);
123 }
124
125 TEST(ProcessQueryStringParametersTest, ParameterWithoutAssignSign)
126 {
127 std::pair<std::wstring, std::wstring> parameters;
128 int callCounter = 0;
129 ProcessQueryStringParameters(L"param1",
130 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
131 {
132 parameters.first = name;
133 parameters.second = value;
134 ++callCounter;
135 return true;
136 });
137 EXPECT_EQ(L"param1", parameters.first);
138 EXPECT_EQ(L"", parameters.second);
139 EXPECT_EQ(1, callCounter);
140 }
141
142 TEST(ProcessQueryStringParametersTest, ParametersWithoutAssignSign)
143 {
144 std::pair<std::wstring, std::wstring> parameters[3];
145 int callCounter = 0;
146 ProcessQueryStringParameters(L"param1&param2&param3",
147 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
148 {
149 parameters[callCounter].first = name;
150 parameters[callCounter].second = value;
151 ++callCounter;
152 return true;
153 });
154 EXPECT_EQ(L"param1", parameters[0].first);
155 EXPECT_EQ(L"", parameters[0].second);
156 EXPECT_EQ(L"param2", parameters[1].first);
157 EXPECT_EQ(L"", parameters[1].second);
158 EXPECT_EQ(L"param3", parameters[2].first);
159 EXPECT_EQ(L"", parameters[2].second);
160 EXPECT_EQ(3, callCounter);
161 }
162
163 TEST(ProcessQueryStringParametersTest, ParameterWithSeveralAssignSigns)
164 {
165 std::pair<std::wstring, std::wstring> parameters;
166 int callCounter = 0;
167 ProcessQueryStringParameters(L"param1=value1.1=value1.2",
168 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
169 {
170 parameters.first = name;
171 parameters.second = value;
172 ++callCounter;
173 return true;
174 });
175 EXPECT_EQ(L"param1", parameters.first);
176 EXPECT_EQ(L"value1.1=value1.2", parameters.second);
177 EXPECT_EQ(1, callCounter);
178 }
179
180 TEST(ProcessQueryStringParametersTest, ParameterWithEmptyValue)
181 {
182 std::pair<std::wstring, std::wstring> parameters;
183 int callCounter = 0;
184 ProcessQueryStringParameters(L"param1=",
185 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
186 {
187 parameters.first = name;
188 parameters.second = value;
189 ++callCounter;
190 return true;
191 });
192 EXPECT_EQ(L"param1", parameters.first);
193 EXPECT_EQ(L"", parameters.second);
194 EXPECT_EQ(1, callCounter);
195 }
196
197 TEST(ProcessQueryStringParametersTest, StopProcessingWhenHandlerReturnsFalse)
198 {
199 std::pair<std::wstring, std::wstring> parameters[3];
200 int callCounter = 0;
201 ProcessQueryStringParameters(L"param1=value1&param2=value2&param3=value3",
202 [&parameters, &callCounter](const std::wstring& name, const std::wstring& va lue)->bool
203 {
204 parameters[callCounter].first = name;
205 parameters[callCounter].second = value;
206 ++callCounter;
207 return callCounter < 2;
208 });
209 EXPECT_EQ(L"param1", parameters[0].first);
210 EXPECT_EQ(L"value1", parameters[0].second);
211 EXPECT_EQ(L"param2", parameters[1].first);
212 EXPECT_EQ(L"value2", parameters[1].second);
213 EXPECT_EQ(L"", parameters[2].first);
214 EXPECT_EQ(L"", parameters[2].second);
215 EXPECT_EQ(2, callCounter);
216 }
OLDNEW

Powered by Google App Engine
This is Rietveld