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: Created Nov. 29, 2015, 3:49 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
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-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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(std::wstring input, std::wstring expected)
sergei 2015/11/30 12:37:54 It's not introduces in this change set but the com
Eric 2015/11/30 15:54:07 Done.
23 { 23 {
24 std::wstring trimmed = TrimString(input); 24 std::wstring trimmed = TrimString(input);
25 ASSERT_EQ(expected, trimmed); 25 ASSERT_EQ(expected, trimmed);
26 } 26 }
27
28 void TrimLeftTestBody(std::wstring input, std::wstring expected)
sergei 2015/11/30 12:37:54 Why not to pass arguments as constant references?
sergei 2015/11/30 12:37:54 It would be better to call it like ExpectEqualToLe
Eric 2015/11/30 15:54:07 I'm not going to bother with the renaming. I don't
Eric 2015/11/30 15:54:08 Done.
29 {
30 std::wstring trimmed = TrimStringLeft(input);
31 ASSERT_EQ(expected, trimmed);
sergei 2015/11/30 12:37:54 It should not stop the tests, could you please use
Eric 2015/11/30 15:54:07 Done.
32 }
33
34 void TrimRightTestBody(std::wstring input, std::wstring expected)
sergei 2015/11/30 12:37:54 ExpectEqualToRightTrimmed(expected, input);
sergei 2015/11/30 12:37:54 Same here, constant references
Eric 2015/11/30 15:54:07 Done.
35 {
36 std::wstring trimmed = TrimStringRight(input);
37 ASSERT_EQ(expected, trimmed);
sergei 2015/11/30 12:37:55 EXPECT_EQ
Eric 2015/11/30 15:54:07 Done.
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 TEST(TrimTest, TrimPassesByValue)
162 {
163 std::wstring x = L"foo bar "; // not declared 'const', coould alter
164 const std::wstring y = x;
165 ASSERT_EQ(y, x);
sergei 2015/11/30 12:37:54 EXPECT_EQ here and below
Eric 2015/11/30 15:54:08 This statement is largely documentation. It's here
166 std::wstring trimmed = TrimString(x); // expect here pass by value
sergei 2015/11/30 12:37:54 What if one calls it as `TrimString<std::wstring&>
Eric 2015/11/30 15:54:08 If you do that, you get in-place modification. I s
sergei 2015/11/30 16:36:03 Acknowledged. It's another issue, let's leave it.
167 ASSERT_EQ(L"foo bar", trimmed);
168 ASSERT_EQ(y, x); // argument variable not altered
169 }
170
171 TEST(TrimTest, TrimBindsOnConstArg)
sergei 2015/11/30 12:37:55 If it's an attempt to test whether there is some b
Eric 2015/11/30 15:54:07 It verifies the modification, yes. The real purpos
172 {
173 const std::wstring x = L"foo bar "; // declared 'const'
174 const std::wstring y = x;
175 ASSERT_EQ(y, x);
176 std::wstring trimmed = TrimString(x);
177 ASSERT_EQ(L"foo bar", trimmed);
178 ASSERT_EQ(y, x);
179 }
OLDNEW

Powered by Google App Engine
This is Rietveld