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/container/XIndexAccess.hpp>
11 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
12 #include <com/sun/star/table/XCell.hpp>
13 #include <com/sun/star/table/XCellRange.hpp>
14 #include <com/sun/star/uno/XComponentContext.hpp>
16 #include <cppuhelper/supportsservice.hxx>
18 #include <rtl/ref.hxx>
20 #include <DocumentHandlerForOds.hxx>
21 #include <ImportFilter.hxx>
22 #include "WpftFilterFixture.hxx"
23 #include "WpftLoader.hxx"
24 #include "wpftimport.hxx"
28 namespace uno
= css::uno
;
30 class SpreadsheetImportFilter
: public writerperfect::ImportFilter
<OdsGenerator
>
33 explicit SpreadsheetImportFilter(const uno::Reference
<uno::XComponentContext
>& rxContext
)
34 : writerperfect::ImportFilter
<OdsGenerator
>(rxContext
)
39 virtual OUString SAL_CALL
getImplementationName() override
;
40 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
41 virtual uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
;
44 virtual bool doDetectFormat(librevenge::RVNGInputStream
& rInput
, OUString
& rTypeName
) override
;
45 virtual bool doImportDocument(weld::Window
* pWindow
, librevenge::RVNGInputStream
& rInput
,
46 OdsGenerator
& rGenerator
,
47 utl::MediaDescriptor
& rDescriptor
) override
;
49 static void generate(librevenge::RVNGSpreadsheetInterface
& rDocument
);
52 bool SpreadsheetImportFilter::doImportDocument(weld::Window
*, librevenge::RVNGInputStream
&,
53 OdsGenerator
& rGenerator
, utl::MediaDescriptor
&)
55 SpreadsheetImportFilter::generate(rGenerator
);
59 bool SpreadsheetImportFilter::doDetectFormat(librevenge::RVNGInputStream
&, OUString
& rTypeName
)
61 rTypeName
= "WpftDummySpreadsheet";
66 OUString SAL_CALL
SpreadsheetImportFilter::getImplementationName()
68 return "org.libreoffice.comp.Wpft.QA.SpreadsheetImportFilter";
71 sal_Bool SAL_CALL
SpreadsheetImportFilter::supportsService(const OUString
& rServiceName
)
73 return cppu::supportsService(this, rServiceName
);
76 uno::Sequence
<OUString
> SAL_CALL
SpreadsheetImportFilter::getSupportedServiceNames()
78 return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
81 void SpreadsheetImportFilter::generate(librevenge::RVNGSpreadsheetInterface
& rDocument
)
83 using namespace librevenge
;
85 rDocument
.startDocument(RVNGPropertyList());
86 rDocument
.openPageSpan(RVNGPropertyList());
87 rDocument
.openSheet(RVNGPropertyList());
88 rDocument
.openSheetRow(RVNGPropertyList());
89 rDocument
.openSheetCell(RVNGPropertyList());
90 rDocument
.openParagraph(RVNGPropertyList());
91 rDocument
.openSpan(RVNGPropertyList());
92 rDocument
.insertText("My hovercraft is full of eels.");
93 rDocument
.closeSpan();
94 rDocument
.closeParagraph();
95 rDocument
.closeSheetCell();
96 rDocument
.closeSheetRow();
97 rDocument
.closeSheet();
98 rDocument
.closePageSpan();
99 rDocument
.endDocument();
105 class SpreadsheetImportTest
: public writerperfect::test::WpftFilterFixture
110 CPPUNIT_TEST_SUITE(SpreadsheetImportTest
);
112 CPPUNIT_TEST_SUITE_END();
115 void SpreadsheetImportTest::test()
119 rtl::Reference
<SpreadsheetImportFilter
> xFilter
{ new SpreadsheetImportFilter(m_xContext
) };
120 writerperfect::test::WpftLoader
aLoader(createDummyInput(), xFilter
, "private:factory/scalc",
121 m_xDesktop
, m_xContext
);
123 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(aLoader
.getDocument(), uno::UNO_QUERY
);
124 CPPUNIT_ASSERT(xDoc
.is());
125 uno::Reference
<container::XIndexAccess
> xSheets(xDoc
->getSheets(), uno::UNO_QUERY
);
126 CPPUNIT_ASSERT(xSheets
.is());
127 uno::Reference
<table::XCellRange
> xSheet(xSheets
->getByIndex(0), uno::UNO_QUERY
);
128 CPPUNIT_ASSERT(xSheet
.is());
129 uno::Reference
<table::XCell
> xCell
= xSheet
->getCellByPosition(0, 0);
130 CPPUNIT_ASSERT(xCell
.is());
131 CPPUNIT_ASSERT_EQUAL(table::CellContentType_TEXT
, xCell
->getType());
132 CPPUNIT_ASSERT_EQUAL(OUString("My hovercraft is full of eels."), xCell
->getFormula());
135 CPPUNIT_TEST_SUITE_REGISTRATION(SpreadsheetImportTest
);
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */