From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- writerperfect/qa/unit/SpreadsheetImportTest.cxx | 138 ++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 writerperfect/qa/unit/SpreadsheetImportTest.cxx (limited to 'writerperfect/qa/unit/SpreadsheetImportTest.cxx') diff --git a/writerperfect/qa/unit/SpreadsheetImportTest.cxx b/writerperfect/qa/unit/SpreadsheetImportTest.cxx new file mode 100644 index 000000000..3c5de090c --- /dev/null +++ b/writerperfect/qa/unit/SpreadsheetImportTest.cxx @@ -0,0 +1,138 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include +#include "WpftFilterFixture.hxx" +#include "WpftLoader.hxx" +#include "wpftimport.hxx" + +namespace +{ +namespace uno = css::uno; + +class SpreadsheetImportFilter : public writerperfect::ImportFilter +{ +public: + explicit SpreadsheetImportFilter(const uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual uno::Sequence SAL_CALL getSupportedServiceNames() override; + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override; + virtual bool doImportDocument(weld::Window* pWindow, librevenge::RVNGInputStream& rInput, + OdsGenerator& rGenerator, + utl::MediaDescriptor& rDescriptor) override; + + static void generate(librevenge::RVNGSpreadsheetInterface& rDocument); +}; + +bool SpreadsheetImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream&, + OdsGenerator& rGenerator, utl::MediaDescriptor&) +{ + SpreadsheetImportFilter::generate(rGenerator); + return true; +} + +bool SpreadsheetImportFilter::doDetectFormat(librevenge::RVNGInputStream&, OUString& rTypeName) +{ + rTypeName = "WpftDummySpreadsheet"; + return true; +} + +// XServiceInfo +OUString SAL_CALL SpreadsheetImportFilter::getImplementationName() +{ + return "org.libreoffice.comp.Wpft.QA.SpreadsheetImportFilter"; +} + +sal_Bool SAL_CALL SpreadsheetImportFilter::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +uno::Sequence SAL_CALL SpreadsheetImportFilter::getSupportedServiceNames() +{ + return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" }; +} + +void SpreadsheetImportFilter::generate(librevenge::RVNGSpreadsheetInterface& rDocument) +{ + using namespace librevenge; + + rDocument.startDocument(RVNGPropertyList()); + rDocument.openPageSpan(RVNGPropertyList()); + rDocument.openSheet(RVNGPropertyList()); + rDocument.openSheetRow(RVNGPropertyList()); + rDocument.openSheetCell(RVNGPropertyList()); + rDocument.openParagraph(RVNGPropertyList()); + rDocument.openSpan(RVNGPropertyList()); + rDocument.insertText("My hovercraft is full of eels."); + rDocument.closeSpan(); + rDocument.closeParagraph(); + rDocument.closeSheetCell(); + rDocument.closeSheetRow(); + rDocument.closeSheet(); + rDocument.closePageSpan(); + rDocument.endDocument(); +} +} + +namespace +{ +class SpreadsheetImportTest : public writerperfect::test::WpftFilterFixture +{ +public: + void test(); + + CPPUNIT_TEST_SUITE(SpreadsheetImportTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void SpreadsheetImportTest::test() +{ + using namespace css; + + rtl::Reference xFilter{ new SpreadsheetImportFilter(m_xContext) }; + writerperfect::test::WpftLoader aLoader(createDummyInput(), xFilter, "private:factory/scalc", + m_xDesktop, m_xContext); + + uno::Reference xDoc(aLoader.getDocument(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xDoc.is()); + uno::Reference xSheets(xDoc->getSheets(), uno::UNO_QUERY); + CPPUNIT_ASSERT(xSheets.is()); + uno::Reference xSheet(xSheets->getByIndex(0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xSheet.is()); + uno::Reference xCell = xSheet->getCellByPosition(0, 0); + CPPUNIT_ASSERT(xCell.is()); + CPPUNIT_ASSERT_EQUAL(table::CellContentType_TEXT, xCell->getType()); + CPPUNIT_ASSERT_EQUAL(OUString("My hovercraft is full of eels."), xCell->getFormula()); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SpreadsheetImportTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3