2019-11-22 02:07:24 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2021-03-25 08:47:10 -05:00
|
|
|
#include <config.h>
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
#include <memory>
|
|
|
|
#include <ostream>
|
|
|
|
#include <set>
|
|
|
|
#include <string>
|
2021-03-23 21:13:06 -05:00
|
|
|
#include <thread>
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
#include <Poco/Exception.h>
|
|
|
|
#include <Poco/URI.h>
|
2021-03-23 21:13:06 -05:00
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
|
|
|
|
2020-01-20 10:45:53 -06:00
|
|
|
#include <test/lokassert.hpp>
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <helpers.hpp>
|
2021-03-23 21:13:06 -05:00
|
|
|
#include <net/WebSocketSession.hpp>
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
class LOOLWebSocket;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void loadDoc(const std::string& documentURL, const std::string& testname)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and wait for the status.
|
|
|
|
// Don't replace with helpers, so we catch status.
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
Poco::Net::HTTPResponse response;
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket
|
|
|
|
= helpers::connectLOKit(uri, request, response, testname);
|
|
|
|
helpers::sendTextFrame(socket, "load url=" + documentURL, testname);
|
|
|
|
|
|
|
|
helpers::assertResponseString(socket, "status:", testname);
|
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Test suite for loading.
|
|
|
|
class UnitLoad : public UnitWSD
|
|
|
|
{
|
|
|
|
TestResult testConnectNoLoad();
|
|
|
|
TestResult testLoadSimple();
|
|
|
|
TestResult testBadLoad();
|
|
|
|
TestResult testExcelLoad();
|
|
|
|
TestResult testReload();
|
2021-03-22 15:58:57 -05:00
|
|
|
TestResult testLoad();
|
2019-11-22 02:07:24 -06:00
|
|
|
|
2021-03-23 21:13:06 -05:00
|
|
|
void configure(Poco::Util::LayeredConfiguration& config) override
|
|
|
|
{
|
|
|
|
UnitWSD::configure(config);
|
|
|
|
|
|
|
|
config.setBool("ssl.enable", true);
|
|
|
|
}
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
public:
|
2020-12-24 11:15:37 -06:00
|
|
|
void invokeWSDTest() override;
|
2019-11-22 02:07:24 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testConnectNoLoad()
|
|
|
|
{
|
|
|
|
const char* testname1 = "connectNoLoad-1 ";
|
|
|
|
const char* testname2 = "connectNoLoad-2 ";
|
|
|
|
const char* testname3 = "connectNoLoad-3 ";
|
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, "connectNoLoad ");
|
|
|
|
|
|
|
|
// Connect and disconnect without loading.
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
|
|
|
TST_LOG_NAME(testname1, "Connecting first to disconnect without loading.");
|
|
|
|
Poco::Net::HTTPResponse response;
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket
|
|
|
|
= helpers::connectLOKit(uri, request, response, testname1);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("Failed to connect.", socket);
|
2019-11-22 02:07:24 -06:00
|
|
|
TST_LOG_NAME(testname1, "Disconnecting first.");
|
|
|
|
socket.reset();
|
|
|
|
|
2019-12-06 01:51:51 -06:00
|
|
|
sleep(1); // paranoia.
|
2019-12-05 01:48:26 -06:00
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
// Connect and load first view.
|
|
|
|
TST_LOG_NAME(testname2, "Connecting second to load first view.");
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket1
|
|
|
|
= helpers::connectLOKit(uri, request, response, testname2);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("Failed to connect.", socket1);
|
2019-11-22 02:07:24 -06:00
|
|
|
helpers::sendTextFrame(socket1, "load url=" + documentURL, testname2);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("cannot load the document " + documentURL,
|
2019-11-22 02:07:24 -06:00
|
|
|
helpers::isDocumentLoaded(socket1, testname2));
|
|
|
|
|
|
|
|
// Connect but don't load second view.
|
|
|
|
TST_LOG_NAME(testname3, "Connecting third to disconnect without loading.");
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket2
|
|
|
|
= helpers::connectLOKit(uri, request, response, testname3);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_MESSAGE("Failed to connect.", socket2);
|
2019-11-22 02:07:24 -06:00
|
|
|
TST_LOG_NAME(testname3, "Disconnecting third.");
|
|
|
|
socket2.reset();
|
|
|
|
|
|
|
|
TST_LOG_NAME(testname2, "Getting status from first view.");
|
|
|
|
helpers::sendTextFrame(socket1, "status", testname2);
|
|
|
|
helpers::assertResponseString(socket1, "status:", testname2);
|
|
|
|
|
|
|
|
TST_LOG_NAME(testname2, "Disconnecting second.");
|
|
|
|
socket1.reset();
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testLoadSimple()
|
|
|
|
{
|
|
|
|
const char* testname = "loadSimple ";
|
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
loadDoc(documentURL, "load ");
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testBadLoad()
|
|
|
|
{
|
|
|
|
const char* testname = "badLoad ";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get its status.
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
|
|
|
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
Poco::Net::HTTPResponse response;
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket
|
|
|
|
= helpers::connectLOKit(uri, request, response, testname);
|
|
|
|
|
|
|
|
// Before loading request status.
|
|
|
|
helpers::sendTextFrame(socket, "status");
|
|
|
|
|
|
|
|
const auto line = helpers::assertResponseString(socket, "error:", testname);
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(std::string("error: cmd=status kind=nodocloaded"), line);
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testExcelLoad()
|
|
|
|
{
|
|
|
|
const char* testname = "excelLoad ";
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get status.
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
std::shared_ptr<LOOLWebSocket> socket
|
|
|
|
= helpers::loadDocAndGetSocket("timeline.xlsx", uri, testname);
|
|
|
|
|
|
|
|
helpers::sendTextFrame(socket, "status", testname);
|
|
|
|
const auto status = helpers::assertResponseString(socket, "status:", testname);
|
|
|
|
|
|
|
|
// Expected format is something like 'status: type=text parts=2 current=0 width=12808 height=1142 viewid=0\n...'.
|
2020-05-21 09:22:49 -05:00
|
|
|
StringVector tokens(Util::tokenize(status, ' '));
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_EQUAL(static_cast<size_t>(7), tokens.size());
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
catch (const Poco::Exception& exc)
|
|
|
|
{
|
2020-01-20 10:45:53 -06:00
|
|
|
LOK_ASSERT_FAIL(exc.displayText());
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testReload()
|
|
|
|
{
|
|
|
|
const char* testname = "reload ";
|
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
|
|
|
TST_LOG("loading #" << (i + 1));
|
|
|
|
loadDoc(documentURL, testname);
|
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
2021-03-22 15:58:57 -05:00
|
|
|
UnitBase::TestResult UnitLoad::testLoad()
|
|
|
|
{
|
|
|
|
const char* testname = "load ";
|
|
|
|
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
|
|
|
// Start the polling thread.
|
|
|
|
SocketPoll pollThread("WsAsyncReqPoll");
|
|
|
|
pollThread.startThread();
|
|
|
|
|
|
|
|
http::Request httpRequest(documentURL);
|
2021-03-23 21:13:06 -05:00
|
|
|
auto wsSession = http::WebSocketSession::create(helpers::getTestServerURI());
|
|
|
|
wsSession->asyncRequest(httpRequest, pollThread);
|
|
|
|
|
|
|
|
TST_LOG(">>> Loading");
|
|
|
|
wsSession->sendMessage("load url=" + documentURL);
|
|
|
|
|
|
|
|
TST_LOG(">>> Sleeping");
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(20));
|
|
|
|
TST_LOG(">>> Woke up");
|
2021-03-22 15:58:57 -05:00
|
|
|
|
|
|
|
// Load a document and wait for the status.
|
|
|
|
// Don't replace with helpers, so we catch status.
|
2021-03-23 21:13:06 -05:00
|
|
|
// Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
|
|
|
|
// Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
// Poco::Net::HTTPResponse response;
|
|
|
|
// std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(uri, request, response, testname);
|
|
|
|
// helpers::sendTextFrame(socket, "load url=" + documentURL, testname);
|
2021-03-22 15:58:57 -05:00
|
|
|
|
2021-03-23 21:13:06 -05:00
|
|
|
// helpers::assertResponseString(socket, "status:", testname);
|
2021-03-22 15:58:57 -05:00
|
|
|
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
2020-12-24 11:15:37 -06:00
|
|
|
void UnitLoad::invokeWSDTest()
|
2019-11-22 02:07:24 -06:00
|
|
|
{
|
2019-12-06 03:22:54 -06:00
|
|
|
// FIXME fails on Jenkins for some reason.
|
2021-03-23 21:13:06 -05:00
|
|
|
UnitBase::TestResult result = testLoad();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
2019-12-06 03:22:54 -06:00
|
|
|
#if 0
|
2021-03-23 21:13:06 -05:00
|
|
|
result = testConnectNoLoad();
|
2019-11-22 02:07:24 -06:00
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testLoadSimple();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testLoadSimple();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testExcelLoad();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
result = testReload();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
2019-12-06 03:22:54 -06:00
|
|
|
#endif
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
exitTest(TestResult::Ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase* unit_create_wsd(void) { return new UnitLoad(); }
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|