1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <com/sun/star/beans/PropertyValue.hpp>
11 #include <com/sun/star/beans/XPropertySet.hpp>
12 #include <com/sun/star/container/XIndexAccess.hpp>
13 #include <com/sun/star/document/XFilter.hpp>
14 #include <com/sun/star/document/XTypeDetection.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
17 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
18 #include <com/sun/star/table/XCellRange.hpp>
20 #include <unotools/mediadescriptor.hxx>
22 #include "WpftFilterFixture.hxx"
23 #include "WpftLoader.hxx"
27 namespace beans
= css::beans
;
28 namespace container
= css::container
;
29 namespace document
= css::document
;
30 namespace lang
= css::lang
;
31 namespace sheet
= css::sheet
;
32 namespace table
= css::table
;
33 namespace uno
= css::uno
;
37 using writerperfect::test::WpftLoader
;
39 class ImportTest
: public writerperfect::test::WpftFilterFixture
42 virtual void setUp() override
;
44 void testWK3WithFM3();
46 CPPUNIT_TEST_SUITE(ImportTest
);
47 CPPUNIT_TEST(testWK3WithFM3
);
48 CPPUNIT_TEST_SUITE_END();
51 WpftLoader
createCalcLoader(const OUString
& rFile
) const;
53 WpftLoader
createLoader(const OUString
& rUrl
, const OUString
& rFactoryUrl
) const;
55 OUString
makeUrl(const OUString
& rFile
) const;
58 uno::Reference
<lang::XMultiServiceFactory
> m_xFilterFactory
;
61 void ImportTest::setUp()
63 writerperfect::test::WpftFilterFixture::setUp();
66 m_xFactory
->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext
),
68 assert(m_xFilterFactory
.is());
71 void ImportTest::testWK3WithFM3()
73 WpftLoader
aLoader(createCalcLoader("SOLVE.WK3"));
74 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(aLoader
.getDocument(), UNO_QUERY
);
75 CPPUNIT_ASSERT(xDoc
.is());
76 uno::Reference
<container::XIndexAccess
> xSheets(xDoc
->getSheets(), UNO_QUERY
);
77 CPPUNIT_ASSERT(xSheets
.is());
78 uno::Reference
<table::XCellRange
> xSheet(xSheets
->getByIndex(0), UNO_QUERY
);
79 CPPUNIT_ASSERT(xSheet
.is());
80 uno::Reference
<beans::XPropertySet
> xCellProps(xSheet
->getCellByPosition(1, 1), UNO_QUERY
);
81 CPPUNIT_ASSERT(xCellProps
.is());
82 sal_Int32 nCharColor
= 0;
83 CPPUNIT_ASSERT(xCellProps
->getPropertyValue("CharColor") >>= nCharColor
);
84 CPPUNIT_ASSERT_EQUAL(sal_Int32(0x0000ff), nCharColor
); // blue text
87 WpftLoader
ImportTest::createCalcLoader(const OUString
& rFile
) const
89 return createLoader(makeUrl(rFile
), "private:factory/scalc");
92 WpftLoader
ImportTest::createLoader(const OUString
& rUrl
, const OUString
& rFactoryUrl
) const
94 utl::MediaDescriptor aDesc
;
95 aDesc
[utl::MediaDescriptor::PROP_URL()] <<= rUrl
;
96 aDesc
[utl::MediaDescriptor::PROP_READONLY()] <<= true;
97 uno::Sequence
<beans::PropertyValue
> lDesc(aDesc
.getAsConstPropertyValueList());
98 m_xTypeDetection
->queryTypeByDescriptor(lDesc
, true);
101 aDesc
[utl::MediaDescriptor::PROP_FILTERNAME()] >>= sFilter
;
102 CPPUNIT_ASSERT(!sFilter
.isEmpty());
103 const uno::Reference
<document::XFilter
> xFilter(m_xFilterFactory
->createInstance(sFilter
),
105 CPPUNIT_ASSERT(xFilter
.is());
106 return WpftLoader(rUrl
, xFilter
, rFactoryUrl
, m_xDesktop
, m_xTypeMap
, m_xContext
);
109 OUString
ImportTest::makeUrl(const OUString
& rFile
) const
111 return const_cast<ImportTest
*>(this)->m_directories
.getURLFromSrc("/" TEST_DIR
"/" + rFile
);
114 CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest
);
117 CPPUNIT_PLUGIN_IMPLEMENT();
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */