[Libreoffice-commits] online.git: loolwsd/.gitignore loolwsd/test
Henry Castro
hcastro at collabora.com
Thu Oct 6 18:29:08 UTC 2016
loolwsd/.gitignore | 1
loolwsd/test/Makefile.am | 14 +++++
loolwsd/test/testlokit.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 2 deletions(-)
New commits:
commit 9b1087e000a5e1ca5ebf9e9c25c8a31705ce6795
Author: Henry Castro <hcastro at collabora.com>
Date: Thu Oct 6 10:02:49 2016 -0400
loolwsd: test: .uno:AutoSum
diff --git a/loolwsd/.gitignore b/loolwsd/.gitignore
index d98297b..d2ff61f 100644
--- a/loolwsd/.gitignore
+++ b/loolwsd/.gitignore
@@ -56,3 +56,4 @@ loolstress
loolforkit-nocaps
loadtest
unittest
+testlokit
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
index 70c073a..1cf21fe 100644
--- a/loolwsd/test/Makefile.am
+++ b/loolwsd/test/Makefile.am
@@ -7,7 +7,7 @@ AUTOMAKE_OPTION = serial-tests
# test: tests that need loolwsd running, and that are run via 'make check'
check_PROGRAMS = test
-noinst_PROGRAMS = test unittest
+noinst_PROGRAMS = test unittest testlokit
AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
@@ -46,6 +46,10 @@ unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS
unittest_SOURCES = TileQueueTests.cpp WhiteBoxTests.cpp test.cpp $(wsd_sources)
unittest_LDADD = $(CPPUNIT_LIBS)
+testlokit_CPPFLAGS = -DTDOC=\"$(abs_top_srcdir)/test/data\" -I$(top_srcdir) -DBUILDING_TESTS
+testlokit_SOURCES = testlokit.cpp test.cpp $(wsd_sources)
+testlokit_LDADD = $(CPPUNIT_LIBS)
+
# unit test modules:
unit_fuzz_la_SOURCES = UnitFuzz.cpp
unit_admin_la_SOURCES = UnitAdmin.cpp
@@ -65,7 +69,13 @@ SYSTEM_STAMP =
endif
if HAVE_LO_PATH
-check-local:
+check-lokit: testlokit
+ @echo
+ @echo "Running testlokit."
+ @echo
+ @JAIL_PATH="file://@JAILS_PATH@/user" LO_PATH="@LO_PATH@/program" ${top_builddir}/test/testlokit > check-lokit.log 2>&1 || { cat check-lokit.log ; exit 1 ; }
+
+check-local: check-lokit
./run_unit.sh --log-file test.log --trs-file test.trs
# FIXME unit-fonts.la is unstable, disabled for now.
TESTS = unit-timeout.la unit-prefork.la unit-tilecache.la unit-admin.la unit-storage.la
diff --git a/loolwsd/test/testlokit.cpp b/loolwsd/test/testlokit.cpp
new file mode 100644
index 0000000..5d02c20
--- /dev/null
+++ b/loolwsd/test/testlokit.cpp
@@ -0,0 +1,107 @@
+/* -*- 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 "config.h"
+
+#include <mutex>
+#include <cassert>
+#include <memory>
+#include <condition_variable>
+
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitInit.h>
+
+#include "LibreOfficeKit.hpp"
+
+#include <cppunit/extensions/HelperMacros.h>
+
+class TestLOKit : public CPPUNIT_NS::TestFixture
+{
+ std::shared_ptr<lok::Office> _loKit;
+
+ CPPUNIT_TEST_SUITE(TestLOKit);
+
+ CPPUNIT_TEST(testAutoSum);
+
+ CPPUNIT_TEST_SUITE_END();
+
+ void testAutoSum();
+
+public:
+ bool _readyCallback;
+ std::string _cellFormula;
+ std::condition_variable _cvCallback;
+
+ TestLOKit()
+ {
+ char* userdir = getenv("JAIL_PATH");
+ CPPUNIT_ASSERT_MESSAGE("JAIL_PATH env variable not set", userdir != nullptr);
+
+ char* instdir = getenv("LO_PATH");
+ CPPUNIT_ASSERT_MESSAGE("LO_PATH env variable not set", instdir != nullptr);
+
+ _loKit = std::make_shared<lok::Office>(lok_init_2(instdir, userdir));
+ if (!_loKit || !_loKit->get())
+ {
+ CPPUNIT_FAIL("LibreOfficeKit initialization failed.");
+ }
+ }
+
+ ~TestLOKit()
+ {
+ }
+
+ static void ViewCallback(const int type, const char* payload, void* data)
+ {
+ if (data == nullptr)
+ {
+ CPPUNIT_FAIL("Data is nullptr");
+ }
+
+ TestLOKit* test = static_cast<TestLOKit*>(data);
+
+ switch (type)
+ {
+ case LOK_CALLBACK_CELL_FORMULA:
+ {
+ test->_cellFormula = payload;
+ test->_readyCallback = true;
+ test->_cvCallback.notify_one();
+ }
+ }
+ }
+
+ void setUp()
+ {
+ }
+
+ void tearDown()
+ {
+ }
+};
+
+void TestLOKit::testAutoSum()
+{
+ std::shared_ptr<lok::Document> doc = _loKit->documentLoad(TDOC"/empty.ods");
+ CPPUNIT_ASSERT(doc);
+
+ std::mutex mutex;
+ doc->initializeForRendering("");
+ doc->registerCallback(ViewCallback, this);
+ doc->postUnoCommand(".uno:AutoSum");
+
+ std::unique_lock<std::mutex> lock(mutex);
+ _cvCallback.wait_for(lock, std::chrono::seconds(2), [this] { return _readyCallback; });
+ doc->registerCallback(nullptr, nullptr);
+ CPPUNIT_ASSERT(_cellFormula.find("=SUM(") != std::string::npos);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(TestLOKit);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list