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 <sal/config.h>
12 #include <string_view>
14 #include <com/sun/star/beans/PropertyValue.hpp>
15 #include <com/sun/star/beans/XPropertySet.hpp>
16 #include <com/sun/star/container/XIndexAccess.hpp>
17 #include <com/sun/star/document/XFilter.hpp>
18 #include <com/sun/star/document/XTypeDetection.hpp>
19 #include <com/sun/star/lang/XComponent.hpp>
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/table/XCellRange.hpp>
24 #include <unotools/mediadescriptor.hxx>
26 #include "WpftFilterFixture.hxx"
27 #include "WpftLoader.hxx"
31 namespace beans
= css::beans
;
32 namespace container
= css::container
;
33 namespace document
= css::document
;
34 namespace lang
= css::lang
;
35 namespace sheet
= css::sheet
;
36 namespace table
= css::table
;
37 namespace uno
= css::uno
;
41 using writerperfect::test::WpftLoader
;
43 class ImportTest
: public writerperfect::test::WpftFilterFixture
46 virtual void setUp() override
;
48 void testWK3WithFM3();
50 CPPUNIT_TEST_SUITE(ImportTest
);
51 CPPUNIT_TEST(testWK3WithFM3
);
52 CPPUNIT_TEST_SUITE_END();
55 WpftLoader
createCalcLoader(std::u16string_view rFile
) const;
57 WpftLoader
createLoader(const OUString
& rUrl
, const OUString
& rFactoryUrl
) const;
59 OUString
makeUrl(std::u16string_view rFile
) const;
62 uno::Reference
<lang::XMultiServiceFactory
> m_xFilterFactory
;
65 void ImportTest::setUp()
67 writerperfect::test::WpftFilterFixture::setUp();
70 m_xFactory
->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext
),
72 assert(m_xFilterFactory
.is());
75 void ImportTest::testWK3WithFM3()
77 WpftLoader
aLoader(createCalcLoader(u
"SOLVE.WK3"));
78 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(aLoader
.getDocument(), UNO_QUERY
);
79 CPPUNIT_ASSERT(xDoc
.is());
80 uno::Reference
<container::XIndexAccess
> xSheets(xDoc
->getSheets(), UNO_QUERY
);
81 CPPUNIT_ASSERT(xSheets
.is());
82 uno::Reference
<table::XCellRange
> xSheet(xSheets
->getByIndex(0), UNO_QUERY
);
83 CPPUNIT_ASSERT(xSheet
.is());
84 uno::Reference
<beans::XPropertySet
> xCellProps(xSheet
->getCellByPosition(1, 1), UNO_QUERY
);
85 CPPUNIT_ASSERT(xCellProps
.is());
87 CPPUNIT_ASSERT(xCellProps
->getPropertyValue("CharColor") >>= nCharColor
);
88 CPPUNIT_ASSERT_EQUAL(COL_LIGHTBLUE
, nCharColor
); // blue text
91 WpftLoader
ImportTest::createCalcLoader(std::u16string_view rFile
) const
93 return createLoader(makeUrl(rFile
), "private:factory/scalc");
96 WpftLoader
ImportTest::createLoader(const OUString
& rUrl
, const OUString
& rFactoryUrl
) const
98 utl::MediaDescriptor aDesc
;
99 aDesc
[utl::MediaDescriptor::PROP_URL
] <<= rUrl
;
100 aDesc
[utl::MediaDescriptor::PROP_READONLY
] <<= true;
101 uno::Sequence
<beans::PropertyValue
> lDesc(aDesc
.getAsConstPropertyValueList());
102 m_xTypeDetection
->queryTypeByDescriptor(lDesc
, true);
105 aDesc
[utl::MediaDescriptor::PROP_FILTERNAME
] >>= sFilter
;
106 CPPUNIT_ASSERT(!sFilter
.isEmpty());
107 const uno::Reference
<document::XFilter
> xFilter(m_xFilterFactory
->createInstance(sFilter
),
109 CPPUNIT_ASSERT(xFilter
.is());
110 return WpftLoader(rUrl
, xFilter
, rFactoryUrl
, m_xDesktop
, m_xTypeMap
, m_xContext
);
113 OUString
ImportTest::makeUrl(std::u16string_view rFile
) const
115 return const_cast<ImportTest
*>(this)->m_directories
.getURLFromSrc(
116 Concat2View(OUString::Concat("/" TEST_DIR
"/") + rFile
));
119 CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest
);
122 CPPUNIT_PLUGIN_IMPLEMENT();
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */