Bump version to 6.4-15
[LibreOffice.git] / writerperfect / qa / unit / ImportTest.cxx
blob3a7b9c2293f0735e4eb84732f5bde6ebf7d744fe
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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/XMultiServiceFactory.hpp>
16 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
17 #include <com/sun/star/table/XCellRange.hpp>
19 #include <unotools/mediadescriptor.hxx>
21 #include "WpftFilterFixture.hxx"
22 #include "WpftLoader.hxx"
24 namespace
26 namespace beans = css::beans;
27 namespace container = css::container;
28 namespace document = css::document;
29 namespace lang = css::lang;
30 namespace sheet = css::sheet;
31 namespace table = css::table;
32 namespace uno = css::uno;
34 using uno::UNO_QUERY;
36 using writerperfect::test::WpftLoader;
38 class ImportTest : public writerperfect::test::WpftFilterFixture
40 public:
41 virtual void setUp() override;
43 void testWK3WithFM3();
45 CPPUNIT_TEST_SUITE(ImportTest);
46 CPPUNIT_TEST(testWK3WithFM3);
47 CPPUNIT_TEST_SUITE_END();
49 private:
50 WpftLoader createCalcLoader(const OUString& rFile) const;
52 WpftLoader createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const;
54 OUString makeUrl(const OUString& rFile) const;
56 private:
57 uno::Reference<lang::XMultiServiceFactory> m_xFilterFactory;
60 void ImportTest::setUp()
62 writerperfect::test::WpftFilterFixture::setUp();
64 m_xFilterFactory.set(
65 m_xFactory->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext),
66 UNO_QUERY);
67 assert(m_xFilterFactory.is());
70 void ImportTest::testWK3WithFM3()
72 WpftLoader aLoader(createCalcLoader("SOLVE.WK3"));
73 uno::Reference<sheet::XSpreadsheetDocument> xDoc(aLoader.getDocument(), UNO_QUERY);
74 CPPUNIT_ASSERT(xDoc.is());
75 uno::Reference<container::XIndexAccess> xSheets(xDoc->getSheets(), UNO_QUERY);
76 CPPUNIT_ASSERT(xSheets.is());
77 uno::Reference<table::XCellRange> xSheet(xSheets->getByIndex(0), UNO_QUERY);
78 CPPUNIT_ASSERT(xSheet.is());
79 uno::Reference<beans::XPropertySet> xCellProps(xSheet->getCellByPosition(1, 1), UNO_QUERY);
80 CPPUNIT_ASSERT(xCellProps.is());
81 sal_Int32 nCharColor = 0;
82 CPPUNIT_ASSERT(xCellProps->getPropertyValue("CharColor") >>= nCharColor);
83 CPPUNIT_ASSERT_EQUAL(sal_Int32(0x0000ff), nCharColor); // blue text
86 WpftLoader ImportTest::createCalcLoader(const OUString& rFile) const
88 return createLoader(makeUrl(rFile), "private:factory/scalc");
91 WpftLoader ImportTest::createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const
93 utl::MediaDescriptor aDesc;
94 aDesc[utl::MediaDescriptor::PROP_URL()] <<= rUrl;
95 aDesc[utl::MediaDescriptor::PROP_READONLY()] <<= true;
96 uno::Sequence<beans::PropertyValue> lDesc(aDesc.getAsConstPropertyValueList());
97 m_xTypeDetection->queryTypeByDescriptor(lDesc, true);
98 aDesc = lDesc;
99 OUString sFilter;
100 aDesc[utl::MediaDescriptor::PROP_FILTERNAME()] >>= sFilter;
101 CPPUNIT_ASSERT(!sFilter.isEmpty());
102 const uno::Reference<document::XFilter> xFilter(m_xFilterFactory->createInstance(sFilter),
103 UNO_QUERY);
104 CPPUNIT_ASSERT(xFilter.is());
105 return WpftLoader(rUrl, xFilter, rFactoryUrl, m_xDesktop, m_xTypeMap, m_xContext);
108 OUString ImportTest::makeUrl(const OUString& rFile) const
110 return const_cast<ImportTest*>(this)->m_directories.getURLFromSrc("/" TEST_DIR "/" + rFile);
113 CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest);
116 CPPUNIT_PLUGIN_IMPLEMENT();
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */