[Libreoffice-commits] online.git: loolwsd/test

Henry Castro hcastro at collabora.com
Thu Apr 21 03:08:17 UTC 2016


 loolwsd/test/Makefile.am     |    2 -
 loolwsd/test/httpgettest.cpp |   79 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 1 deletion(-)

New commits:
commit 40daf0185aeace0c323d296ec8b46e7eeb02b14a
Author: Henry Castro <hcastro at collabora.com>
Date:   Wed Apr 20 23:09:04 2016 -0400

    loolwsd: test: discovery

diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index d5ec9b9..9f662bd 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -14,7 +14,7 @@ AM_LDFLAGS = -module $(MAGIC_TO_FORCE_SHLIB_CREATION)
 AM_CPPFLAGS = -pthread -I$(top_srcdir)
 
 test_CPPFLAGS = -DTDOC=\"$(top_srcdir)/test/data\"
-test_SOURCES = WhiteBoxTests.cpp httpposttest.cpp httpwstest.cpp httpcrashtest.cpp test.cpp ../LOOLProtocol.cpp
+test_SOURCES = WhiteBoxTests.cpp httpgettest.cpp httpposttest.cpp httpwstest.cpp httpcrashtest.cpp test.cpp ../LOOLProtocol.cpp
 test_LDADD = $(CPPUNIT_LIBS)
 
 # unit test modules:
diff --git a/loolwsd/test/httpgettest.cpp b/loolwsd/test/httpgettest.cpp
new file mode 100644
index 0000000..28831e2
--- /dev/null
+++ b/loolwsd/test/httpgettest.cpp
@@ -0,0 +1,79 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "config.h"
+
+#include <Poco/Net/AcceptCertificateHandler.h>
+#include <Poco/Net/FilePartSource.h>
+#include <Poco/Net/HTMLForm.h>
+#include <Poco/Net/HTTPClientSession.h>
+#include <Poco/Net/HTTPSClientSession.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
+#include <Poco/Net/InvalidCertificateHandler.h>
+#include <Poco/Net/PrivateKeyPassphraseHandler.h>
+#include <Poco/Net/SSLManager.h>
+#include <Poco/StreamCopier.h>
+#include <Poco/URI.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <Common.hpp>
+#include <Util.hpp>
+
+/// Tests the HTTP GET API of loolwsd.
+class HTTPGetTest : public CPPUNIT_NS::TestFixture
+{
+    CPPUNIT_TEST_SUITE(HTTPGetTest);
+
+    CPPUNIT_TEST(testDiscovery);
+
+    CPPUNIT_TEST_SUITE_END();
+
+    void testDiscovery();
+
+#if ENABLE_SSL
+public:
+    HTTPGetTest()
+    {
+        Poco::Net::initializeSSL();
+        // Just accept the certificate anyway for testing purposes
+        Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> invalidCertHandler = new Poco::Net::AcceptCertificateHandler(false);
+        Poco::Net::Context::Params sslParams;
+        Poco::Net::Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams);
+        Poco::Net::SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext);
+    }
+
+    ~HTTPGetTest()
+    {
+        Poco::Net::uninitializeSSL();
+    }
+#endif
+};
+
+void HTTPGetTest::testDiscovery()
+{
+#if ENABLE_SSL
+    Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
+    Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort());
+#else
+    Poco::URI uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
+    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+#endif
+
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
+    session.sendRequest(request);
+
+    Poco::Net::HTTPResponse response;
+    session.receiveResponse(response);
+    CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HTTPGetTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list