Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 146 |
147 TEST(CommunicationTest, TypeProc) | 147 TEST(CommunicationTest, TypeProc) |
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 } | |
157 | |
158 TEST(CommunicationTest, SendReceiveEmptyString) | |
159 { | |
160 Communication::OutputBuffer message; | |
161 message << std::string(); | |
162 Communication::InputBuffer response(message.Get()); | |
163 std::string received = "clean me"; | |
164 response >> received; | |
165 EXPECT_EQ("", received); | |
156 } | 166 } |
157 | 167 |
158 TEST(CommunicationTest, TypeStringSendWideReceiveWide) | 168 TEST(CommunicationTest, TypeStringSendWideReceiveWide) |
159 { | 169 { |
160 int32_t nonStringTypeValue = 10; | 170 int32_t nonStringTypeValue = 10; |
161 SendReceiveTypes(std::wstring(L"stringValue"), nonStringTypeValue); | 171 SendReceiveTypes(std::wstring(L"stringValue"), nonStringTypeValue); |
162 } | 172 } |
163 | 173 |
164 TEST(CommunicationTest, SendString_ReceiveWString) | 174 TEST(CommunicationTest, SendString_ReceiveWString) |
165 { | 175 { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 { | 243 { |
234 Communication::OutputBuffer outputBuffer; | 244 Communication::OutputBuffer outputBuffer; |
235 outputBuffer << src; | 245 outputBuffer << src; |
236 Communication::InputBuffer inputBuffer(outputBuffer.Get()); | 246 Communication::InputBuffer inputBuffer(outputBuffer.Get()); |
237 std::vector<std::wstring> dst; | 247 std::vector<std::wstring> dst; |
238 inputBuffer >> dst; | 248 inputBuffer >> dst; |
239 return dst; | 249 return dst; |
240 } | 250 } |
241 } | 251 } |
242 | 252 |
243 TEST(InputOutputBuffersTests, InputOutputBufferEmptyStrings) | 253 TEST(InputOutputBuffersTest, EmptyStrings) |
244 { | 254 { |
245 SendReceiveStrings(std::vector<std::string>()); | 255 SendReceiveStrings(std::vector<std::string>()); |
246 } | 256 } |
247 | 257 |
248 TEST(InputOutputBuffersTests, InputOutputBufferEmptyStringsToWideStrings) | 258 TEST(InputOutputBuffersTest, EmptyStringsToWideStrings) |
249 { | 259 { |
250 EXPECT_EQ(0u, SendReceiveStringsToWStrings(std::vector<std::string>()).size()) ; | 260 EXPECT_EQ(0u, SendReceiveStringsToWStrings(std::vector<std::string>()).size()) ; |
251 } | 261 } |
252 | 262 |
253 TEST(InputOutputBuffersTests, InputOutputBufferStringsWithOneValue) | 263 TEST(InputOutputBuffersTest, StringsWithOneValue) |
254 { | 264 { |
255 std::vector<std::string> src; | 265 std::vector<std::string> src; |
256 src.emplace_back("string1"); | 266 src.emplace_back("string1"); |
257 SendReceiveStrings(src); | 267 SendReceiveStrings(src); |
258 } | 268 } |
259 | 269 |
260 TEST(InputOutputBuffersTests, InputOutputBufferStringsWithOneValueToWStrings) | 270 TEST(InputOutputBuffersTest, StringsWithOneValueToWStrings) |
261 { | 271 { |
262 std::vector<std::string> src; | 272 std::vector<std::string> src; |
263 src.emplace_back("string1"); | 273 src.emplace_back("string1"); |
264 auto dst = SendReceiveStringsToWStrings(src); | 274 auto dst = SendReceiveStringsToWStrings(src); |
265 ASSERT_EQ(1u, dst.size()); | 275 ASSERT_EQ(1u, dst.size()); |
266 EXPECT_EQ(L"string1", dst[0]); | 276 EXPECT_EQ(L"string1", dst[0]); |
267 } | 277 } |
268 | 278 |
269 TEST(InputOutputBuffersTests, InputOutputBufferWithMultivalueStrings) | 279 TEST(InputOutputBuffersTest, WithMultivalueStrings) |
270 { | 280 { |
271 std::vector<std::string> src; | 281 std::vector<std::string> src; |
272 src.emplace_back("string1"); | 282 src.emplace_back("string1"); |
273 src.emplace_back("str2"); | 283 src.emplace_back("str2"); |
274 src.emplace_back("value"); | 284 src.emplace_back("value"); |
275 SendReceiveStrings(src); | 285 SendReceiveStrings(src); |
276 } | 286 } |
277 | 287 |
278 TEST(InputOutputBuffersTests, InputOutputBufferWithMultivalueStringsToWStrings) | 288 TEST(InputOutputBuffersTest, WithMultivalueStringsToWStrings) |
279 { | 289 { |
280 std::vector<std::string> src; | 290 std::vector<std::string> src; |
281 src.emplace_back("string1"); | 291 src.emplace_back("string1"); |
282 src.emplace_back("str2"); | 292 src.emplace_back("str2"); |
283 src.emplace_back("value"); | 293 src.emplace_back("value"); |
284 auto dst = SendReceiveStringsToWStrings(src); | 294 auto dst = SendReceiveStringsToWStrings(src); |
285 ASSERT_EQ(3u, dst.size()); | 295 ASSERT_EQ(3u, dst.size()); |
286 EXPECT_EQ(L"string1", dst[0]); | 296 EXPECT_EQ(L"string1", dst[0]); |
287 EXPECT_EQ(L"str2", dst[1]); | 297 EXPECT_EQ(L"str2", dst[1]); |
288 EXPECT_EQ(L"value", dst[2]); | 298 EXPECT_EQ(L"value", dst[2]); |
289 } | 299 } |
LEFT | RIGHT |