Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : // Unit test to check that we get the right filters for the right extensions.
11 :
12 : #include <limits>
13 :
14 : #include <cppunit/TestAssert.h>
15 : #include <cppunit/TestFixture.h>
16 : #include <cppunit/extensions/HelperMacros.h>
17 : #include <cppunit/plugin/TestPlugIn.h>
18 :
19 : #include <sal/types.h>
20 : #include <rtl/ustrbuf.hxx>
21 :
22 : #include <com/sun/star/document/XTypeDetection.hpp>
23 : #include <comphelper/processfactory.hxx>
24 :
25 : #include <unotest/bootstrapfixturebase.hxx>
26 :
27 :
28 : using namespace std;
29 : using namespace css;
30 :
31 : namespace {
32 :
33 6 : class PriorityFilterTest
34 : : public test::BootstrapFixtureBase
35 : {
36 : public:
37 : void testPriority();
38 :
39 4 : CPPUNIT_TEST_SUITE(PriorityFilterTest);
40 2 : CPPUNIT_TEST(testPriority);
41 4 : CPPUNIT_TEST_SUITE_END();
42 : };
43 :
44 2 : void PriorityFilterTest::testPriority()
45 : {
46 : uno::Reference<document::XTypeDetection> xDetection(
47 2 : comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
48 2 : CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection.is());
49 :
50 : static struct {
51 : const char *pURL;
52 : const char *pFormat;
53 : } aToCheck[] = {
54 : { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
55 : // TODO: expand this to check more of these priorities
56 : };
57 :
58 4 : for (size_t i = 0; i < SAL_N_ELEMENTS(aToCheck); i++)
59 : {
60 2 : OUString aURL = OUString::createFromAscii(aToCheck[i].pURL);
61 : try
62 : {
63 2 : OUString aTypeName = xDetection->queryTypeByURL(aURL);
64 :
65 4 : OUString aFormatCorrect = OUString::createFromAscii(aToCheck[i].pFormat);
66 4 : OUStringBuffer aMsg("Mis-matching formats ");
67 2 : aMsg.append("'");
68 2 : aMsg.append(aTypeName);
69 2 : aMsg.append("' should be '");
70 2 : aMsg.append(aFormatCorrect);
71 2 : aMsg.append("'");
72 4 : CPPUNIT_ASSERT_MESSAGE(rtl::OUStringToOString(aMsg.makeStringAndClear(),
73 : RTL_TEXTENCODING_UTF8).getStr(),
74 4 : aTypeName == aFormatCorrect);
75 : }
76 0 : catch (const uno::Exception &e)
77 : {
78 0 : OUStringBuffer aMsg("Exception querying for type: ");
79 0 : aMsg.append("'");
80 0 : aMsg.append(e.Message);
81 0 : aMsg.append("'");
82 0 : CPPUNIT_FAIL(rtl::OUStringToOString(aMsg.makeStringAndClear(),
83 0 : RTL_TEXTENCODING_UTF8).getStr());
84 : }
85 4 : }
86 2 : }
87 :
88 2 : CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest);
89 :
90 : }
91 :
92 8 : CPPUNIT_PLUGIN_IMPLEMENT();
93 :
94 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|