[Libreoffice-commits] online.git: loolwsd/test
Henry Castro
hcastro at collabora.com
Tue Apr 26 01:00:58 UTC 2016
loolwsd/test/httpgettest.cpp | 54 +++++++++++++++++++++++++++++++++++++++
loolwsd/test/httpposttest.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+)
New commits:
commit 7317345a2badb363a2490ab1b32dcb776cb6dca3
Author: Henry Castro <hcastro at collabora.com>
Date: Mon Apr 25 21:01:46 2016 -0400
loolwsd: test: add testScripts
diff --git a/loolwsd/test/httpgettest.cpp b/loolwsd/test/httpgettest.cpp
index 2dd1df9..a1eecdc 100644
--- a/loolwsd/test/httpgettest.cpp
+++ b/loolwsd/test/httpgettest.cpp
@@ -34,12 +34,14 @@ class HTTPGetTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testDiscovery);
CPPUNIT_TEST(testLOleaflet);
CPPUNIT_TEST(testParams);
+ CPPUNIT_TEST(testScripts);
CPPUNIT_TEST_SUITE_END();
void testDiscovery();
void testLOleaflet();
void testParams();
+ void testScripts();
#if ENABLE_SSL
public:
@@ -124,6 +126,58 @@ void HTTPGetTest::testParams()
CPPUNIT_ASSERT(html.find(std::string(LOOLWSD_VERSION)) != std::string::npos);
}
+void HTTPGetTest::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_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 script("<script.*?src=\"(.*?)\"");
+ Poco::RegularExpression::MatchVec matches;
+ int offset = 0;
+
+ while (script.match(html, offset, matches) > 0)
+ {
+ CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
+ Poco::URI uriScript(html.substr(matches[1].offset, matches[1].length));
+ if (uriScript.getHost().empty())
+ {
+#if ENABLE_SSL
+ Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
+#else
+ Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
+#endif
+ std::cout << "checking... " << uriScript.toString();
+ Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, uriScript.toString());
+ sessionScript.sendRequest(requestScript);
+
+ Poco::Net::HTTPResponse responseScript;
+ sessionScript.receiveResponse(responseScript);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseScript.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("application/javascript"), responseScript.getContentType());
+ std::cout << " OK" << std::endl;
+ }
+ else
+ {
+ std::cout << "skip " << uriScript.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 2f764ce..8c7f637 100644
--- a/loolwsd/test/httpposttest.cpp
+++ b/loolwsd/test/httpposttest.cpp
@@ -40,6 +40,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testLOleaflet);
CPPUNIT_TEST(testParams);
+ CPPUNIT_TEST(testScripts);
CPPUNIT_TEST(testConvertTo);
// This should be the last test:
@@ -50,6 +51,7 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture
void testCountHowManyLoolkits();
void testLOleaflet();
void testParams();
+ void testScripts();
void testConvertTo();
void testNoExtraLoolKitsLeft();
@@ -130,6 +132,61 @@ void HTTPPostTest::testParams()
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=\"(.*?)\"");
+ Poco::RegularExpression::MatchVec matches;
+ int offset = 0;
+
+ while (script.match(html, offset, matches) > 0)
+ {
+ CPPUNIT_ASSERT_EQUAL(2, (int)matches.size());
+ Poco::URI uriScript(html.substr(matches[1].offset, matches[1].length));
+ if (uriScript.getHost().empty())
+ {
+#if ENABLE_SSL
+ Poco::Net::HTTPSClientSession sessionScript(uri.getHost(), uri.getPort());
+#else
+ Poco::Net::HTTPClientSession sessionScript(uri.getHost(), uri.getPort());
+#endif
+ std::cout << "checking... " << uriScript.toString();
+ Poco::Net::HTTPRequest requestScript(Poco::Net::HTTPRequest::HTTP_GET, uriScript.toString());
+ sessionScript.sendRequest(requestScript);
+
+ Poco::Net::HTTPResponse responseScript;
+ sessionScript.receiveResponse(responseScript);
+ CPPUNIT_ASSERT_EQUAL(Poco::Net::HTTPResponse::HTTP_OK, responseScript.getStatus());
+ CPPUNIT_ASSERT_EQUAL(std::string("application/javascript"), responseScript.getContentType());
+ std::cout << " OK" << std::endl;
+ }
+ else
+ {
+ std::cout << "skip " << uriScript.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