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/awt/XWindow.hpp>
11 #include <com/sun/star/beans/XPropertySet.hpp>
12 #include <com/sun/star/container/XIndexAccess.hpp>
13 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
14 #include <com/sun/star/table/XCell.hpp>
15 #include <com/sun/star/table/XCellRange.hpp>
16 #include <com/sun/star/uno/XComponentContext.hpp>
18 #include <cppuhelper/supportsservice.hxx>
20 #include <rtl/ref.hxx>
22 #include <DocumentHandlerForOds.hxx>
23 #include <ImportFilter.hxx>
24 #include "WpftFilterFixture.hxx"
25 #include "WpftLoader.hxx"
26 #include "wpftimport.hxx"
30 namespace uno
= css::uno
;
32 class SpreadsheetImportFilter
: public writerperfect::ImportFilter
<OdsGenerator
>
35 explicit SpreadsheetImportFilter(const uno::Reference
<uno::XComponentContext
>& rxContext
)
36 : writerperfect::ImportFilter
<OdsGenerator
>(rxContext
)
41 virtual OUString SAL_CALL
getImplementationName() override
;
42 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
43 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
46 virtual bool doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
) override
;
47 virtual bool doImportDocument(weld::Window
* pWindow
, librevenge::RVNGInputStream
& rInput
,
48 OdsGenerator
& rGenerator
,
49 utl::MediaDescriptor
& rDescriptor
) override
;
51 static void generate(librevenge::RVNGSpreadsheetInterface
& rDocument
);
54 bool SpreadsheetImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
&,
55 OdsGenerator
& rGenerator
, utl::MediaDescriptor
&)
57 SpreadsheetImportFilter::generate(rGenerator
);
61 bool SpreadsheetImportFilter::doDetectFormat(librevenge::RVNGInputStream
&, OUString
& rTypeName
)
63 rTypeName
= "WpftDummySpreadsheet";
68 OUString SAL_CALL
SpreadsheetImportFilter::getImplementationName()
70 return "org.libreoffice.comp.Wpft.QA.SpreadsheetImportFilter";
73 sal_Bool SAL_CALL
SpreadsheetImportFilter::supportsService(const OUString
& rServiceName
)
75 return cppu::supportsService(this, rServiceName
);
78 uno::Sequence
<OUString
> SAL_CALL
SpreadsheetImportFilter::getSupportedServiceNames()
80 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
83 void SpreadsheetImportFilter::generate(librevenge::RVNGSpreadsheetInterface
& rDocument
)
85 using namespace librevenge
;
87 rDocument
.startDocument(RVNGPropertyList());
88 rDocument
.openPageSpan(RVNGPropertyList());
89 rDocument
.openSheet(RVNGPropertyList());
90 rDocument
.openSheetRow(RVNGPropertyList());
91 rDocument
.openSheetCell(RVNGPropertyList());
92 rDocument
.openParagraph(RVNGPropertyList());
93 rDocument
.openSpan(RVNGPropertyList());
94 rDocument
.insertText("My hovercraft is full of eels.");
95 rDocument
.closeSpan();
96 rDocument
.closeParagraph();
97 rDocument
.closeSheetCell();
98 rDocument
.closeSheetRow();
99 rDocument
.closeSheet();
100 rDocument
.closePageSpan();
101 rDocument
.endDocument();
107 class SpreadsheetImportTest
: public writerperfect::test::WpftFilterFixture
112 CPPUNIT_TEST_SUITE(SpreadsheetImportTest
);
114 CPPUNIT_TEST_SUITE_END();
117 void SpreadsheetImportTest::test()
121 rtl::Reference
<SpreadsheetImportFilter
> xFilter
{ new SpreadsheetImportFilter(m_xContext
) };
122 writerperfect::test::WpftLoader
aLoader(createDummyInput(), xFilter
.get(),
123 "private:factory/scalc", m_xDesktop
, m_xContext
);
125 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(aLoader
.getDocument(), uno::UNO_QUERY
);
126 CPPUNIT_ASSERT(xDoc
.is());
127 uno::Reference
<container::XIndexAccess
> xSheets(xDoc
->getSheets(), uno::UNO_QUERY
);
128 CPPUNIT_ASSERT(xSheets
.is());
129 uno::Reference
<table::XCellRange
> xSheet(xSheets
->getByIndex(0), uno::UNO_QUERY
);
130 CPPUNIT_ASSERT(xSheet
.is());
131 uno::Reference
<table::XCell
> xCell
= xSheet
->getCellByPosition(0, 0);
132 CPPUNIT_ASSERT(xCell
.is());
133 CPPUNIT_ASSERT_EQUAL(table::CellContentType_TEXT
, xCell
->getType());
134 CPPUNIT_ASSERT_EQUAL(OUString("My hovercraft is full of eels."), xCell
->getFormula());
137 CPPUNIT_TEST_SUITE_REGISTRATION(SpreadsheetImportTest
);
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */