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

Jan Holesovsky kendy at collabora.com
Thu Apr 28 16:36:46 UTC 2016


 loolwsd/test/Makefile.am                 |    2 
 loolwsd/test/httpgettest.cpp             |  184 --------------------
 loolwsd/test/httpposttest.cpp            |  243 ---------------------------
 loolwsd/test/httptestutils.hpp           |   64 -------
 loolwsd/test/integration-http-server.cpp |  273 +++++++++++++++++++++++++++++++
 5 files changed, 274 insertions(+), 492 deletions(-)

New commits:
commit 407b41afb9508c805849ac72a638dc412c25d63f
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Apr 28 18:35:22 2016 +0200

    Decrease verbosity of this the http server test.
    
    And also check that we've had a hit in loleaflet.html.

diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index e619df9..f4e7557 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -166,28 +166,28 @@ namespace {
 void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, const std::string& html, const std::string& mimetype = std::string())
 {
     Poco::RegularExpression::MatchVec matches;
+    bool found = false;
 
     for (int offset = 0; expr.match(html, offset, matches) > 0; offset = static_cast<int>(matches[0].offset + matches[0].length))
     {
+        found = true;
 	CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
 	Poco::URI uriScript(html.substr(matches[1].offset, matches[1].length));
 	if (uriScript.getHost().empty())
 	{
 	    std::string scriptString(uriScript.toString());
 
-	    // ignore the branding bits, they do not have to be there
+	    // ignore the branding bits, it's not an error when they are not
+            // present
 	    if (scriptString.find("/branding.") != std::string::npos)
-	    {
-		std::cout << "skipping test for... " << scriptString << std::endl;
 		continue;
-	    }
 
 #if ENABLE_SSL
 	    Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
 #else
 	    Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
 #endif
-	    std::cout << "checking... " << scriptString;
+
 	    Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, scriptString);
 	    sessionScript.sendRequest(requestScript);
 
@@ -197,14 +197,10 @@ void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, c
 
 	    if (!mimetype.empty())
 		CPPUNIT_ASSERT_EQUAL(mimetype, responseScript.getContentType());
-
-	    std::cout << " OK" << std::endl;
-	}
-	else
-	{
-	    std::cout << "skip " << uriScript.toString() << std::endl;
 	}
     }
+
+    CPPUNIT_ASSERT_MESSAGE("No match found", found);
 }
 
 }
commit 28b7aee356625338f99e3aad34ae81c517df4239
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Apr 28 18:17:37 2016 +0200

    No need for a standalone httptestutils.hpp any more.

diff --git a/loolwsd/test/httptestutils.hpp b/loolwsd/test/httptestutils.hpp
deleted file mode 100644
index c6fa398..0000000
--- a/loolwsd/test/httptestutils.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-/* -*- 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/.
- */
-
-#ifndef TEST_HTTPTESTUTILS_HPP
-#define TEST_HTTPTESTUTILS_HPP
-
-namespace httptest
-{
-
-inline void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, const std::string& html, const std::string& mimetype = std::string())
-{
-    Poco::RegularExpression::MatchVec matches;
-
-    for (int offset = 0; expr.match(html, offset, matches) > 0; offset = static_cast<int>(matches[0].offset + matches[0].length))
-    {
-	CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
-	Poco::URI uriScript(html.substr(matches[1].offset, matches[1].length));
-	if (uriScript.getHost().empty())
-	{
-	    std::string scriptString(uriScript.toString());
-
-	    // ignore the branding bits, they do not have to be there
-	    if (scriptString.find("/branding.") != std::string::npos)
-	    {
-		std::cout << "skipping test for... " << scriptString << std::endl;
-		continue;
-	    }
-
-#if ENABLE_SSL
-	    Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
-#else
-	    Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
-#endif
-	    std::cout << "checking... " << scriptString;
-	    Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, scriptString);
-	    sessionScript.sendRequest(requestScript);
-
-	    Poco::Net::HTTPResponse responseScript;
-	    sessionScript.receiveResponse(responseScript);
-	    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseScript.getStatus());
-
-	    if (!mimetype.empty())
-		CPPUNIT_ASSERT_EQUAL(mimetype, responseScript.getContentType());
-
-	    std::cout << " OK" << std::endl;
-	}
-	else
-	{
-	    std::cout << "skip " << uriScript.toString() << std::endl;
-	}
-    }
-}
-
-}
-
-#endif // TEST_HTTPTESTUTILS_HPP
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 2cf7edd..e619df9 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -27,7 +27,6 @@
 #include <Util.hpp>
 
 #include "countloolkits.hpp"
-#include "httptestutils.hpp"
 
 /// Tests the HTTP GET API of loolwsd.
 class HTTPServerTest : public CPPUNIT_NS::TestFixture
@@ -162,6 +161,54 @@ void HTTPServerTest::testLoleafletPost()
     CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
 }
 
+namespace {
+
+void assertHTTPFilesExist(const Poco::URI& uri, Poco::RegularExpression& expr, const std::string& html, const std::string& mimetype = std::string())
+{
+    Poco::RegularExpression::MatchVec matches;
+
+    for (int offset = 0; expr.match(html, offset, matches) > 0; offset = static_cast<int>(matches[0].offset + matches[0].length))
+    {
+	CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
+	Poco::URI uriScript(html.substr(matches[1].offset, matches[1].length));
+	if (uriScript.getHost().empty())
+	{
+	    std::string scriptString(uriScript.toString());
+
+	    // ignore the branding bits, they do not have to be there
+	    if (scriptString.find("/branding.") != std::string::npos)
+	    {
+		std::cout << "skipping test for... " << scriptString << std::endl;
+		continue;
+	    }
+
+#if ENABLE_SSL
+	    Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
+#else
+	    Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
+#endif
+	    std::cout << "checking... " << scriptString;
+	    Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, scriptString);
+	    sessionScript.sendRequest(requestScript);
+
+	    Poco::Net::HTTPResponse responseScript;
+	    sessionScript.receiveResponse(responseScript);
+	    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseScript.getStatus());
+
+	    if (!mimetype.empty())
+		CPPUNIT_ASSERT_EQUAL(mimetype, responseScript.getContentType());
+
+	    std::cout << " OK" << std::endl;
+	}
+	else
+	{
+	    std::cout << "skip " << uriScript.toString() << std::endl;
+	}
+    }
+}
+
+}
+
 void HTTPServerTest::testScriptsAndLinksGet()
 {
 #if ENABLE_SSL
@@ -183,10 +230,10 @@ void HTTPServerTest::testScriptsAndLinksGet()
     Poco::StreamCopier::copyToString(rs, html);
 
     Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-    httptest::assertHTTPFilesExist(uri, script, html, "application/javascript");
+    assertHTTPFilesExist(uri, script, html, "application/javascript");
 
     Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-    httptest::assertHTTPFilesExist(uri, link, html);
+    assertHTTPFilesExist(uri, link, html);
 }
 
 void HTTPServerTest::testScriptsAndLinksPost()
@@ -212,10 +259,10 @@ void HTTPServerTest::testScriptsAndLinksPost()
     Poco::StreamCopier::copyToString(rs, html);
 
     Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-    httptest::assertHTTPFilesExist(uri, script, html, "application/javascript");
+    assertHTTPFilesExist(uri, script, html, "application/javascript");
 
     Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-    httptest::assertHTTPFilesExist(uri, link, html);
+    assertHTTPFilesExist(uri, link, html);
 }
 
 void HTTPServerTest::testNoExtraLoolKitsLeft()
commit 8e266391f13a7daa3b074ba2ae33ac4958d39ae0
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Apr 28 18:08:07 2016 +0200

    Merge the http get and post tests into one file, and reduce copy/paste.

diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index 5c65e9d..4a7663b 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 integration-http-server.cpp httpposttest.cpp httpwstest.cpp httpcrashtest.cpp test.cpp ../LOOLProtocol.cpp
+test_SOURCES = WhiteBoxTests.cpp integration-http-server.cpp httpwstest.cpp httpcrashtest.cpp test.cpp ../LOOLProtocol.cpp
 test_LDADD = $(CPPUNIT_LIBS)
 
 # unit test modules:
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
deleted file mode 100644
index ce4f460..0000000
--- a/loolwsd/test/httpposttest.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/* -*- 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>
-
-#include "countloolkits.hpp"
-#include "httptestutils.hpp"
-
-/// Tests the HTTP POST API of loolwsd. The server has to be started manually before running this test.
-class HTTPPostTest : public CPPUNIT_NS::TestFixture
-{
-    static int _initialLoolKitCount;
-
-    CPPUNIT_TEST_SUITE(HTTPPostTest);
-
-    // This should be the first test:
-    CPPUNIT_TEST(testCountHowManyLoolkits);
-
-    CPPUNIT_TEST(testLOleaflet);
-    CPPUNIT_TEST(testParams);
-    CPPUNIT_TEST(testScripts);
-    CPPUNIT_TEST(testLinks);
-    CPPUNIT_TEST(testConvertTo);
-
-    // This should be the last test:
-    CPPUNIT_TEST(testNoExtraLoolKitsLeft);
-
-    CPPUNIT_TEST_SUITE_END();
-
-    void testCountHowManyLoolkits();
-    void testLOleaflet();
-    void testParams();
-    void testScripts();
-    void testLinks();
-    void testConvertTo();
-    void testNoExtraLoolKitsLeft();
-
-#if ENABLE_SSL
-public:
-    HTTPPostTest()
-    {
-        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);
-    }
-
-    ~HTTPPostTest()
-    {
-        Poco::Net::uninitializeSSL();
-    }
-#endif
-};
-
-int HTTPPostTest::_initialLoolKitCount = 0;
-
-void HTTPPostTest::testCountHowManyLoolkits()
-{
-    _initialLoolKitCount = countLoolKitProcesses();
-    CPPUNIT_ASSERT(_initialLoolKitCount > 0);
-}
-
-void HTTPPostTest::testLOleaflet()
-{
-#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_POST, "/loleaflet/dist/loleaflet.html");
-    std::string body;
-    request.setContentLength((int) body.length());
-    session.sendRequest(request) << body;
-
-    Poco::Net::HTTPResponse response;
-    session.receiveResponse(response);
-    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
-    CPPUNIT_ASSERT_EQUAL(std::string("text/html"), response.getContentType());
-}
-
-void HTTPPostTest::testParams()
-{
-#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_POST, "/loleaflet/dist/loleaflet.html");
-    Poco::Net::HTMLForm form;
-    form.set("access_token", "2222222222");
-    form.prepareSubmit(request);
-    std::ostream& ostr = session.sendRequest(request);
-    form.write(ostr);
-
-    Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
-    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
-
-    std::string html;
-    Poco::StreamCopier::copyToString(rs, html);
-
-    CPPUNIT_ASSERT(html.find(form["access_token"]) != std::string::npos);
-    CPPUNIT_ASSERT(html.find(uri.getHost()) != std::string::npos);
-    CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
-}
-
-void HTTPPostTest::testScripts()
-{
-#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_POST, "/loleaflet/dist/loleaflet.html");
-    std::string body;
-    request.setContentLength((int) body.length());
-    session.sendRequest(request) << body;
-
-    Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
-    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
-
-    std::string html;
-    Poco::StreamCopier::copyToString(rs, html);
-
-    Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-
-    httptest::assertHTTPFilesExist(uri, script, html, "application/javascript");
-}
-
-void HTTPPostTest::testLinks()
-{
-#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_POST, "/loleaflet/dist/loleaflet.html");
-    std::string body;
-    request.setContentLength((int) body.length());
-    session.sendRequest(request) << body;
-
-    Poco::Net::HTTPResponse response;
-    std::istream& rs = session.receiveResponse(response);
-    CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
-
-    std::string html;
-    Poco::StreamCopier::copyToString(rs, html);
-
-    Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-
-    httptest::assertHTTPFilesExist(uri, link, html);
-}
-
-void HTTPPostTest::testConvertTo()
-{
-    const auto srcPath = Util::getTempFilePath(TDOC, "hello.odt");
-
-#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_POST, "/convert-to");
-    Poco::Net::HTMLForm form;
-    form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
-    form.set("format", "txt");
-    form.addPart("data", new Poco::Net::FilePartSource(srcPath));
-    form.prepareSubmit(request);
-    // If this results in a Poco::Net::ConnectionRefusedException, loolwsd is not running.
-    form.write(session.sendRequest(request));
-
-    Poco::Net::HTTPResponse response;
-    std::stringstream actualStream;
-    // receiveResponse() resulted in a Poco::Net::NoMessageException.
-    std::istream& responseStream = session.receiveResponse(response);
-    Poco::StreamCopier::copyStream(responseStream, actualStream);
-
-    std::ifstream fileStream(TDOC "/hello.txt");
-    std::stringstream expectedStream;
-    expectedStream << fileStream.rdbuf();
-
-    // Remove the temp files.
-    Util::removeFile(srcPath);
-
-    // In some cases the result is prefixed with (the UTF-8 encoding of) the Unicode BOM
-    // (U+FEFF). Skip that.
-    std::string actualString = actualStream.str();
-    if (actualString.size() > 3 && actualString[0] == '\xEF' && actualString[1] == '\xBB' && actualString[2] == '\xBF')
-        actualString = actualString.substr(3);
-    CPPUNIT_ASSERT_EQUAL(expectedStream.str(), actualString);
-}
-
-void HTTPPostTest::testNoExtraLoolKitsLeft()
-{
-    int countNow = countLoolKitProcesses();
-
-    CPPUNIT_ASSERT_EQUAL(_initialLoolKitCount, countNow);
-}
-
-CPPUNIT_TEST_SUITE_REGISTRATION(HTTPPostTest);
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index 1daab67..2cf7edd 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -26,30 +26,43 @@
 #include <Common.hpp>
 #include <Util.hpp>
 
+#include "countloolkits.hpp"
 #include "httptestutils.hpp"
 
 /// Tests the HTTP GET API of loolwsd.
-class HTTPGetTest : public CPPUNIT_NS::TestFixture
+class HTTPServerTest : public CPPUNIT_NS::TestFixture
 {
-    CPPUNIT_TEST_SUITE(HTTPGetTest);
+    static int _initialLoolKitCount;
+
+    CPPUNIT_TEST_SUITE(HTTPServerTest);
+
+    // This should be the first test:
+    CPPUNIT_TEST(testCountHowManyLoolkits);
 
     CPPUNIT_TEST(testDiscovery);
-    CPPUNIT_TEST(testLOleaflet);
-    CPPUNIT_TEST(testParams);
-    CPPUNIT_TEST(testScripts);
-    CPPUNIT_TEST(testLinks);
+    CPPUNIT_TEST(testLoleafletGet);
+    CPPUNIT_TEST(testLoleafletPost);
+    CPPUNIT_TEST(testScriptsAndLinksGet);
+    CPPUNIT_TEST(testScriptsAndLinksPost);
+
+    // This should be the last test:
+    CPPUNIT_TEST(testNoExtraLoolKitsLeft);
 
     CPPUNIT_TEST_SUITE_END();
 
+    void testCountHowManyLoolkits();
+
     void testDiscovery();
-    void testLOleaflet();
-    void testParams();
-    void testScripts();
-    void testLinks();
+    void testLoleafletGet();
+    void testLoleafletPost();
+    void testScriptsAndLinksGet();
+    void testScriptsAndLinksPost();
+
+    void testNoExtraLoolKitsLeft();
 
 #if ENABLE_SSL
 public:
-    HTTPGetTest()
+    HTTPServerTest()
     {
         Poco::Net::initializeSSL();
         // Just accept the certificate anyway for testing purposes
@@ -59,14 +72,22 @@ public:
         Poco::Net::SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext);
     }
 
-    ~HTTPGetTest()
+    ~HTTPServerTest()
     {
         Poco::Net::uninitializeSSL();
     }
 #endif
 };
 
-void HTTPGetTest::testDiscovery()
+int HTTPServerTest::_initialLoolKitCount = 0;
+
+void HTTPServerTest::testCountHowManyLoolkits()
+{
+    _initialLoolKitCount = countLoolKitProcesses();
+    CPPUNIT_ASSERT(_initialLoolKitCount > 0);
+}
+
+void HTTPServerTest::testDiscovery()
 {
 #if ENABLE_SSL
     Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
@@ -85,7 +106,7 @@ void HTTPGetTest::testDiscovery()
     CPPUNIT_ASSERT_EQUAL(std::string("text/xml"), response.getContentType());
 }
 
-void HTTPGetTest::testLOleaflet()
+void HTTPServerTest::testLoleafletGet()
 {
 #if ENABLE_SSL
     Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
@@ -95,16 +116,24 @@ void HTTPGetTest::testLOleaflet()
     Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
 #endif
 
-    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html");
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html?access_token=111111111");
+    Poco::Net::HTMLForm param(request);
     session.sendRequest(request);
 
     Poco::Net::HTTPResponse response;
-    session.receiveResponse(response);
+    std::istream& rs = session.receiveResponse(response);
     CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, response.getStatus());
     CPPUNIT_ASSERT_EQUAL(std::string("text/html"), response.getContentType());
+
+    std::string html;
+    Poco::StreamCopier::copyToString(rs, html);
+
+    CPPUNIT_ASSERT(html.find(param["access_token"]) != std::string::npos);
+    CPPUNIT_ASSERT(html.find(uri.getHost()) != std::string::npos);
+    CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
 }
 
-void HTTPGetTest::testParams()
+void HTTPServerTest::testLoleafletPost()
 {
 #if ENABLE_SSL
     Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
@@ -114,9 +143,12 @@ void HTTPGetTest::testParams()
     Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
 #endif
 
-    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/loleaflet/dist/loleaflet.html?access_token=111111111");
-    Poco::Net::HTMLForm param(request);
-    session.sendRequest(request);
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
+    Poco::Net::HTMLForm form;
+    form.set("access_token", "2222222222");
+    form.prepareSubmit(request);
+    std::ostream& ostr = session.sendRequest(request);
+    form.write(ostr);
 
     Poco::Net::HTTPResponse response;
     std::istream& rs = session.receiveResponse(response);
@@ -125,12 +157,12 @@ void HTTPGetTest::testParams()
     std::string html;
     Poco::StreamCopier::copyToString(rs, html);
 
-    CPPUNIT_ASSERT(html.find(param["access_token"]) != std::string::npos);
+    CPPUNIT_ASSERT(html.find(form["access_token"]) != std::string::npos);
     CPPUNIT_ASSERT(html.find(uri.getHost()) != std::string::npos);
     CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
 }
 
-void HTTPGetTest::testScripts()
+void HTTPServerTest::testScriptsAndLinksGet()
 {
 #if ENABLE_SSL
     Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
@@ -139,6 +171,7 @@ void HTTPGetTest::testScripts()
     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, "/loleaflet/dist/loleaflet.html");
     session.sendRequest(request);
 
@@ -150,11 +183,13 @@ void HTTPGetTest::testScripts()
     Poco::StreamCopier::copyToString(rs, html);
 
     Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
-
     httptest::assertHTTPFilesExist(uri, script, html, "application/javascript");
+
+    Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
+    httptest::assertHTTPFilesExist(uri, link, html);
 }
 
-void HTTPGetTest::testLinks()
+void HTTPServerTest::testScriptsAndLinksPost()
 {
 #if ENABLE_SSL
     Poco::URI uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER));
@@ -163,8 +198,11 @@ void HTTPGetTest::testLinks()
     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, "/loleaflet/dist/loleaflet.html");
-    session.sendRequest(request);
+
+    Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/loleaflet/dist/loleaflet.html");
+    std::string body;
+    request.setContentLength((int) body.length());
+    session.sendRequest(request) << body;
 
     Poco::Net::HTTPResponse response;
     std::istream& rs = session.receiveResponse(response);
@@ -173,12 +211,20 @@ void HTTPGetTest::testLinks()
     std::string html;
     Poco::StreamCopier::copyToString(rs, html);
 
-    Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
-    Poco::RegularExpression::MatchVec matches;
+    Poco::RegularExpression script("<script.*?src=\"(.*?)\"");
+    httptest::assertHTTPFilesExist(uri, script, html, "application/javascript");
 
+    Poco::RegularExpression link("<link.*?href=\"(.*?)\"");
     httptest::assertHTTPFilesExist(uri, link, html);
 }
 
-CPPUNIT_TEST_SUITE_REGISTRATION(HTTPGetTest);
+void HTTPServerTest::testNoExtraLoolKitsLeft()
+{
+    int countNow = countLoolKitProcesses();
+
+    CPPUNIT_ASSERT_EQUAL(_initialLoolKitCount, countNow);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HTTPServerTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f283b045a95dc2dad68ff1b65b87f57546599ace
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu Apr 28 17:45:18 2016 +0200

    The http tests are actually integration tests, not unit tests.

diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index 9f662bd..5c65e9d 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 httpgettest.cpp httpposttest.cpp httpwstest.cpp httpcrashtest.cpp test.cpp ../LOOLProtocol.cpp
+test_SOURCES = WhiteBoxTests.cpp integration-http-server.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/integration-http-server.cpp
similarity index 100%
rename from loolwsd/test/httpgettest.cpp
rename to loolwsd/test/integration-http-server.cpp


More information about the Libreoffice-commits mailing list