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

Side by Side Diff: test/UtilTest.cpp

Issue 29331055: Issue #1234 - Remove 'CString' from PluginFilter.* (Closed)
Patch Set: fix whitespace nit Created May 17, 2016, 6:40 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
« no previous file with comments | « src/shared/Utils.h ('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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 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 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 #include <gtest/gtest.h> 17 #include <gtest/gtest.h>
18 #include "../src/shared/Utils.h" 18 #include "../src/shared/Utils.h"
19 19
20 namespace 20 namespace
21 { 21 {
22 void TrimTestBody(std::wstring input, std::wstring expected) 22 void TrimTestBody(const std::wstring& input, const std::wstring& expected)
23 { 23 {
24 std::wstring trimmed = TrimString(input); 24 std::wstring trimmed = TrimString(input);
25 ASSERT_EQ(expected, trimmed); 25 EXPECT_EQ(expected, trimmed);
26 }
27
28 void TrimLeftTestBody(const std::wstring& input, const std::wstring& expected)
29 {
30 std::wstring trimmed = TrimStringLeft(input);
31 EXPECT_EQ(expected, trimmed);
32 }
33
34 void TrimRightTestBody(const std::wstring& input, const std::wstring& expected )
35 {
36 std::wstring trimmed = TrimStringRight(input);
37 EXPECT_EQ(expected, trimmed);
26 } 38 }
27 } 39 }
28 40
29 TEST(TrimTest, Trim00) 41 TEST(TrimTest, Trim00)
30 { 42 {
31 TrimTestBody(L"", L""); 43 const std::wstring x = L"";
44 TrimTestBody(x, L"");
45 TrimLeftTestBody(x, L"");
46 TrimRightTestBody(x, L"");
32 } 47 }
33 48
34 TEST(TrimTest, Trim01) 49 TEST(TrimTest, Trim01)
35 { 50 {
36 TrimTestBody(L" ", L""); 51 const std::wstring x = L" ";
52 TrimTestBody(x, L"");
53 TrimLeftTestBody(x, L"");
54 TrimRightTestBody(x, L"");
37 } 55 }
38 56
39 TEST(TrimTest, Trim02) 57 TEST(TrimTest, Trim02)
40 { 58 {
41 TrimTestBody(L"\n", L""); 59 const std::wstring x = L"\n";
60 TrimTestBody(x, L"");
61 TrimLeftTestBody(x, L"");
62 TrimRightTestBody(x, L"");
42 } 63 }
43 64
44 TEST(TrimTest, Trim03) 65 TEST(TrimTest, Trim03)
45 { 66 {
46 TrimTestBody(L"\r", L""); 67 const std::wstring x = L"\r";
68 TrimTestBody(x, L"");
69 TrimLeftTestBody(x, L"");
70 TrimRightTestBody(x, L"");
47 } 71 }
48 72
49 TEST(TrimTest, Trim04) 73 TEST(TrimTest, Trim04)
50 { 74 {
51 TrimTestBody(L"\t", L""); 75 const std::wstring x = L"\t";
76 TrimTestBody(x, L"");
77 TrimLeftTestBody(x, L"");
78 TrimRightTestBody(x, L"");
52 } 79 }
53 80
54 TEST(TrimTest, Trim05) 81 TEST(TrimTest, Trim05)
55 { 82 {
56 TrimTestBody(L"foo", L"foo"); 83 const std::wstring x = L"foo";
84 TrimTestBody(x, L"foo");
85 TrimLeftTestBody(x, L"foo");
86 TrimRightTestBody(x, L"foo");
57 } 87 }
58 88
59 TEST(TrimTest, Trim06) 89 TEST(TrimTest, Trim06)
60 { 90 {
61 TrimTestBody(L" foo", L"foo"); 91 const std::wstring x = L" foo";
92 TrimTestBody(x, L"foo");
93 TrimLeftTestBody(x, L"foo");
94 TrimRightTestBody(x, L" foo");
62 } 95 }
63 96
64 TEST(TrimTest, Trim07) 97 TEST(TrimTest, Trim07)
65 { 98 {
66 TrimTestBody(L"\r\nfoo", L"foo"); 99 const std::wstring x = L"\r\nfoo";
100 TrimTestBody(x, L"foo");
101 TrimLeftTestBody(x, L"foo");
102 TrimRightTestBody(x, L"\r\nfoo");
67 } 103 }
68 104
69 TEST(TrimTest, Trim08) 105 TEST(TrimTest, Trim08)
70 { 106 {
71 TrimTestBody(L"\tfoo", L"foo"); 107 const std::wstring x = L"\tfoo";
108 TrimTestBody(x, L"foo");
109 TrimLeftTestBody(x, L"foo");
110 TrimRightTestBody(x, L"\tfoo");
72 } 111 }
73 112
74 TEST(TrimTest, Trim09) 113 TEST(TrimTest, Trim09)
75 { 114 {
76 TrimTestBody(L"foo ", L"foo"); 115 const std::wstring x = L"foo ";
116 TrimTestBody(x, L"foo");
117 TrimLeftTestBody(x, L"foo ");
118 TrimRightTestBody(x, L"foo");
77 } 119 }
78 120
79 TEST(TrimTest, Trim10) 121 TEST(TrimTest, Trim10)
80 { 122 {
81 TrimTestBody(L"foo\r\n", L"foo"); 123 const std::wstring x = L"foo\r\n";
124 TrimTestBody(x, L"foo");
125 TrimLeftTestBody(x, L"foo\r\n");
126 TrimRightTestBody(x, L"foo");
82 } 127 }
83 128
84 TEST(TrimTest, Trim11) 129 TEST(TrimTest, Trim11)
85 { 130 {
86 TrimTestBody(L"foo\t", L"foo"); 131 const std::wstring x = L"foo\t";
132 TrimTestBody(x, L"foo");
133 TrimLeftTestBody(x, L"foo\t");
134 TrimRightTestBody(x, L"foo");
87 } 135 }
88 136
89 TEST(TrimTest, Trim12) 137 TEST(TrimTest, Trim12)
90 { 138 {
91 TrimTestBody(L"foo bar", L"foo bar"); 139 const std::wstring x = L"foo bar";
140 TrimTestBody(x, L"foo bar");
141 TrimLeftTestBody(x, L"foo bar");
142 TrimRightTestBody(x, L"foo bar");
92 } 143 }
93 144
94 TEST(TrimTest, Trim13) 145 TEST(TrimTest, Trim13)
95 { 146 {
96 TrimTestBody(L"foo bar \r\n", L"foo bar"); 147 const std::wstring x = L"foo bar \r\n";
148 TrimTestBody(x, L"foo bar");
149 TrimLeftTestBody(x, L"foo bar \r\n");
150 TrimRightTestBody(x, L"foo bar");
97 } 151 }
98 152
99 TEST(TrimTest, Trim14) 153 TEST(TrimTest, Trim14)
100 { 154 {
101 TrimTestBody(L" foo bar \r\n", L"foo bar"); 155 const std::wstring x = L" foo bar \r\n";
156 TrimTestBody(x, L"foo bar");
157 TrimLeftTestBody(x, L"foo bar \r\n");
158 TrimRightTestBody(x, L" foo bar");
102 } 159 }
160
161 /*
162 * First of two tests verifying that TrimString() does not alter its argument.
163 * This one tests an ordinary, non-const variable as an argument.
164 * It differs from its companion only in the one line that declares the variable used as an argument.
165 */
166 TEST(TrimTest, TrimPassesByValue)
167 {
168 std::wstring x = L"foo bar "; // not declared 'const', could alter
169 const std::wstring y = x;
170 ASSERT_EQ(y, x);
171 std::wstring trimmed = TrimString(x); // expect here pass by value
172 EXPECT_EQ(L"foo bar", trimmed);
173 ASSERT_EQ(y, x); // argument variable not altered
174 }
175
176 /*
177 * Second of two tests verifying that TrimString() does not alter its argument.
178 * This one tests a const variable as an argument.
179 */
180 TEST(TrimTest, TrimBindsOnConstArg)
181 {
182 const std::wstring x = L"foo bar "; // declared 'const'
183 const std::wstring y = x;
184 ASSERT_EQ(y, x);
185 std::wstring trimmed = TrimString(x);
186 EXPECT_EQ(L"foo bar", trimmed);
187 ASSERT_EQ(y, x);
188 }
OLDNEW
« no previous file with comments | « src/shared/Utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld