summaryrefslogtreecommitdiffstats
path: root/filter/qa
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2014-07-07 18:04:33 +0100
committerMichael Meeks <michael.meeks@collabora.com>2014-07-07 18:05:18 +0100
commit0f8cf397d4de28ab9e16d4d1c6ca408323d7e189 (patch)
treed3f898843b2763380525196471dc1c57cd291e50 /filter/qa
parentfix build errors related to AVFoundation @ OS X <10.7 (diff)
downloadcore-0f8cf397d4de28ab9e16d4d1c6ca408323d7e189.tar.gz
core-0f8cf397d4de28ab9e16d4d1c6ca408323d7e189.zip
fdo#80955 - add a unit test.
Change-Id: Ie79a86827c4ee9feabcabf2530b30466f95905ed
Diffstat (limited to 'filter/qa')
-rw-r--r--filter/qa/cppunit/priority-test.cxx94
1 files changed, 94 insertions, 0 deletions
diff --git a/filter/qa/cppunit/priority-test.cxx b/filter/qa/cppunit/priority-test.cxx
new file mode 100644
index 000000000000..70093fb68d2e
--- /dev/null
+++ b/filter/qa/cppunit/priority-test.cxx
@@ -0,0 +1,94 @@
+/* -*- 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 <limits>
+
+#include <cppunit/TestAssert.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/plugin/TestPlugIn.h>
+
+#include <sal/types.h>
+#include <rtl/ustrbuf.hxx>
+
+#include <com/sun/star/document/XTypeDetection.hpp>
+#include <comphelper/processfactory.hxx>
+
+#include <unotest/bootstrapfixturebase.hxx>
+
+
+using namespace std;
+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;
+ } 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);
+ OUStringBuffer aMsg("Mis-matching formats ");
+ aMsg.append("'");
+ aMsg.append(aTypeName);
+ aMsg.append("' should be '");
+ aMsg.append(aFormatCorrect);
+ aMsg.append("'");
+ CPPUNIT_ASSERT_MESSAGE(rtl::OUStringToOString(aMsg.makeStringAndClear(),
+ RTL_TEXTENCODING_UTF8).getStr(),
+ aTypeName == aFormatCorrect);
+ }
+ catch (const uno::Exception &e)
+ {
+ OUStringBuffer aMsg("Exception querying for type: ");
+ aMsg.append("'");
+ aMsg.append(e.Message);
+ aMsg.append("'");
+ CPPUNIT_FAIL(rtl::OUStringToOString(aMsg.makeStringAndClear(),
+ RTL_TEXTENCODING_UTF8).getStr());
+ }
+ }
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest);
+
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */