[Libreoffice-commits] online.git: 2 commits - loolwsd/configure.ac loolwsd/.gitignore loolwsd/Makefile.am loolwsd/test
Miklos Vajna
vmiklos at collabora.co.uk
Wed Oct 21 04:52:14 PDT 2015
loolwsd/.gitignore | 1
loolwsd/Makefile.am | 2 +
loolwsd/configure.ac | 10 +++++++
loolwsd/test/.gitignore | 9 ++++++
loolwsd/test/Makefile.am | 13 +++++++++
loolwsd/test/data/hello.odt |binary
loolwsd/test/data/hello.txt | 1
loolwsd/test/httpposttest.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++
loolwsd/test/test.cpp | 36 +++++++++++++++++++++++++
9 files changed, 131 insertions(+)
New commits:
commit 3ed78cce6fa1292e4bb5cfbe872f3dd2e6cffc0e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Oct 21 13:44:35 2015 +0200
loolwsd: add HTTP POST convert-to testcase
Fails with 8f90c38844ba6840acd97c6a72eb104d1171dc8d (loolwsd convert-to:
implement actual conversion, 2015-10-20) reverted.
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
index 13230ee..9a4a7d5 100644
--- a/loolwsd/test/httpposttest.cpp
+++ b/loolwsd/test/httpposttest.cpp
@@ -7,8 +7,18 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <Poco/Net/FilePartSource.h>
+#include <Poco/Net/HTMLForm.h>
+#include <Poco/Net/HTTPClientSession.h>
+#include <Poco/Net/HTTPRequest.h>
+#include <Poco/Net/HTTPResponse.h>
+#include <Poco/StreamCopier.h>
+#include <Poco/URI.h>
#include <cppunit/extensions/HelperMacros.h>
+#include <LOOLWSD.hpp>
+
+/// Tests the HTTP POST API of loolwsd. The server has to be started manually before running this test.
class HTTPPostTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(HTTPPostTest);
@@ -20,6 +30,28 @@ class HTTPPostTest : public CPPUNIT_NS::TestFixture
void HTTPPostTest::testConvertTo()
{
+ Poco::URI uri("http://127.0.0.1:" + std::to_string(LOOLWSD::DEFAULT_CLIENT_PORT_NUMBER) + "/convert-to");
+ Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/convert-to");
+ Poco::Net::HTMLForm form;
+ form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
+ form.set("format", "txt");
+ form.addPart("data", new Poco::Net::FilePartSource(TDOC "/hello.odt"));
+ form.prepareSubmit(request);
+ // If this results in a Poco::Net::ConnectionRefusedException, loolwsd is not running.
+ form.write(session.sendRequest(request));
+
+ Poco::Net::HTTPResponse response;
+ std::stringstream actualStream;
+ // receiveResponse() resulted in a Poco::Net::NoMessageException.
+ std::istream& responseStream = session.receiveResponse(response);
+ Poco::StreamCopier::copyStream(responseStream, actualStream);
+
+ std::ifstream fileStream(TDOC "/hello.txt");
+ std::stringstream expectedStream;
+ expectedStream << fileStream.rdbuf();
+ CPPUNIT_ASSERT_EQUAL(expectedStream.str(), actualStream.str());
}
CPPUNIT_TEST_SUITE_REGISTRATION(HTTPPostTest);
commit 443486117af44dfe314ff1d0af75af5fec0d759f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Oct 21 12:01:47 2015 +0200
loolwsd: cppunit skeleton
diff --git a/loolwsd/.gitignore b/loolwsd/.gitignore
index 101239d..fd499f2 100644
--- a/loolwsd/.gitignore
+++ b/loolwsd/.gitignore
@@ -17,6 +17,7 @@
/install-sh
/missing
/stamp-h1
+/test-driver
*.o
*.exe
diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am
index e0e3fb9..c86f449 100644
--- a/loolwsd/Makefile.am
+++ b/loolwsd/Makefile.am
@@ -1,3 +1,5 @@
+SUBDIRS = test
+
bin_PROGRAMS = loolwsd
dist_bin_SCRIPTS = loolwsd-systemplate-setup
diff --git a/loolwsd/configure.ac b/loolwsd/configure.ac
index f3acfb0..5e219d5 100644
--- a/loolwsd/configure.ac
+++ b/loolwsd/configure.ac
@@ -46,6 +46,10 @@ AC_ARG_WITH([libpng-libs],
AS_HELP_STRING([--with-libpng-libs=<path>],
[Path the "lib" directory with the libpng libraries]))
+AC_ARG_ENABLE([tests],
+ AS_HELP_STRING([--disable-tests],
+ [Build and run unit tests]))
+
# Handle options
AS_IF([test "$enable_debug" = yes -a -n "$with_poco_libs"],
[POCO_DEBUG_SUFFIX=d],
@@ -95,6 +99,9 @@ AS_IF([test `uname -s` = Linux],
[],
[AC_MSG_ERROR([libcap not available?])])])
+AS_IF([test "$enable_tests" != "no"],
+ [PKG_CHECK_MODULES([CPPUNIT], [cppunit])])
+
LIBS="$LIBS -lPocoNet${POCO_DEBUG_SUFFIX} -lPocoUtil${POCO_DEBUG_SUFFIX} -lPocoXML${POCO_DEBUG_SUFFIX} -lPocoJSON${POCO_DEBUG_SUFFIX} -lPocoFoundation${POCO_DEBUG_SUFFIX}"
AC_CHECK_HEADERS([LibreOfficeKit/LibreOfficeKit.h],
@@ -141,7 +148,10 @@ AC_DEFINE_UNQUOTED([LOOLWSD_CACHEDIR],["$LOOLWSD_CACHEDIR"],[Cache folder])
AC_SUBST(LOOLWSD_CACHEDIR)
AC_CONFIG_FILES([Makefile
+ test/Makefile
loolwsd.spec])
AC_OUTPUT
AC_LANG_POP
+
+dnl vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/loolwsd/test/.gitignore b/loolwsd/test/.gitignore
new file mode 100644
index 0000000..81defda
--- /dev/null
+++ b/loolwsd/test/.gitignore
@@ -0,0 +1,9 @@
+# Autofoo
+/.deps
+/Makefile
+/Makefile.in
+*.log
+*.trs
+
+*.o
+test
diff --git a/loolwsd/test/Makefile.am b/loolwsd/test/Makefile.am
new file mode 100644
index 0000000..a161b0f
--- /dev/null
+++ b/loolwsd/test/Makefile.am
@@ -0,0 +1,13 @@
+check_PROGRAMS = test
+
+AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
+
+test_CPPFLAGS = -DTDOC=\"$(top_srcdir)/test/data\"
+
+test_LDADD = $(CPPUNIT_LIBS)
+
+test_SOURCES = httpposttest.cpp test.cpp
+
+EXTRA_DIST = data/hello.odt data/hello.txt $(test_SOURCES)
+
+TESTS = test
diff --git a/loolwsd/test/data/hello.odt b/loolwsd/test/data/hello.odt
new file mode 100644
index 0000000..8340bfb
Binary files /dev/null and b/loolwsd/test/data/hello.odt differ
diff --git a/loolwsd/test/data/hello.txt b/loolwsd/test/data/hello.txt
new file mode 100644
index 0000000..8f2d6bd
--- /dev/null
+++ b/loolwsd/test/data/hello.txt
@@ -0,0 +1 @@
+Hello world
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
new file mode 100644
index 0000000..13230ee
--- /dev/null
+++ b/loolwsd/test/httpposttest.cpp
@@ -0,0 +1,27 @@
+/* -*- 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 <cppunit/extensions/HelperMacros.h>
+
+class HTTPPostTest : public CPPUNIT_NS::TestFixture
+{
+ CPPUNIT_TEST_SUITE(HTTPPostTest);
+ CPPUNIT_TEST(testConvertTo);
+ CPPUNIT_TEST_SUITE_END();
+
+ void testConvertTo();
+};
+
+void HTTPPostTest::testConvertTo()
+{
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(HTTPPostTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/test.cpp b/loolwsd/test/test.cpp
new file mode 100644
index 0000000..96a071e
--- /dev/null
+++ b/loolwsd/test/test.cpp
@@ -0,0 +1,36 @@
+/* -*- 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 <iostream>
+#include <cppunit/TestRunner.h>
+#include <cppunit/TestResult.h>
+#include <cppunit/TestResultCollector.h>
+#include <cppunit/BriefTestProgressListener.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/CompilerOutputter.h>
+
+int main()
+{
+ CPPUNIT_NS::TestResult controller;
+ CPPUNIT_NS::TestResultCollector result;
+ controller.addListener(&result);
+ CPPUNIT_NS::BriefTestProgressListener progress;
+ controller.addListener(&progress);
+
+ CPPUNIT_NS::TestRunner runner;
+ runner.addTest(CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest());
+ runner.run(controller);
+
+ CPPUNIT_NS::CompilerOutputter outputter(&result, std::cerr);
+ outputter.write();
+
+ return result.wasSuccessful() ? 0 : 1;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
More information about the Libreoffice-commits
mailing list