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

Delta Between Two Patch Sets: test/CommunicationTest.cpp

Issue 4882650246414336: Issue 2005 - Refactor working with strings in InputBuffer and OutputBuffer
Left Patch Set: fix forgotten sizeof and add check for string length Created Feb. 18, 2015, 2:37 p.m.
Right Patch Set: rebase Created April 2, 2015, 11:09 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/shared/Communication.h ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2014 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 *
(...skipping 20 matching lines...) Expand all
34 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 34 std::this_thread::sleep_for(std::chrono::milliseconds(100));
35 ASSERT_NO_THROW(Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_C ONNECT)); 35 ASSERT_NO_THROW(Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_C ONNECT));
36 serverThread.join(); 36 serverThread.join();
37 } 37 }
38 38
39 TEST(CommunicationTest, PipeSendReceive) 39 TEST(CommunicationTest, PipeSendReceive)
40 { 40 {
41 std::unique_ptr<Communication::Pipe> client; 41 std::unique_ptr<Communication::Pipe> client;
42 auto clientThread = std::thread([&client] 42 auto clientThread = std::thread([&client]
43 { 43 {
44 while(!client) 44 for (int i = 0; !client && i < 100; ++i)
Eric 2015/02/18 18:12:47 There's the possibility of an infinite loop if the
sergei 2015/02/19 17:26:57 I've added the counter and changed `yeild` by `sle
Eric 2015/05/14 13:53:38 There's no need to guard the loop with the term "!
sergei 2015/05/15 09:45:55 Before declaration of `clientThread` `client` is a
45 { 45 {
46 try 46 try
47 { 47 {
48 client.reset(new Communication::Pipe(pipeName, Communication::Pipe::MODE _CONNECT)); 48 client.reset(new Communication::Pipe(pipeName, Communication::Pipe::MODE _CONNECT));
49 } 49 }
50 catch(...) 50 catch(...)
51 { 51 {
52 std::this_thread::yield(); 52 std::this_thread::sleep_for(i * std::chrono::milliseconds(20));
53 } 53 }
54 } 54 }
55 }); 55 });
56 Communication::Pipe server(pipeName, Communication::Pipe::MODE_CREATE); 56 Communication::Pipe server(pipeName, Communication::Pipe::MODE_CREATE);
Eric 2015/02/18 18:12:47 Shouldn't creating the pipe come before connecting
sergei 2015/02/19 17:26:57 This particular test is aimed to exercise the send
57 clientThread.join(); 57 clientThread.join();
58 58 ASSERT_TRUE(client);
Eric 2015/05/14 13:53:38 This assertion should appear before the declaratio
59 // send to the server 59 // send to the server
60 { 60 {
61 Communication::OutputBuffer message; 61 Communication::OutputBuffer message;
62 message << Communication::ProcType::PROC_IS_WHITELISTED_URL 62 message << Communication::ProcType::PROC_GET_WHITELISTING_FITER
63 << std::string("This is a test message") << 64ll << 32 << true << false; 63 << std::string("This is a test message") << 64ll << 32 << true << false;
64 client->WriteMessage(message); 64 client->WriteMessage(message);
65 } 65 }
66 // receive on the server and send back 66 // receive on the server and send back
67 { 67 {
68 Communication::OutputBuffer response; 68 Communication::OutputBuffer response;
69 Communication::InputBuffer message = server.ReadMessage(); 69 Communication::InputBuffer message = server.ReadMessage();
70 Communication::ProcType proc; 70 Communication::ProcType proc;
71 message >> proc; 71 message >> proc;
72 EXPECT_EQ(Communication::ProcType::PROC_IS_WHITELISTED_URL, proc); 72 EXPECT_EQ(Communication::ProcType::PROC_GET_WHITELISTING_FITER, proc);
73 response << Communication::ProcType::PROC_IS_FIRST_RUN_ACTION_NEEDED; 73 response << Communication::ProcType::PROC_IS_FIRST_RUN_ACTION_NEEDED;
74 74
75 std::string text; 75 std::string text;
76 message >> text; 76 message >> text;
77 EXPECT_EQ("This is a test message", text); 77 EXPECT_EQ("This is a test message", text);
78 response << std::string("Response"); 78 response << std::string("Response");
79 79
80 int64_t integer64; 80 int64_t integer64;
81 message >> integer64; 81 message >> integer64;
82 EXPECT_EQ(64ll, integer64); 82 EXPECT_EQ(64ll, integer64);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 { 148 {
149 SendReceiveTypes(Communication::ProcType::PROC_GET_ELEMHIDE_SELECTORS, std::st ring("non-ProcType")); 149 SendReceiveTypes(Communication::ProcType::PROC_GET_ELEMHIDE_SELECTORS, std::st ring("non-ProcType"));
150 } 150 }
151 151
152 TEST(CommunicationTest, TypeString) 152 TEST(CommunicationTest, TypeString)
153 { 153 {
154 int32_t nonStringTypeValue = 10; 154 int32_t nonStringTypeValue = 10;
155 SendReceiveTypes(std::string("stringValue"), nonStringTypeValue); 155 SendReceiveTypes(std::string("stringValue"), nonStringTypeValue);
156 } 156 }
157 157
158 TEST(CommunicationTest, SendReceiveEmptyString) 158 TEST(CommunicationTest, SendReceiveEmptyString)
Eric 2015/02/18 18:12:47 How about 'TypeStringNarrowEmpty'?
sergei 2015/02/19 17:26:57 For this case and below, TypeString is not what we
159 { 159 {
160 Communication::OutputBuffer message; 160 Communication::OutputBuffer message;
161 message << std::string(); 161 message << std::string();
162 Communication::InputBuffer response(message.Get()); 162 Communication::InputBuffer response(message.Get());
163 std::string received = "clean me"; 163 std::string received = "clean me";
164 response >> received; 164 response >> received;
165 EXPECT_EQ("", received); 165 EXPECT_EQ("", received);
166 } 166 }
167 167
168 TEST(CommunicationTest, TypeStringSendWideReceiveWide) 168 TEST(CommunicationTest, TypeStringSendWideReceiveWide)
169 { 169 {
170 int32_t nonStringTypeValue = 10; 170 int32_t nonStringTypeValue = 10;
171 SendReceiveTypes(std::wstring(L"stringValue"), nonStringTypeValue); 171 SendReceiveTypes(std::wstring(L"stringValue"), nonStringTypeValue);
172 } 172 }
173 173
174 TEST(CommunicationTest, SendString_ReceiveWString) 174 TEST(CommunicationTest, SendString_ReceiveWString)
Eric 2015/02/18 18:12:47 How about 'TypeStringSendNarrowReceiveWide'?
175 { 175 {
176 Communication::OutputBuffer message; 176 Communication::OutputBuffer message;
177 message << std::string("test"); 177 message << std::string("test");
178 Communication::InputBuffer response(message.Get()); 178 Communication::InputBuffer response(message.Get());
179 std::wstring received; 179 std::wstring received;
180 response >> received; 180 response >> received;
181 EXPECT_EQ(L"test", received); 181 EXPECT_EQ(L"test", received);
182 } 182 }
183 183
184 TEST(CommunicationTest, SendWString_ReceiveString) 184 TEST(CommunicationTest, SendWString_ReceiveString)
Eric 2015/02/18 18:12:47 How about 'TypeStringSendWideReceiveNarrow'?
185 { 185 {
186 Communication::OutputBuffer message; 186 Communication::OutputBuffer message;
187 message << std::wstring(L"test"); 187 message << std::wstring(L"test");
188 Communication::InputBuffer response(message.Get()); 188 Communication::InputBuffer response(message.Get());
189 std::string received; 189 std::string received;
190 response >> received; 190 response >> received;
191 EXPECT_EQ("test", received); 191 EXPECT_EQ("test", received);
192 } 192 }
193 193
194 TEST(CommunicationTest, SendStrings_ReceiveWStrings) 194 TEST(CommunicationTest, SendStrings_ReceiveWStrings)
Eric 2015/02/18 18:12:47 How about 'TypeStringSendNarrowReceiveWide'?
195 { 195 {
196 Communication::OutputBuffer message; 196 Communication::OutputBuffer message;
197 std::vector<std::string> strings; 197 std::vector<std::string> strings;
198 strings.emplace_back("test0"); 198 strings.emplace_back("test0");
199 strings.emplace_back("test1"); 199 strings.emplace_back("test1");
200 message << strings; 200 message << strings;
201 Communication::InputBuffer response(message.Get()); 201 Communication::InputBuffer response(message.Get());
202 std::vector<std::wstring> received; 202 std::vector<std::wstring> received;
203 response >> received; 203 response >> received;
204 ASSERT_EQ(2u, received.size()); 204 ASSERT_EQ(2u, received.size());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 { 243 {
244 Communication::OutputBuffer outputBuffer; 244 Communication::OutputBuffer outputBuffer;
245 outputBuffer << src; 245 outputBuffer << src;
246 Communication::InputBuffer inputBuffer(outputBuffer.Get()); 246 Communication::InputBuffer inputBuffer(outputBuffer.Get());
247 std::vector<std::wstring> dst; 247 std::vector<std::wstring> dst;
248 inputBuffer >> dst; 248 inputBuffer >> dst;
249 return dst; 249 return dst;
250 } 250 }
251 } 251 }
252 252
253 TEST(InputOutputBuffersTests, InputOutputBufferEmptyStrings) 253 TEST(InputOutputBuffersTest, EmptyStrings)
Eric 2015/02/18 18:12:47 Consistent naming would start this name and below
sergei 2015/02/19 17:26:57 We don't start test names with Test. I've fixed 'I
254 { 254 {
255 SendReceiveStrings(std::vector<std::string>()); 255 SendReceiveStrings(std::vector<std::string>());
256 } 256 }
257 257
258 TEST(InputOutputBuffersTests, InputOutputBufferEmptyStringsToWideStrings) 258 TEST(InputOutputBuffersTest, EmptyStringsToWideStrings)
259 { 259 {
260 EXPECT_EQ(0u, SendReceiveStringsToWStrings(std::vector<std::string>()).size()) ; 260 EXPECT_EQ(0u, SendReceiveStringsToWStrings(std::vector<std::string>()).size()) ;
261 } 261 }
262 262
263 TEST(InputOutputBuffersTests, InputOutputBufferStringsWithOneValue) 263 TEST(InputOutputBuffersTest, StringsWithOneValue)
264 { 264 {
265 std::vector<std::string> src; 265 std::vector<std::string> src;
266 src.emplace_back("string1"); 266 src.emplace_back("string1");
267 SendReceiveStrings(src); 267 SendReceiveStrings(src);
268 } 268 }
269 269
270 TEST(InputOutputBuffersTests, InputOutputBufferStringsWithOneValueToWStrings) 270 TEST(InputOutputBuffersTest, StringsWithOneValueToWStrings)
271 { 271 {
272 std::vector<std::string> src; 272 std::vector<std::string> src;
273 src.emplace_back("string1"); 273 src.emplace_back("string1");
274 auto dst = SendReceiveStringsToWStrings(src); 274 auto dst = SendReceiveStringsToWStrings(src);
275 ASSERT_EQ(1u, dst.size()); 275 ASSERT_EQ(1u, dst.size());
276 EXPECT_EQ(L"string1", dst[0]); 276 EXPECT_EQ(L"string1", dst[0]);
277 } 277 }
278 278
279 TEST(InputOutputBuffersTests, InputOutputBufferWithMultivalueStrings) 279 TEST(InputOutputBuffersTest, WithMultivalueStrings)
280 { 280 {
281 std::vector<std::string> src; 281 std::vector<std::string> src;
282 src.emplace_back("string1"); 282 src.emplace_back("string1");
283 src.emplace_back("str2"); 283 src.emplace_back("str2");
284 src.emplace_back("value"); 284 src.emplace_back("value");
285 SendReceiveStrings(src); 285 SendReceiveStrings(src);
286 } 286 }
287 287
288 TEST(InputOutputBuffersTests, InputOutputBufferWithMultivalueStringsToWStrings) 288 TEST(InputOutputBuffersTest, WithMultivalueStringsToWStrings)
289 { 289 {
290 std::vector<std::string> src; 290 std::vector<std::string> src;
291 src.emplace_back("string1"); 291 src.emplace_back("string1");
292 src.emplace_back("str2"); 292 src.emplace_back("str2");
293 src.emplace_back("value"); 293 src.emplace_back("value");
294 auto dst = SendReceiveStringsToWStrings(src); 294 auto dst = SendReceiveStringsToWStrings(src);
295 ASSERT_EQ(3u, dst.size()); 295 ASSERT_EQ(3u, dst.size());
296 EXPECT_EQ(L"string1", dst[0]); 296 EXPECT_EQ(L"string1", dst[0]);
297 EXPECT_EQ(L"str2", dst[1]); 297 EXPECT_EQ(L"str2", dst[1]);
298 EXPECT_EQ(L"value", dst[2]); 298 EXPECT_EQ(L"value", dst[2]);
299 } 299 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld