summaryrefslogtreecommitdiff
path: root/filter/qa/cppunit/priority-test.cxx
blob: 88b232684ecfb70583d68675d95e43a769701997 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

// Unit test to check that we get the right filters for the right extensions.

#include <limits>

#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>

#include <sal/types.h>
#include <rtl/ustrbuf.hxx>

#include <com/sun/star/document/XTypeDetection.hpp>
#include <comphelper/processfactory.hxx>

#include <unotest/bootstrapfixturebase.hxx>


using namespace std;
using namespace css;

namespace {

class PriorityFilterTest
    : public test::BootstrapFixtureBase
{
public:
    void testPriority();

    CPPUNIT_TEST_SUITE(PriorityFilterTest);
    CPPUNIT_TEST(testPriority);
    CPPUNIT_TEST_SUITE_END();
};

void PriorityFilterTest::testPriority()
{
    uno::Reference<document::XTypeDetection> xDetection(
        comphelper::getProcessServiceFactory()->createInstance("com.sun.star.document.TypeDetection"), uno::UNO_QUERY);
    CPPUNIT_ASSERT_MESSAGE("No type detection component", xDetection.is());

    static struct {
        const char *pURL;
        const char *pFormat;
    } const aToCheck[] = {
        { "file:///tmp/foo.xls", "calc_MS_Excel_97" }
        // TODO: expand this to check more of these priorities
    };

    for (size_t i = 0; i < SAL_N_ELEMENTS(aToCheck); i++)
    {
        OUString aURL = OUString::createFromAscii(aToCheck[i].pURL);
        try
        {
            OUString aTypeName = xDetection->queryTypeByURL(aURL);

            OUString aFormatCorrect = OUString::createFromAscii(aToCheck[i].pFormat);
            OUStringBuffer aMsg("Mis-matching formats ");
            aMsg.append("'");
            aMsg.append(aTypeName);
            aMsg.append("' should be '");
            aMsg.append(aFormatCorrect);
            aMsg.append("'");
            CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(aMsg.makeStringAndClear(),
                                                          RTL_TEXTENCODING_UTF8).getStr(),
                                   aFormatCorrect, aTypeName);
        }
        catch (const uno::Exception &e)
        {
            OUStringBuffer aMsg("Exception querying for type: ");
            aMsg.append("'");
            aMsg.append(e.Message);
            aMsg.append("'");
            CPPUNIT_FAIL(OUStringToOString(aMsg.makeStringAndClear(),
                                                RTL_TEXTENCODING_UTF8).getStr());
        }
    }
}

CPPUNIT_TEST_SUITE_REGISTRATION(PriorityFilterTest);

}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */