[Libreoffice-commits] online.git: test/integration-http-server.cpp test/Makefile.am test/UnitHosting.cpp
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Fri Jan 17 08:17:01 UTC 2020
test/Makefile.am | 4 +
test/UnitHosting.cpp | 150 +++++++++++++++++++++++++++++++++++++++
test/integration-http-server.cpp | 100 --------------------------
3 files changed, 154 insertions(+), 100 deletions(-)
New commits:
commit e2fa8c43a1cc800016ec4a2ca5ba0da5c322ca47
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Jan 17 08:50:15 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Jan 17 09:16:41 2020 +0100
Convert some of the integration-http-server tests to new-style ones
So that they are in-process, which means it's easier to debug when they
fail.
Change-Id: I164b97be0bc487a02d4b2a872b9c0e40791056cd
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/86951
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index a1b6528e1..f1d4963b1 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,6 +37,7 @@ noinst_LTLIBRARIES = \
unit-insert-delete.la \
unit-close.la \
unit-bad-doc-load.la \
+ unit-hosting.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
MAGIC_TO_FORCE_SHLIB_CREATION = -rpath /dummy
@@ -169,6 +170,8 @@ unit_close_la_SOURCES = UnitClose.cpp
unit_close_la_LIBADD = $(CPPUNIT_LIBS)
unit_bad_doc_load_la_SOURCES = UnitBadDocLoad.cpp
unit_bad_doc_load_la_LIBADD = $(CPPUNIT_LIBS)
+unit_hosting_la_SOURCES = UnitHosting.cpp
+unit_hosting_la_LIBADD = $(CPPUNIT_LIBS)
if HAVE_LO_PATH
SYSTEM_STAMP = @SYSTEMPLATE_PATH@/system_stamp
@@ -204,6 +207,7 @@ TESTS = unit-copy-paste.la unit-typing.la unit-convert.la unit-prefork.la unit-t
unit-insert-delete.la \
unit-close.la \
unit-bad-doc-load.la \
+ unit-hosting.la \
unit-wopi-loadencoded.la unit-wopi-temp.la
# TESTS = unit-client.la
# TESTS += unit-admin.la
diff --git a/test/UnitHosting.cpp b/test/UnitHosting.cpp
new file mode 100644
index 000000000..9c3825727
--- /dev/null
+++ b/test/UnitHosting.cpp
@@ -0,0 +1,150 @@
+/* -*- 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 <memory>
+#include <ostream>
+#include <set>
+#include <string>
+
+#include <Poco/DOM/AutoPtr.h>
+#include <Poco/DOM/DOMParser.h>
+#include <Poco/DOM/Document.h>
+#include <Poco/DOM/NodeList.h>
+#include <Poco/Exception.h>
+#include <Poco/RegularExpression.h>
+#include <Poco/URI.h>
+#include <cppunit/TestAssert.h>
+
+#include <Png.hpp>
+#include <Unit.hpp>
+#include <helpers.hpp>
+
+// Include config.h last, so the test server URI is still HTTP, even in SSL builds.
+#include <config.h>
+
+class LOOLWebSocket;
+
+/// Test suite for /hosting, etc.
+class UnitHosting : public UnitWSD
+{
+ TestResult testDiscovery();
+ TestResult testCapabilities();
+
+public:
+ void invokeTest() override;
+};
+
+UnitBase::TestResult UnitHosting::testDiscovery()
+{
+ Poco::URI uri(helpers::getTestServerURI());
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
+ session->sendRequest(request);
+
+ Poco::Net::HTTPResponse response;
+ session->receiveResponse(response);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
+
+ Poco::Net::HTTPRequest request2(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery/");
+ session->sendRequest(request2);
+
+ Poco::Net::HTTPResponse response2;
+ session->receiveResponse(response2);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response2.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response2.getContentType());
+ return TestResult::Ok;
+}
+
+UnitBase::TestResult UnitHosting::testCapabilities()
+{
+ Poco::URI uri(helpers::getTestServerURI());
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(uri));
+
+ // Get discovery first and extract the urlsrc of the capabilities end point
+ std::string capabilitiesURI;
+ {
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
+ session->sendRequest(request);
+
+ Poco::Net::HTTPResponse response;
+ std::istream& rs = session->receiveResponse(response);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
+
+ std::string discoveryXML;
+ Poco::StreamCopier::copyToString(rs, discoveryXML);
+
+ Poco::XML::DOMParser parser;
+ Poco::XML::AutoPtr<Poco::XML::Document> docXML = parser.parseString(discoveryXML);
+ Poco::XML::AutoPtr<Poco::XML::NodeList> listNodes = docXML->getElementsByTagName("action");
+ bool foundCapabilities = false;
+ for (unsigned long index = 0; index < listNodes->length(); ++index)
+ {
+ Poco::XML::Element* elem = static_cast<Poco::XML::Element*>(listNodes->item(index));
+ Poco::XML::Element* parent = elem->parentNode()
+ ? static_cast<Poco::XML::Element*>(elem->parentNode())
+ : nullptr;
+ if (parent && parent->getAttribute("name") == "Capabilities")
+ {
+ foundCapabilities = true;
+ capabilitiesURI = elem->getAttribute("urlsrc");
+ break;
+ }
+ }
+
+ CPPUNIT_ASSERT(foundCapabilities);
+ CPPUNIT_ASSERT_EQUAL(uri.toString() + CAPABILITIES_END_POINT, capabilitiesURI);
+ }
+
+ // Then get the capabilities json
+ {
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, CAPABILITIES_END_POINT);
+ session->sendRequest(request);
+
+ Poco::Net::HTTPResponse response;
+ std::istream& rs = session->receiveResponse(response);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("application/json"), response.getContentType());
+
+ std::ostringstream oss;
+ Poco::StreamCopier::copyStream(rs, oss);
+ std::string responseString = oss.str();
+
+ Poco::JSON::Parser parser;
+ Poco::Dynamic::Var jsonFile = parser.parse(responseString);
+ Poco::JSON::Object::Ptr features = jsonFile.extract<Poco::JSON::Object::Ptr>();
+ CPPUNIT_ASSERT(features);
+ CPPUNIT_ASSERT(features->has("convert-to"));
+
+ Poco::JSON::Object::Ptr convert_to
+ = features->get("convert-to").extract<Poco::JSON::Object::Ptr>();
+ CPPUNIT_ASSERT(convert_to->has("available"));
+ CPPUNIT_ASSERT(convert_to->get("available"));
+ }
+ return TestResult::Ok;
+}
+
+void UnitHosting::invokeTest()
+{
+ UnitBase::TestResult result = testDiscovery();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ result = testCapabilities();
+ if (result != TestResult::Ok)
+ exitTest(result);
+
+ exitTest(TestResult::Ok);
+}
+
+UnitBase* unit_create_wsd(void) { return new UnitHosting(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/test/integration-http-server.cpp b/test/integration-http-server.cpp
index a2ceaca92..4db04737a 100644
--- a/test/integration-http-server.cpp
+++ b/test/integration-http-server.cpp
@@ -9,20 +9,13 @@
#include <config.h>
-#include <Poco/DOM/AutoPtr.h>
-#include <Poco/DOM/DOMParser.h>
-#include <Poco/DOM/Document.h>
-#include <Poco/DOM/Element.h>
-#include <Poco/DOM/NodeList.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/FilePartSource.h>
#include <Poco/Net/HTMLForm.h>
#include <Poco/Net/HTTPClientSession.h>
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
-#include <Poco/Net/HTTPSClientSession.h>
#include <Poco/Net/InvalidCertificateHandler.h>
-#include <Poco/Net/PrivateKeyPassphraseHandler.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/RegularExpression.h>
#include <Poco/StreamCopier.h>
@@ -32,7 +25,6 @@
#include <Common.hpp>
#include <common/FileUtil.hpp>
-#include <Util.hpp>
#include <countloolkits.hpp>
#include <helpers.hpp>
@@ -44,8 +36,6 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE(HTTPServerTest);
- CPPUNIT_TEST(testDiscovery);
- CPPUNIT_TEST(testCapabilities);
CPPUNIT_TEST(testLoleafletGet);
CPPUNIT_TEST(testLoleafletPost);
CPPUNIT_TEST(testScriptsAndLinksGet);
@@ -56,8 +46,6 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE_END();
- void testDiscovery();
- void testCapabilities();
void testLoleafletGet();
void testLoleafletPost();
void testScriptsAndLinksGet();
@@ -119,94 +107,6 @@ public:
};
-void HTTPServerTest::testDiscovery()
-{
- std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
- session->sendRequest(request);
-
- Poco::Net::HTTPResponse response;
- session->receiveResponse(response);
- CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
- CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
-
- Poco::Net::HTTPRequest request2(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery/");
- session->sendRequest(request2);
-
- Poco::Net::HTTPResponse response2;
- session->receiveResponse(response2);
- CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response2.getStatus());
- CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response2.getContentType());
-}
-
-
-void HTTPServerTest::testCapabilities()
-{
- std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
-
- // Get discovery first and extract the urlsrc of the capabilities end point
- std::string capabilitiesURI;
- {
-
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/hosting/discovery");
- session->sendRequest(request);
-
- Poco::Net::HTTPResponse response;
- std::istream& rs = session->receiveResponse(response);
- CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
- CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
-
- std::string discoveryXML;
- Poco::StreamCopier::copyToString(rs, discoveryXML);
-
- Poco::XML::DOMParser parser;
- Poco::XML::AutoPtr<Poco::XML::Document> docXML = parser.parseString(discoveryXML);
- Poco::XML::AutoPtr<Poco::XML::NodeList> listNodes = docXML->getElementsByTagName("action");
- bool foundCapabilities = false;
- for (unsigned long index = 0; index < listNodes->length(); ++index)
- {
- Poco::XML::Element* elem = static_cast<Poco::XML::Element*>(listNodes->item(index));
- Poco::XML::Element* parent = elem->parentNode() ? static_cast<Poco::XML::Element*>(elem->parentNode()) : nullptr;
- if(parent && parent->getAttribute("name") == "Capabilities")
- {
- foundCapabilities = true;
- capabilitiesURI = elem->getAttribute("urlsrc");
- break;
- }
- }
-
- CPPUNIT_ASSERT(foundCapabilities);
- CPPUNIT_ASSERT_EQUAL(_uri.toString() + CAPABILITIES_END_POINT, capabilitiesURI);
- }
-
- // Then get the capabilities json
- {
- Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, CAPABILITIES_END_POINT);
- session->sendRequest(request);
-
- Poco::Net::HTTPResponse response;
- std::istream& rs = session->receiveResponse(response);
- CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
- CPPUNIT_ASSERT_EQUAL(std::string("application/json"), response.getContentType());
-
- std::ostringstream oss;
- Poco::StreamCopier::copyStream(rs, oss);
- std::string responseString = oss.str();
-
- Poco::JSON::Parser parser;
- Poco::Dynamic::Var jsonFile = parser.parse(responseString);
- Poco::JSON::Object::Ptr features = jsonFile.extract<Poco::JSON::Object::Ptr>();
- CPPUNIT_ASSERT(features);
- CPPUNIT_ASSERT(features->has("convert-to"));
-
- Poco::JSON::Object::Ptr convert_to = features->get("convert-to").extract<Poco::JSON::Object::Ptr>();
- CPPUNIT_ASSERT(convert_to->has("available"));
- CPPUNIT_ASSERT(convert_to->get("available"));
- }
-}
-
-
void HTTPServerTest::testLoleafletGet()
{
std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
More information about the Libreoffice-commits
mailing list