summaryrefslogtreecommitdiffstats
path: root/writerperfect/qa/unit/ImportTest.cxx
blob: 07c82d4134cbbd3d4b54268f278757d7deb8b827 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* -*- 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/.
 */

#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexAccess.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XTypeDetection.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
#include <com/sun/star/table/XCellRange.hpp>

#include <unotools/mediadescriptor.hxx>

#include "WpftFilterFixture.hxx"
#include "WpftLoader.hxx"

namespace
{
namespace beans = css::beans;
namespace container = css::container;
namespace document = css::document;
namespace lang = css::lang;
namespace sheet = css::sheet;
namespace table = css::table;
namespace uno = css::uno;

using uno::UNO_QUERY;

using writerperfect::test::WpftLoader;

class ImportTest : public writerperfect::test::WpftFilterFixture
{
public:
    virtual void setUp() override;

    void testWK3WithFM3();

    CPPUNIT_TEST_SUITE(ImportTest);
    CPPUNIT_TEST(testWK3WithFM3);
    CPPUNIT_TEST_SUITE_END();

private:
    WpftLoader createCalcLoader(const OUString& rFile) const;

    WpftLoader createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const;

    OUString makeUrl(const OUString& rFile) const;

private:
    uno::Reference<lang::XMultiServiceFactory> m_xFilterFactory;
};

void ImportTest::setUp()
{
    writerperfect::test::WpftFilterFixture::setUp();

    m_xFilterFactory.set(
        m_xFactory->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext),
        UNO_QUERY);
    assert(m_xFilterFactory.is());
}

void ImportTest::testWK3WithFM3()
{
    WpftLoader aLoader(createCalcLoader("SOLVE.WK3"));
    uno::Reference<sheet::XSpreadsheetDocument> xDoc(aLoader.getDocument(), UNO_QUERY);
    CPPUNIT_ASSERT(xDoc.is());
    uno::Reference<container::XIndexAccess> xSheets(xDoc->getSheets(), UNO_QUERY);
    CPPUNIT_ASSERT(xSheets.is());
    uno::Reference<table::XCellRange> xSheet(xSheets->getByIndex(0), UNO_QUERY);
    CPPUNIT_ASSERT(xSheet.is());
    uno::Reference<beans::XPropertySet> xCellProps(xSheet->getCellByPosition(1, 1), UNO_QUERY);
    CPPUNIT_ASSERT(xCellProps.is());
    sal_Int32 nCharColor = 0;
    CPPUNIT_ASSERT(xCellProps->getPropertyValue("CharColor") >>= nCharColor);
    CPPUNIT_ASSERT_EQUAL(sal_Int32(0x0000ff), nCharColor); // blue text
}

WpftLoader ImportTest::createCalcLoader(const OUString& rFile) const
{
    return createLoader(makeUrl(rFile), "private:factory/scalc");
}

WpftLoader ImportTest::createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const
{
    utl::MediaDescriptor aDesc;
    aDesc[utl::MediaDescriptor::PROP_URL()] <<= rUrl;
    aDesc[utl::MediaDescriptor::PROP_READONLY()] <<= true;
    uno::Sequence<beans::PropertyValue> lDesc(aDesc.getAsConstPropertyValueList());
    m_xTypeDetection->queryTypeByDescriptor(lDesc, true);
    aDesc = lDesc;
    OUString sFilter;
    aDesc[utl::MediaDescriptor::PROP_FILTERNAME()] >>= sFilter;
    CPPUNIT_ASSERT(!sFilter.isEmpty());
    const uno::Reference<document::XFilter> xFilter(m_xFilterFactory->createInstance(sFilter),
                                                    UNO_QUERY);
    CPPUNIT_ASSERT(xFilter.is());
    return WpftLoader(rUrl, xFilter, rFactoryUrl, m_xDesktop, m_xTypeMap, m_xContext);
}

OUString ImportTest::makeUrl(const OUString& rFile) const
{
    return const_cast<ImportTest*>(this)->m_directories.getURLFromSrc("/" TEST_DIR "/" + rFile);
}

CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
}

CPPUNIT_PLUGIN_IMPLEMENT();

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