summaryrefslogtreecommitdiff
path: root/test/UnitRenderingOptions.cpp
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-10-25 08:54:46 +0200
committerMiklos Vajna <vmiklos@collabora.com>2019-10-25 08:54:46 +0200
commitcdec2c78700a77a1a927ec1ff7ea2d1751505da8 (patch)
tree3da12a8d19a91d3ad1d8f5930790f038956b87e3 /test/UnitRenderingOptions.cpp
parent564b36f01ae271357e79754269f3d30f475fbc79 (diff)
Convert rendering options to a new-style one
So that they are in-process, which means it's easier to debug when they fail. Change-Id: I817812eaeaffea4de8bb3a90466d815d4047372c
Diffstat (limited to 'test/UnitRenderingOptions.cpp')
-rw-r--r--test/UnitRenderingOptions.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/UnitRenderingOptions.cpp b/test/UnitRenderingOptions.cpp
new file mode 100644
index 000000000..526eed06c
--- /dev/null
+++ b/test/UnitRenderingOptions.cpp
@@ -0,0 +1,74 @@
+/* -*- 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 <memory>
+#include <string>
+
+#include <Poco/URI.h>
+#include <cppunit/TestAssert.h>
+
+#include <Unit.hpp>
+#include <Util.hpp>
+#include <helpers.hpp>
+
+class LOOLWebSocket;
+
+/// Rendering options testcase.
+class UnitRenderingOptions : public UnitWSD
+{
+public:
+ void invokeTest() override;
+};
+
+void UnitRenderingOptions::invokeTest()
+{
+ const char testname[] = "UnitRenderingOptions";
+
+ try
+ {
+ // Load a document and make it empty, then paste some text into it.
+ std::string documentPath;
+ std::string documentURL;
+ helpers::getDocumentPathAndURL("hide-whitespace.odt", documentPath, documentURL, testname);
+
+ const std::string options
+ = "{\"rendering\":{\".uno:HideWhitespace\":{\"type\":\"boolean\",\"value\":\"true\"}}}";
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
+ Poco::Net::HTTPResponse response;
+ std::shared_ptr<LOOLWebSocket> socket = helpers::connectLOKit(
+ Poco::URI(helpers::getTestServerURI()), request, response, testname);
+
+ helpers::sendTextFrame(socket, "load url=" + documentURL + " options=" + options);
+ helpers::sendTextFrame(socket, "status");
+ const auto status = helpers::assertResponseString(socket, "status:", testname);
+
+ // Expected format is something like 'status: type=text parts=2 current=0 width=12808 height=1142'.
+ Poco::StringTokenizer tokens(
+ status, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(7), tokens.count());
+
+ const std::string token = tokens[5];
+ const std::string prefix = "height=";
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), token.find(prefix));
+ const int height = std::stoi(token.substr(prefix.size()));
+ // HideWhitespace was ignored, this was 32532, should be around 16706.
+ CPPUNIT_ASSERT(height < 20000);
+ }
+ catch (const Poco::Exception& exc)
+ {
+ CPPUNIT_FAIL(exc.displayText());
+ }
+
+ exitTest(TestResult::Ok);
+}
+
+UnitBase* unit_create_wsd(void) { return new UnitRenderingOptions(); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */