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: rebase Created Feb. 19, 2015, 2:11 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://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
(...skipping 23 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/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);
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 160 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)
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