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

Side by Side Diff: test/UtilSplitString.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 */
Eric 2015/02/02 18:41:58 Many of the same comments from the previous file a
17
18 #include <fstream>
19 #include <Windows.h>
20 #include <gtest/gtest.h>
21
22 #include "../src/shared/Utils.h"
23
24 TEST(SplitStringTest, EmptyHandler)
25 {
26 SplitString(L"aaa!asdasd!", L'!', std::function<bool(std::wstring::const_itera tor, std::wstring::const_iterator)>());
27 }
28
29 TEST(SplitStringTest, EmptyQueryString)
30 {
31 bool isCalled = false;
32 SplitString(L"", L'\0', [&isCalled](std::wstring::const_iterator, std::wstring ::const_iterator)->bool
33 {
34 return isCalled = true;
35 });
36 EXPECT_FALSE(isCalled);
37 }
38
39 TEST(SplitStringTest, StringWithoutDelimiter)
40 {
41 std::wstring value;
42 bool isCalled = false;
43 SplitString(L"value", L'D', [&value, &isCalled](std::wstring::const_iterator b egin, std::wstring::const_iterator end)->bool
44 {
45 EXPECT_FALSE(isCalled);
46 isCalled = true;
47 value.assign(begin, end);
48 return true;
49 });
50 EXPECT_EQ(L"value", value);
51 }
52
53 TEST(SplitStringTest, StringWithDelimiter)
54 {
55 std::wstring value[2];
56 int callNumber = 0;
57 SplitString(L"value1&value2", L'&', [&value, &callNumber](std::wstring::const_ iterator begin, std::wstring::const_iterator end)->bool
58 {
59 value[callNumber++].assign(begin, end);
60 return true;
61 });
62 EXPECT_EQ(L"value1", value[0]);
63 EXPECT_EQ(L"value2", value[1]);
64 EXPECT_EQ(2, callNumber);
65 }
66
67 TEST(SplitStringTest, StringWithDelimiterAtTheEnd)
68 {
69 std::wstring value[3];
70 int callNumber = 0;
71 SplitString(L"value1&value2&", L'&', [&value, &callNumber](std::wstring::const _iterator begin, std::wstring::const_iterator end)->bool
72 {
73 value[callNumber++].assign(begin, end);
74 return true;
75 });
76 EXPECT_EQ(L"value1", value[0]);
77 EXPECT_EQ(L"value2", value[1]);
78 EXPECT_EQ(L"", value[2]);
79 EXPECT_EQ(3, callNumber);
80 }
81
82 TEST(SplitStringTest, StringWithDelimiterAtTheBeginning)
83 {
84 std::wstring value[3];
85 int callNumber = 0;
86 SplitString(L"&value1&value2", L'&', [&value, &callNumber](std::wstring::const _iterator begin, std::wstring::const_iterator end)->bool
87 {
88 value[callNumber++].assign(begin, end);
89 return true;
90 });
91 EXPECT_EQ(L"", value[0]);
92 EXPECT_EQ(L"value1", value[1]);
93 EXPECT_EQ(L"value2", value[2]);
94 EXPECT_EQ(3, callNumber);
95 }
96
97 TEST(SplitStringTest, StringWithOnlyDelimiters)
98 {
99 std::wstring value[4];
100 int callNumber = 0;
101 SplitString(L"&&&", L'&', [&value, &callNumber](std::wstring::const_iterator b egin, std::wstring::const_iterator end)->bool
102 {
103 value[callNumber++].assign(begin, end);
104 return true;
105 });
106 EXPECT_EQ(L"", value[0]);
107 EXPECT_EQ(L"", value[1]);
108 EXPECT_EQ(L"", value[2]);
109 EXPECT_EQ(L"", value[3]);
110 EXPECT_EQ(4, callNumber);
111 }
112
113 TEST(SplitStringTest, ProcessUntilHandlerReturnsFalse)
114 {
115 int callNumber = 0;
116 // handler is called three times
117 SplitString(L"&&&&&&", L'&', [&callNumber](std::wstring::const_iterator begin, std::wstring::const_iterator end)->bool
118 {
119 return ++callNumber <= 2;
120 });
121 EXPECT_EQ(3, callNumber);
122 }
OLDNEW
« test/UtilProcessQueryStringParameters.cpp ('K') | « test/UtilProcessQueryStringParameters.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld