1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 // Unit test to check that we get the right filters for the right extensions.
12 #include <cppunit/TestAssert.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <sal/types.h>
18 #include <com/sun/star/document/XTypeDetection.hpp>
19 #include <comphelper/processfactory.hxx>
21 #include <unotest/bootstrapfixturebase.hxx>
28 class PriorityFilterTest
29 : public test::BootstrapFixtureBase
34 CPPUNIT_TEST_SUITE(PriorityFilterTest
);
35 CPPUNIT_TEST(testPriority
);
36 CPPUNIT_TEST_SUITE_END();
39 void PriorityFilterTest::testPriority()
41 uno::Reference
<document::XTypeDetection
> xDetection(
42 comphelper::getProcessServiceFactory()->createInstance(u
"com.sun.star.document.TypeDetection"_ustr
), uno::UNO_QUERY
);
43 CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection
.is());
48 } const aToCheck
[] = {
49 { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
50 // TODO: expand this to check more of these priorities
53 for (auto const[pURL
, pFormat
] : aToCheck
)
55 OUString aURL
= OUString::createFromAscii(pURL
);
58 OUString aTypeName
= xDetection
->queryTypeByURL(aURL
);
60 OUString aFormatCorrect
= OUString::createFromAscii(pFormat
);
61 OUString aMsg
= "Mis-matching formats "
63 aTypeName
+ "' should be '" + aFormatCorrect
+ "'";
64 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(aMsg
,
65 RTL_TEXTENCODING_UTF8
).getStr(),
66 aFormatCorrect
, aTypeName
);
68 catch (const uno::Exception
&e
)
70 OUString aMsg
= "Exception querying for type: '" + e
.Message
+ "'";
71 CPPUNIT_FAIL(OUStringToOString(aMsg
, RTL_TEXTENCODING_UTF8
).getStr());
76 CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest
);
80 CPPUNIT_PLUGIN_IMPLEMENT();
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */