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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/shared/Communication.cpp ('K') | « src/shared/Communication.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/CommunicationTest.cpp
===================================================================
new file mode 100644
--- /dev/null
+++ b/test/CommunicationTest.cpp
@@ -0,0 +1,114 @@
+/*
+ * This file is part of Adblock Plus <http://adblockplus.org/>,
+ * Copyright (C) 2006-2013 Eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <gtest/gtest.h>
+
+#include "../src/shared/AutoHandle.h"
+#include "../src/shared/Communication.h"
+
+const std::wstring pipeName(L"\\\\.\\pipe\\adblockplustests");
+
+namespace
+{
+ DWORD WINAPI CreatePipe(LPVOID param)
+ {
+ Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CREATE);
+ return 0;
+ }
+
+ DWORD WINAPI ReceiveSend(LPVOID param)
+ {
+ Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CREATE);
+
+ Communication::InputBuffer message = pipe.ReadMessage();
+
+ std::string stringValue;
+ std::wstring wstringValue;
+ int64_t int64Value;
+ int32_t int32Value;
+ bool boolValue;
+ message >> stringValue >> wstringValue >> int64Value >> int32Value >> boolValue;
+
+ stringValue += " Received";
+ wstringValue += L" \u043f\u0440\u0438\u043d\u044f\u0442\u043e";
+ int64Value += 1;
+ int32Value += 2;
+ boolValue = !boolValue;
+
+ Communication::OutputBuffer response;
+ response << stringValue << wstringValue << int64Value << int32Value << boolValue;
+ pipe.WriteMessage(response);
+
+ return 0;
+ }
+}
+
+TEST(CommunicationTest, ConnectPipe)
+{
+ AutoHandle thread(CreateThread(0, 0, CreatePipe, 0, 0, 0));
+
+ Sleep(100);
+
+ ASSERT_NO_THROW(Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CONNECT));
+}
+
+TEST(CommunicationTest, SendReceive)
+{
+ AutoHandle thread(CreateThread(0, 0, ReceiveSend, 0, 0, 0));
+
+ Sleep(100);
+
+ Communication::Pipe pipe(pipeName, Communication::Pipe::MODE_CONNECT);
+
+ Communication::OutputBuffer message;
+ message << std::string("Foo") << std::wstring(L"Bar") << int64_t(9876543210L) << int32_t(5) << true;
+ pipe.WriteMessage(message);
+
+ Communication::InputBuffer response = pipe.ReadMessage();
+
+ std::string stringValue;
+ std::wstring wstringValue;
+ int64_t int64Value;
+ int32_t int32Value;
+ bool boolValue;
+
+ ASSERT_ANY_THROW(response >> wstringValue);
+ ASSERT_ANY_THROW(response >> int64Value);
+ ASSERT_ANY_THROW(response >> int32Value);
+ ASSERT_ANY_THROW(response >> boolValue);
+
+ response >> stringValue >> wstringValue;
+
+ ASSERT_ANY_THROW(response >> stringValue);
+ ASSERT_ANY_THROW(response >> wstringValue);
+ ASSERT_ANY_THROW(response >> int32Value);
+ ASSERT_ANY_THROW(response >> boolValue);
+
+ response >> int64Value >> int32Value >> boolValue;
+
+ ASSERT_ANY_THROW(response >> stringValue);
+ ASSERT_ANY_THROW(response >> wstringValue);
+ ASSERT_ANY_THROW(response >> int64Value);
+ ASSERT_ANY_THROW(response >> int32Value);
+ ASSERT_ANY_THROW(response >> boolValue);
+
+ ASSERT_EQ("Foo Received", stringValue);
+ ASSERT_EQ(L"Bar \u043f\u0440\u0438\u043d\u044f\u0442\u043e", wstringValue);
+ ASSERT_EQ(9876543211L, int64Value);
+ ASSERT_EQ(7, int32Value);
+ ASSERT_FALSE(boolValue);
+}
« 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