nss: upgrade to release 3.73
[LibreOffice.git] / filter / qa / cppunit / priority-test.cxx
blob018d882a7215a621493bd04818ce50ead6e29b1b
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 std;
25 using namespace css;
27 namespace {
29 class PriorityFilterTest
30 : public test::BootstrapFixtureBase
32 public:
33 void testPriority();
35 CPPUNIT_TEST_SUITE(PriorityFilterTest);
36 CPPUNIT_TEST(testPriority);
37 CPPUNIT_TEST_SUITE_END();
40 void PriorityFilterTest::testPriority()
42 uno::Reference<document::XTypeDetection> xDetection(
43 comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
44 CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection.is());
46 static struct {
47 const char *pURL;
48 const char *pFormat;
49 } const aToCheck[] = {
50 { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
51 // TODO: expand this to check more of these priorities
54 for (size_t i = 0; i < SAL_N_ELEMENTS(aToCheck); i++)
56 OUString aURL = OUString::createFromAscii(aToCheck[i].pURL);
57 try
59 OUString aTypeName = xDetection->queryTypeByURL(aURL);
61 OUString aFormatCorrect = OUString::createFromAscii(aToCheck[i].pFormat);
62 OUString aMsg = "Mis-matching formats "
63 "'" +
64 aTypeName +
65 "' should be '" +
66 aFormatCorrect +
67 "'";
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(aMsg,
69 RTL_TEXTENCODING_UTF8).getStr(),
70 aFormatCorrect, aTypeName);
72 catch (const uno::Exception &e)
74 OUString aMsg = "Exception querying for type: '" + e.Message + "'";
75 CPPUNIT_FAIL(OUStringToOString(aMsg, RTL_TEXTENCODING_UTF8).getStr());
80 CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest);
84 CPPUNIT_PLUGIN_IMPLEMENT();
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */