 Issue 4882650246414336:
  Issue 2005 - Refactor working with strings in InputBuffer and OutputBuffer
    
  
    Issue 4882650246414336:
  Issue 2005 - Refactor working with strings in InputBuffer and OutputBuffer 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 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 for (int i = 0; !client && i < 100; ++i) | 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::sleep_for(i * std::chrono::milliseconds(20)); | 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 ASSERT_TRUE(client); | 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 } | 
| LEFT | RIGHT |