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/ImportTest.cxx | 124 +++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 writerperfect/qa/unit/ImportTest.cxx (limited to 'writerperfect/qa/unit/ImportTest.cxx') diff --git a/writerperfect/qa/unit/ImportTest.cxx b/writerperfect/qa/unit/ImportTest.cxx new file mode 100644 index 000000000..ef58118b0 --- /dev/null +++ b/writerperfect/qa/unit/ImportTest.cxx @@ -0,0 +1,124 @@ +/* -*- 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 +#include + +#include + +#include "WpftFilterFixture.hxx" +#include "WpftLoader.hxx" + +namespace +{ +namespace beans = css::beans; +namespace container = css::container; +namespace document = css::document; +namespace lang = css::lang; +namespace sheet = css::sheet; +namespace table = css::table; +namespace uno = css::uno; + +using uno::UNO_QUERY; + +using writerperfect::test::WpftLoader; + +class ImportTest : public writerperfect::test::WpftFilterFixture +{ +public: + virtual void setUp() override; + + void testWK3WithFM3(); + + CPPUNIT_TEST_SUITE(ImportTest); + CPPUNIT_TEST(testWK3WithFM3); + CPPUNIT_TEST_SUITE_END(); + +private: + WpftLoader createCalcLoader(std::u16string_view rFile) const; + + WpftLoader createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const; + + OUString makeUrl(std::u16string_view rFile) const; + +private: + uno::Reference m_xFilterFactory; +}; + +void ImportTest::setUp() +{ + writerperfect::test::WpftFilterFixture::setUp(); + + m_xFilterFactory.set( + m_xFactory->createInstanceWithContext("com.sun.star.document.FilterFactory", m_xContext), + UNO_QUERY); + assert(m_xFilterFactory.is()); +} + +void ImportTest::testWK3WithFM3() +{ + WpftLoader aLoader(createCalcLoader(u"SOLVE.WK3")); + uno::Reference xDoc(aLoader.getDocument(), UNO_QUERY); + CPPUNIT_ASSERT(xDoc.is()); + uno::Reference xSheets(xDoc->getSheets(), UNO_QUERY); + CPPUNIT_ASSERT(xSheets.is()); + uno::Reference xSheet(xSheets->getByIndex(0), UNO_QUERY); + CPPUNIT_ASSERT(xSheet.is()); + uno::Reference xCellProps(xSheet->getCellByPosition(1, 1), UNO_QUERY); + CPPUNIT_ASSERT(xCellProps.is()); + sal_Int32 nCharColor = 0; + CPPUNIT_ASSERT(xCellProps->getPropertyValue("CharColor") >>= nCharColor); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0x0000ff), nCharColor); // blue text +} + +WpftLoader ImportTest::createCalcLoader(std::u16string_view rFile) const +{ + return createLoader(makeUrl(rFile), "private:factory/scalc"); +} + +WpftLoader ImportTest::createLoader(const OUString& rUrl, const OUString& rFactoryUrl) const +{ + utl::MediaDescriptor aDesc; + aDesc[utl::MediaDescriptor::PROP_URL] <<= rUrl; + aDesc[utl::MediaDescriptor::PROP_READONLY] <<= true; + uno::Sequence lDesc(aDesc.getAsConstPropertyValueList()); + m_xTypeDetection->queryTypeByDescriptor(lDesc, true); + aDesc = lDesc; + OUString sFilter; + aDesc[utl::MediaDescriptor::PROP_FILTERNAME] >>= sFilter; + CPPUNIT_ASSERT(!sFilter.isEmpty()); + const uno::Reference xFilter(m_xFilterFactory->createInstance(sFilter), + UNO_QUERY); + CPPUNIT_ASSERT(xFilter.is()); + return WpftLoader(rUrl, xFilter, rFactoryUrl, m_xDesktop, m_xTypeMap, m_xContext); +} + +OUString ImportTest::makeUrl(std::u16string_view rFile) const +{ + return const_cast(this)->m_directories.getURLFromSrc( + OUStringConcatenation(OUString::Concat("/" TEST_DIR "/") + rFile)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ImportTest); +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3