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.
14 #include <cppunit/TestAssert.h>
15 #include <cppunit/TestFixture.h>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <cppunit/plugin/TestPlugIn.h>
19 #include <sal/types.h>
20 #include <rtl/ustrbuf.hxx>
22 #include <com/sun/star/document/XTypeDetection.hpp>
23 #include <comphelper/processfactory.hxx>
25 #include <unotest/bootstrapfixturebase.hxx>
33 class PriorityFilterTest
34 : public test::BootstrapFixtureBase
39 CPPUNIT_TEST_SUITE(PriorityFilterTest
);
40 CPPUNIT_TEST(testPriority
);
41 CPPUNIT_TEST_SUITE_END();
44 void PriorityFilterTest::testPriority()
46 uno::Reference
<document::XTypeDetection
> xDetection(
47 comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY
);
48 CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection
.is());
54 { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
55 // TODO: expand this to check more of these priorities
58 for (size_t i
= 0; i
< SAL_N_ELEMENTS(aToCheck
); i
++)
60 OUString aURL
= OUString::createFromAscii(aToCheck
[i
].pURL
);
63 OUString aTypeName
= xDetection
->queryTypeByURL(aURL
);
65 OUString aFormatCorrect
= OUString::createFromAscii(aToCheck
[i
].pFormat
);
66 OUStringBuffer
aMsg("Mis-matching formats ");
68 aMsg
.append(aTypeName
);
69 aMsg
.append("' should be '");
70 aMsg
.append(aFormatCorrect
);
72 CPPUNIT_ASSERT_MESSAGE(rtl::OUStringToOString(aMsg
.makeStringAndClear(),
73 RTL_TEXTENCODING_UTF8
).getStr(),
74 aTypeName
== aFormatCorrect
);
76 catch (const uno::Exception
&e
)
78 OUStringBuffer
aMsg("Exception querying for type: ");
80 aMsg
.append(e
.Message
);
82 CPPUNIT_FAIL(rtl::OUStringToOString(aMsg
.makeStringAndClear(),
83 RTL_TEXTENCODING_UTF8
).getStr());
88 CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest
);
92 CPPUNIT_PLUGIN_IMPLEMENT();
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */