summaryrefslogtreecommitdiffstats
path: root/filter/qa/cppunit
diff options
context:
space:
mode:
Diffstat (limited to 'filter/qa/cppunit')
-rw-r--r--filter/qa/cppunit/data/xslt/copy.xslt9
-rw-r--r--filter/qa/cppunit/msfilter-test.cxx76
-rw-r--r--filter/qa/cppunit/priority-test.cxx85
-rw-r--r--filter/qa/cppunit/xslt-test.cxx207
4 files changed, 377 insertions, 0 deletions
diff --git a/filter/qa/cppunit/data/xslt/copy.xslt b/filter/qa/cppunit/data/xslt/copy.xslt
new file mode 100644
index 000000000..d46172a41
--- /dev/null
+++ b/filter/qa/cppunit/data/xslt/copy.xslt
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:template match="/">
+ <xsl:copy-of select="/"/>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/filter/qa/cppunit/msfilter-test.cxx b/filter/qa/cppunit/msfilter-test.cxx
new file mode 100644
index 000000000..439aad88b
--- /dev/null
+++ b/filter/qa/cppunit/msfilter-test.cxx
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+#include <tools/color.hxx>
+#include <filter/msfilter/util.hxx>
+
+#include <unotest/bootstrapfixturebase.hxx>
+
+namespace {
+
+class MSFilterTest
+ : public test::BootstrapFixtureBase
+{
+public:
+ void testTransColToIco();
+
+ CPPUNIT_TEST_SUITE(MSFilterTest);
+ CPPUNIT_TEST(testTransColToIco);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void MSFilterTest::testTransColToIco()
+{
+ const sal_uInt32 aStdCol[] = {
+ 0xeeeeee, 0xffff99, 0xff6600, 0xff3333, 0xff00cc, 0xff33ff, 0x9900ff, 0x6666ff, 0x00ccff, 0x66ffff, 0x33ff99, 0x99ff66, 0xccff00,
+ 0xdddddd, 0xffff66, 0xffcc00, 0xff9999, 0xff66cc, 0xff99ff, 0xcc66ff, 0x9999ff, 0x9999ff, 0x99ffff, 0x66ff99, 0x99ff99, 0xccff66,
+ 0xcccccc, 0xffff00, 0xff9900, 0xff6666, 0xff3399, 0xff66ff, 0x9933ff, 0x3333ff, 0x3399ff, 0x00ffff, 0x00ff66, 0x66ff66, 0x99ff33,
+ 0xb2b2b2, 0xcc9900, 0xff3300, 0xff0000, 0xff0066, 0xff00ff, 0x6600ff, 0x0000ff, 0x0066ff, 0x00cccc, 0x00cc33, 0x00cc00, 0x66ff00,
+ 0x999999, 0x996600, 0xcc3300, 0xcc0000, 0xcc0066, 0xcc00cc, 0x6600cc, 0x0000cc, 0x0066cc, 0x009999, 0x009933, 0x009900, 0x66cc00,
+ 0x808080, 0x663300, 0x801900, 0x990000, 0x990066, 0x990099, 0x330099, 0x000099, 0x006699, 0x006666, 0x007826, 0x006600, 0x669900,
+ 0x666666, 0x333300, 0x461900, 0x330000, 0x330033, 0x660066, 0x000033, 0x000066, 0x000080, 0x003333, 0x00331a, 0x003300, 0x193300,
+ 0x333333, 0x666633, 0x661900, 0x663333, 0x660033, 0x663366, 0x330066, 0x333366, 0x003366, 0x336666, 0x006633, 0x336633, 0x336600 };
+
+ const sal_uInt16 aExpected[] = {
+ 8, 7, 6, 6, 5, 5, 5, 2, 3, 3, 10, 4, 7,
+ 16, 7, 7, 6, 5, 5, 5, 2, 2, 3, 4, 4, 7,
+ 16, 7, 7, 6, 12, 5, 12, 2, 10, 3, 4, 4, 14,
+ 16, 14, 6, 6, 6, 5, 2, 2, 2, 3, 4, 4, 4,
+ 15, 14, 6, 6, 12, 5, 12, 2, 10, 10, 11, 11, 14,
+ 15, 1, 13, 13, 12, 12, 9, 9, 10, 10, 11, 11, 14,
+ 15, 14, 13, 13, 12, 12, 9, 9, 9, 10, 10, 11, 11,
+ 1, 14, 13, 13, 1, 12, 1, 9, 1, 10, 1, 11, 1 };
+
+ for( size_t i = 0; i < SAL_N_ELEMENTS(aStdCol); ++i)
+ {
+ const OString sMessage = "Index of unmatched color: " + OString::number(i);
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpected[i],
+ static_cast<sal_uInt16>(msfilter::util::TransColToIco( Color(ColorTransparency, aStdCol[i]) )));
+ }
+
+ // tdf#92471
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), static_cast<sal_uInt16>(msfilter::util::TransColToIco( Color( 0x6666ff ))));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), static_cast<sal_uInt16>(msfilter::util::TransColToIco( Color( 0x6566ff ))));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), static_cast<sal_uInt16>(msfilter::util::TransColToIco( Color( 0x6665ff ))));
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(2), static_cast<sal_uInt16>(msfilter::util::TransColToIco( Color( 0x6666fe ))));
+
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(MSFilterTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/qa/cppunit/priority-test.cxx b/filter/qa/cppunit/priority-test.cxx
new file mode 100644
index 000000000..18e63c318
--- /dev/null
+++ b/filter/qa/cppunit/priority-test.cxx
@@ -0,0 +1,85 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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/.
+ */
+
+// Unit test to check that we get the right filters for the right extensions.
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <comphelper/processfactory.hxx>
+
+#include <unotest/bootstrapfixturebase.hxx>
+
+
+using namespace css;
+
+namespace {
+
+class PriorityFilterTest
+ : public test::BootstrapFixtureBase
+{
+public:
+ void testPriority();
+
+ CPPUNIT_TEST_SUITE(PriorityFilterTest);
+ CPPUNIT_TEST(testPriority);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+void PriorityFilterTest::testPriority()
+{
+ uno::Reference<document::XTypeDetection> xDetection(
+ comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection.is());
+
+ static struct {
+ const char *pURL;
+ const char *pFormat;
+ } const aToCheck[] = {
+ { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
+ // TODO: expand this to check more of these priorities
+ };
+
+ for (size_t i = 0; i < SAL_N_ELEMENTS(aToCheck); i++)
+ {
+ OUString aURL = OUString::createFromAscii(aToCheck[i].pURL);
+ try
+ {
+ OUString aTypeName = xDetection->queryTypeByURL(aURL);
+
+ OUString aFormatCorrect = OUString::createFromAscii(aToCheck[i].pFormat);
+ OUString aMsg = "Mis-matching formats "
+ "'" +
+ aTypeName +
+ "' should be '" +
+ aFormatCorrect +
+ "'";
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(aMsg,
+ RTL_TEXTENCODING_UTF8).getStr(),
+ aFormatCorrect, aTypeName);
+ }
+ catch (const uno::Exception &e)
+ {
+ OUString aMsg = "Exception querying for type: '" + e.Message + "'";
+ CPPUNIT_FAIL(OUStringToOString(aMsg, RTL_TEXTENCODING_UTF8).getStr());
+ }
+ }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/qa/cppunit/xslt-test.cxx b/filter/qa/cppunit/xslt-test.cxx
new file mode 100644
index 000000000..4e0c621d6
--- /dev/null
+++ b/filter/qa/cppunit/xslt-test.cxx
@@ -0,0 +1,207 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 <sal/config.h>
+
+#include <condition_variable>
+#include <mutex>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+#include <sal/log.hxx>
+
+#include <rtl/ref.hxx>
+
+#include <osl/file.hxx>
+
+#include <com/sun/star/beans/NamedValue.hpp>
+#include <com/sun/star/io/XStreamListener.hpp>
+#include <com/sun/star/ucb/SimpleFileAccess.hpp>
+#include <com/sun/star/xml/xslt/XSLTTransformer.hpp>
+
+#include <cppuhelper/implbase.hxx>
+
+#include <test/bootstrapfixture.hxx>
+
+
+using namespace ::com::sun::star;
+
+
+namespace {
+
+class XsltFilterTest
+ : public test::BootstrapFixture
+{
+public:
+ void testXsltCopyOld();
+ void testXsltCopyNew();
+
+ CPPUNIT_TEST_SUITE(XsltFilterTest);
+ CPPUNIT_TEST(testXsltCopyOld);
+ CPPUNIT_TEST(testXsltCopyNew);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+class Listener : public ::cppu::WeakImplHelper<io::XStreamListener>
+{
+public:
+ Listener() : m_bDone(false) {}
+
+ void wait() {
+ std::unique_lock<std::mutex> g(m_mutex);
+ m_cond.wait(g, [this]() { return m_bDone; });
+ }
+
+private:
+ std::mutex m_mutex;
+ std::condition_variable m_cond;
+ bool m_bDone;
+
+ virtual void SAL_CALL disposing(const lang::EventObject&) noexcept override {}
+ virtual void SAL_CALL started() noexcept override {}
+ virtual void SAL_CALL closed() noexcept override { notifyDone(); }
+ virtual void SAL_CALL terminated() noexcept override { notifyDone(); }
+ virtual void SAL_CALL error(const uno::Any& e) override
+ {
+ notifyDone(); // set on error too, otherwise main thread waits forever
+ SAL_WARN("filter.xslt", e);
+ CPPUNIT_FAIL("exception while in XSLT");
+ }
+
+ void notifyDone() {
+ std::scoped_lock<std::mutex> g(m_mutex);
+ m_bDone = true;
+ m_cond.notify_all();
+ }
+};
+
+void XsltFilterTest::testXsltCopyNew()
+{
+ OUString tempDirURL;
+ osl_getTempDirURL(&tempDirURL.pData);
+ oslFileHandle tempFile;
+ OUString tempURL;
+ osl::File::RC rc = osl::File::createTempFile(nullptr, &tempFile, &tempURL);
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc);
+ osl_closeFile(tempFile); // close it so xSFA can open it on WNT
+
+ OUString source(
+ m_directories.getURLFromSrc(u"/filter/source/xsltfilter/xsltfilter.component"));
+ uno::Sequence<uno::Any> args{
+ uno::Any(beans::NamedValue("StylesheetURL",
+ uno::Any(m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/xslt/copy.xslt")))),
+ uno::Any(beans::NamedValue("SourceURL", uno::Any(source))),
+ uno::Any(beans::NamedValue("TargetURL", uno::Any(tempURL))),
+ uno::Any(beans::NamedValue("SourceBaseURL",
+ uno::Any(m_directories.getURLFromSrc(u"/filter/source/xsltfilter/")))),
+ uno::Any(beans::NamedValue("TargetBaseURL", uno::Any(tempDirURL))),
+ uno::Any(beans::NamedValue("SystemType", uno::Any(OUString()))),
+ uno::Any(beans::NamedValue("PublicType", uno::Any(OUString())))
+ };
+
+ uno::Reference<ucb::XSimpleFileAccess3> xSFA =
+ ucb::SimpleFileAccess::create(getComponentContext());
+
+ uno::Reference<io::XInputStream> xIn = xSFA->openFileRead(source);
+ uno::Reference<io::XOutputStream> xOut = xSFA->openFileWrite(tempURL);
+
+ rtl::Reference<Listener> xListener = new Listener();
+
+ uno::Reference<xml::xslt::XXSLTTransformer> xXslt(
+ xml::xslt::XSLTTransformer::create(getComponentContext(), args));
+
+ xXslt->addListener(xListener);
+ xXslt->setInputStream(xIn);
+ xXslt->setOutputStream(xOut);
+
+ xXslt->start();
+
+ xListener->wait();
+
+ xIn->closeInput();
+ xOut->closeOutput();
+
+ osl::File foo(tempURL); // apparently it's necessary to open it again?
+ foo.open(osl_File_OpenFlag_Read);
+ sal_uInt64 size(0);
+ foo.getSize(size);
+ CPPUNIT_ASSERT(size > 1000); // check that something happened
+ foo.close();
+ osl_removeFile(tempURL.pData);
+}
+
+void XsltFilterTest::testXsltCopyOld()
+{
+ OUString tempDirURL;
+ osl_getTempDirURL(&tempDirURL.pData);
+ oslFileHandle tempFile;
+ OUString tempURL;
+ osl::File::RC rc = osl::File::createTempFile(nullptr, &tempFile, &tempURL);
+ CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc);
+ osl_closeFile(tempFile); // close it so xSFA can open it on WNT
+
+ OUString source(
+ m_directories.getURLFromSrc(u"/filter/source/xsltfilter/xsltfilter.component"));
+ uno::Sequence<uno::Any> args{
+ uno::Any(beans::NamedValue("StylesheetURL",
+ uno::Any(m_directories.getURLFromSrc(u"/filter/qa/cppunit/data/xslt/copy.xslt")))),
+ uno::Any(beans::NamedValue("SourceURL", uno::Any(source))),
+ uno::Any(beans::NamedValue("TargetURL", uno::Any(tempURL))),
+ uno::Any(beans::NamedValue("SourceBaseURL",
+ uno::Any(m_directories.getURLFromSrc(u"/filter/source/xsltfilter/")))),
+ uno::Any(beans::NamedValue("TargetBaseURL", uno::Any(tempDirURL))),
+ uno::Any(beans::NamedValue("SystemType", uno::Any(OUString()))),
+ uno::Any(beans::NamedValue("PublicType", uno::Any(OUString())))
+ };
+
+ uno::Reference<ucb::XSimpleFileAccess3> xSFA =
+ ucb::SimpleFileAccess::create(getComponentContext());
+
+ uno::Reference<io::XInputStream> xIn = xSFA->openFileRead(source);
+ uno::Reference<io::XOutputStream> xOut = xSFA->openFileWrite(tempURL);
+
+ rtl::Reference<Listener> xListener = new Listener();
+
+ uno::Reference<xml::xslt::XXSLTTransformer> xXslt(
+ getMultiServiceFactory()->createInstance(
+ "com.sun.star.comp.documentconversion.LibXSLTTransformer"),
+ uno::UNO_QUERY_THROW);
+
+ uno::Reference<lang::XInitialization> xInit(xXslt, uno::UNO_QUERY_THROW);
+ xInit->initialize(args);
+ xXslt->addListener(xListener);
+ xXslt->setInputStream(xIn);
+ xXslt->setOutputStream(xOut);
+
+ xXslt->start();
+
+ xListener->wait();
+
+ xIn->closeInput();
+ xOut->closeOutput();
+
+ osl::File foo(tempURL); // apparently it's necessary to open it again?
+ foo.open(osl_File_OpenFlag_Read);
+ sal_uInt64 size(0);
+ foo.getSize(size);
+ CPPUNIT_ASSERT(size > 1000); // check that something happened
+ foo.close();
+ osl_removeFile(tempURL.pData);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(XsltFilterTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */