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

Side by Side Diff: test/CommunicationTest.cpp

Issue 10786016: Moved all pipe functionality into a self-containing Communication::Pipe class (Closed)
Patch Set: Created May 31, 2013, 11:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« src/shared/Communication.cpp ('K') | « src/shared/Communication.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 #include <gtest/gtest.h>
19
20 #include "../src/shared/AutoHandle.h"
21 #include "../src/shared/Communication.h"
22
23 const std::wstring pipeName(L"\\\\.\\pipe\\adblockplustests");
24
25 namespace
26 {
27 DWORD WINAPI CreatePipe(LPVOID param)
28 {
29 Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CREATE);
30 return 0;
31 }
32
33 DWORD WINAPI ReceiveSend(LPVOID param)
34 {
35 Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CREATE);
36
37 Communication::InputBuffer message = pipe.ReadMessage();
38
39 std::string stringValue;
40 std::wstring wstringValue;
41 int64_t int64Value;
42 int32_t int32Value;
43 bool boolValue;
44 message >> stringValue >> wstringValue >> int64Value >> int32Value >> boolVa lue;
45
46 stringValue += " Received";
47 wstringValue += L" \u043f\u0440\u0438\u043d\u044f\u0442\u043e";
48 int64Value += 1;
49 int32Value += 2;
50 boolValue = !boolValue;
51
52 Communication::OutputBuffer response;
53 response << stringValue << wstringValue << int64Value << int32Value << boolV alue;
54 pipe.WriteMessage(response);
55
56 return 0;
57 }
58 }
59
60 TEST(CommunicationTest, ConnectPipe)
61 {
62 AutoHandle thread(CreateThread(0, 0, CreatePipe, 0, 0, 0));
63
64 Sleep(100);
65
66 ASSERT_NO_THROW(Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_C ONNECT));
67 }
68
69 TEST(CommunicationTest, SendReceive)
70 {
71 AutoHandle thread(CreateThread(0, 0, ReceiveSend, 0, 0, 0));
72
73 Sleep(100);
74
75 Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CONNECT);
76
77 Communication::OutputBuffer message;
78 message << std::string("Foo") << std::wstring(L"Bar") << int64_t(9876543210L) << int32_t(5) << true;
79 pipe.WriteMessage(message);
80
81 Communication::InputBuffer response = pipe.ReadMessage();
82
83 std::string stringValue;
84 std::wstring wstringValue;
85 int64_t int64Value;
86 int32_t int32Value;
87 bool boolValue;
88
89 ASSERT_ANY_THROW(response >> wstringValue);
90 ASSERT_ANY_THROW(response >> int64Value);
91 ASSERT_ANY_THROW(response >> int32Value);
92 ASSERT_ANY_THROW(response >> boolValue);
93
94 response >> stringValue >> wstringValue;
95
96 ASSERT_ANY_THROW(response >> stringValue);
97 ASSERT_ANY_THROW(response >> wstringValue);
98 ASSERT_ANY_THROW(response >> int32Value);
99 ASSERT_ANY_THROW(response >> boolValue);
100
101 response >> int64Value >> int32Value >> boolValue;
102
103 ASSERT_ANY_THROW(response >> stringValue);
104 ASSERT_ANY_THROW(response >> wstringValue);
105 ASSERT_ANY_THROW(response >> int64Value);
106 ASSERT_ANY_THROW(response >> int32Value);
107 ASSERT_ANY_THROW(response >> boolValue);
108
109 ASSERT_EQ("Foo Received", stringValue);
110 ASSERT_EQ(L"Bar \u043f\u0440\u0438\u043d\u044f\u0442\u043e", wstringValue);
111 ASSERT_EQ(9876543211L, int64Value);
112 ASSERT_EQ(7, int32Value);
113 ASSERT_FALSE(boolValue);
114 }
OLDNEW
« src/shared/Communication.cpp ('K') | « src/shared/Communication.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld