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

Henry Castro hcastro at collabora.com
Tue Apr 26 01:39:36 UTC 2016


 loolwsd/test/httpgettest.cpp  |   53 +++++++++++++++++++++++++++++++++++++++
 loolwsd/test/httpposttest.cpp |   56 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 109 insertions(+)

New commits:
commit 47917fb8c9e232aa9e053c7b150e206ecd00ab34
Author: Henry Castro <hcastro at collabora.com>
Date:   Mon Apr 25 21:40:24 2016 -0400

    loolwsd: test: add testLinks

diff --git a/loolwsd/test/httpgettest.cpp b/loolwsd/test/httpgettest.cpp
index a1eecdc..bb1862a 100644
--- a/loolwsd/test/httpgettest.cpp
+++ b/loolwsd/test/httpgettest.cpp
@@ -35,6 +35,7 @@ class HTTPGetTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testLOleaflet);
     CPPUNIT_TEST(testParams);
     CPPUNIT_TEST(testScripts);
+    CPPUNIT_TEST(testLinks);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -42,6 +43,7 @@ class HTTPGetTest : public CPPUNIT_NS::TestFixture
     void testLOleaflet();
     void testParams();
     void testScripts();
+    void testLinks();
 
 #if ENABLE_SSL
 public:
@@ -178,6 +180,57 @@ void HTTPGetTest::testScripts()
     }
 }
 
+void HTTPGetTest::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_GET, "/loleaflet/dist/loleaflet.html");
+    session.sendRequest(request);
+
+    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=\"(.*?)\"");
+    Poco::RegularExpression::MatchVec matches;
+    int offset = 0;
+
+    while (link.match(html, offset, matches) > 0)
+    {
+        CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
+        Poco::URI uriLink(html.substr(matches[1].offset, matches[1].length));
+        if (uriLink.getHost().empty())
+        {
+#if ENABLE_SSL
+            Poco::Net::HTTPSClientSession sessionLink(uri.getHost(), uri.getPort());
+#else
+            Poco::Net::HTTPClientSession sessionLink(uri.getHost(), uri.getPort());
+#endif
+            std::cout << "checking... " << uriLink.toString();
+            Poco::Net::HTTPRequest requestLink(Poco::Net::HTTPRequest::HTTP_GET, uriLink.toString());
+            sessionLink.sendRequest(requestLink);
+
+            Poco::Net::HTTPResponse responseLink;
+            sessionLink.receiveResponse(responseLink);
+            CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseLink.getStatus());
+            std::cout << " OK" << std::endl;
+        }
+        else
+        {
+            std::cout << "skip " << uriLink.toString() << std::endl;
+        }
+        offset = static_cast<int>(matches[0].offset + matches[0].length);
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(HTTPGetTest);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
index 8c7f637..b8756d5 100644
--- a/loolwsd/test/httpposttest.cpp
+++ b/loolwsd/test/httpposttest.cpp
@@ -41,6 +41,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture
     CPPUNIT_TEST(testLOleaflet);
     CPPUNIT_TEST(testParams);
     CPPUNIT_TEST(testScripts);
+    CPPUNIT_TEST(testLinks);
     CPPUNIT_TEST(testConvertTo);
 
     // This should be the last test:
@@ -52,6 +53,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture
     void testLOleaflet();
     void testParams();
     void testScripts();
+    void testLinks();
     void testConvertTo();
     void testNoExtraLoolKitsLeft();
 
@@ -187,6 +189,60 @@ void HTTPPostTest::testScripts()
     }
 }
 
+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=\"(.*?)\"");
+    Poco::RegularExpression::MatchVec matches;
+    int offset = 0;
+
+    while (link.match(html, offset, matches) > 0)
+    {
+        CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
+        Poco::URI uriLink(html.substr(matches[1].offset, matches[1].length));
+        if (uriLink.getHost().empty())
+        {
+#if ENABLE_SSL
+            Poco::Net::HTTPSClientSession sessionLink(uri.getHost(), uri.getPort());
+#else
+            Poco::Net::HTTPClientSession sessionLink(uri.getHost(), uri.getPort());
+#endif
+            std::cout << "checking... " << uriLink.toString();
+            Poco::Net::HTTPRequest requestLink(Poco::Net::HTTPRequest::HTTP_GET, uriLink.toString());
+            sessionLink.sendRequest(requestLink);
+
+            Poco::Net::HTTPResponse responseLink;
+            sessionLink.receiveResponse(responseLink);
+            CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseLink.getStatus());
+            std::cout << " OK" << std::endl;
+        }
+        else
+        {
+            std::cout << "skip " << uriLink.toString() << std::endl;
+        }
+        offset = static_cast<int>(matches[0].offset + matches[0].length);
+    }
+}
+
 void HTTPPostTest::testConvertTo()
 {
     const auto srcPath = Util::getTempFilePath(TDOC, "hello.odt");


More information about the Libreoffice-commits mailing list