Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / filter / qa / cppunit / priority-test.cxx
blobb04aa125e09e2fb5a00508eeea9dd72cd61a7d8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
24 using namespace css;
26 namespace {
28 class PriorityFilterTest
29 : public test::BootstrapFixtureBase
31 public:
32 void testPriority();
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());
45 static struct {
46 const char *pURL;
47 const char *pFormat;
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);
56 try
58 OUString aTypeName = xDetection->queryTypeByURL(aURL);
60 OUString aFormatCorrect = OUString::createFromAscii(pFormat);
61 OUString aMsg = "Mis-matching formats "
62 "'" +
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: */