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>
|
|
|
|
|
2023-05-21 08:59:20 -05:00
|
|
|
#include <test/lokassert.hpp>
|
|
|
|
#include <Unit.hpp>
|
|
|
|
#include <helpers.hpp>
|
|
|
|
#include <net/WebSocketSession.hpp>
|
|
|
|
#include "Util.hpp"
|
|
|
|
|
|
|
|
#include <chrono>
|
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>
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
void loadDoc(const std::string& documentURL, const std::string& testname)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>(testname + "Poll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
// Load a document and wait for the status.
|
|
|
|
// Don't replace with helpers, so we catch status.
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::connectLOKit(socketPoll, uri, documentURL, testname);
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
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:
|
2022-02-16 16:22:18 -06:00
|
|
|
UnitLoad()
|
|
|
|
: UnitWSD("UnitLoad")
|
|
|
|
{
|
2023-05-21 08:59:20 -05:00
|
|
|
setTimeout(std::chrono::seconds(60));
|
2022-02-16 16:22:18 -06:00
|
|
|
}
|
|
|
|
|
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 ");
|
|
|
|
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>(testname + "Poll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
// Connect and disconnect without loading.
|
|
|
|
TST_LOG_NAME(testname1, "Connecting first to disconnect without loading.");
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::connectLOKit(socketPoll, uri, documentURL, 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.");
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket1 =
|
|
|
|
helpers::connectLOKit(socketPoll, uri, documentURL, 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.");
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket2 =
|
|
|
|
helpers::connectLOKit(socketPoll, uri, documentURL, 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()
|
|
|
|
{
|
2023-09-14 06:33:01 -05:00
|
|
|
testname = __func__;
|
2019-11-22 02:07:24 -06:00
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
loadDoc(documentURL, "load ");
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnitBase::TestResult UnitLoad::testBadLoad()
|
|
|
|
{
|
2023-09-14 06:33:01 -05:00
|
|
|
testname = __func__;
|
2019-11-22 02:07:24 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get its status.
|
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>(testname + "Poll");
|
|
|
|
socketPoll->startThread();
|
|
|
|
|
2019-11-22 02:07:24 -06:00
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::connectLOKit(socketPoll, uri, documentURL, testname);
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
// Before loading request status.
|
2022-07-08 07:07:30 -05:00
|
|
|
helpers::sendTextFrame(socket, "status", testname);
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2023-09-14 06:33:01 -05:00
|
|
|
testname = __func__;
|
2019-11-22 02:07:24 -06:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// Load a document and get status.
|
|
|
|
Poco::URI uri(helpers::getTestServerURI());
|
2022-07-09 09:49:20 -05:00
|
|
|
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPoll = std::make_shared<SocketPoll>("ExcelLoadPoll");
|
2022-07-09 09:49:20 -05:00
|
|
|
socketPoll->startThread();
|
|
|
|
|
|
|
|
std::shared_ptr<http::WebSocketSession> socket =
|
|
|
|
helpers::loadDocAndGetSession(socketPoll, "timeline.xlsx", uri, testname);
|
2019-11-22 02:07:24 -06:00
|
|
|
|
|
|
|
helpers::sendTextFrame(socket, "status", testname);
|
|
|
|
const auto status = helpers::assertResponseString(socket, "status:", testname);
|
|
|
|
|
2023-09-14 14:41:51 -05:00
|
|
|
// Expected format is something like 'status: type=spreadsheet parts=1 current=0 width=20685 height=24885 viewid=0 lastcolumn=31 lastrow=12 readonly=0'
|
2022-03-29 20:37:57 -05:00
|
|
|
StringVector tokens(StringVector::tokenize(status, ' '));
|
2023-09-14 14:41:51 -05:00
|
|
|
LOK_ASSERT(tokens.size() >= 9);
|
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()
|
|
|
|
{
|
2023-09-14 06:33:01 -05:00
|
|
|
testname = __func__;
|
2019-11-22 02:07:24 -06:00
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
{
|
2023-05-21 08:59:20 -05:00
|
|
|
TST_LOG("Loading #" << (i + 1));
|
|
|
|
Util::Stopwatch sw;
|
2019-11-22 02:07:24 -06:00
|
|
|
loadDoc(documentURL, testname);
|
2023-05-21 08:59:20 -05:00
|
|
|
TST_LOG("Loaded #" << (i + 1) << " in " << sw.elapsed());
|
2019-11-22 02:07:24 -06:00
|
|
|
}
|
|
|
|
return TestResult::Ok;
|
|
|
|
}
|
|
|
|
|
2021-03-22 15:58:57 -05:00
|
|
|
UnitBase::TestResult UnitLoad::testLoad()
|
|
|
|
{
|
2023-09-14 06:33:01 -05:00
|
|
|
testname = __func__;
|
2021-03-22 15:58:57 -05:00
|
|
|
std::string documentPath, documentURL;
|
|
|
|
helpers::getDocumentPathAndURL("hello.odt", documentPath, documentURL, testname);
|
|
|
|
|
2022-07-12 06:36:48 -05:00
|
|
|
std::shared_ptr<SocketPoll> socketPollPtr = std::make_shared<SocketPoll>("LoadPoll");
|
2021-04-29 03:11:49 -05:00
|
|
|
socketPollPtr->startThread();
|
2021-03-22 15:58:57 -05:00
|
|
|
|
2021-03-24 21:30:04 -05:00
|
|
|
auto wsSession
|
2021-04-29 03:11:49 -05:00
|
|
|
= http::WebSocketSession::create(socketPollPtr, helpers::getTestServerURI(), documentURL);
|
2021-03-23 21:13:06 -05:00
|
|
|
|
2021-03-24 21:30:04 -05:00
|
|
|
TST_LOG("Loading " << documentURL);
|
2021-03-23 21:13:06 -05:00
|
|
|
wsSession->sendMessage("load url=" + documentURL);
|
|
|
|
|
2023-09-14 06:33:01 -05:00
|
|
|
std::vector<char> message = wsSession->waitForMessage("status:", std::chrono::seconds(10));
|
2021-03-23 22:57:53 -05:00
|
|
|
LOK_ASSERT_MESSAGE("Failed to load the document", !message.empty());
|
|
|
|
|
2021-04-12 23:48:47 -05:00
|
|
|
wsSession->asyncShutdown();
|
2021-04-11 15:06:08 -05:00
|
|
|
|
|
|
|
LOK_ASSERT_MESSAGE("Expected success disconnection of the WebSocket",
|
2023-09-14 06:33:01 -05:00
|
|
|
wsSession->waitForDisconnection(std::chrono::seconds(10)));
|
2021-04-11 15:06:08 -05:00
|
|
|
|
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
|
|
|
{
|
2021-03-23 21:13:06 -05:00
|
|
|
UnitBase::TestResult result = testLoad();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
|
|
|
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 = testExcelLoad();
|
|
|
|
if (result != TestResult::Ok)
|
|
|
|
exitTest(result);
|
|
|
|
|
2023-09-14 06:33:01 -05:00
|
|
|
// Disabling because it doesn't handle 'error: cmd=load kind=docunloading'
|
|
|
|
// when the document unloads. This leads to unreliable results.
|
|
|
|
// result = testReload();
|
|
|
|
// if (result != TestResult::Ok)
|
|
|
|
// exitTest(result);
|
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: */
|