From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- test/source/style/xstyleloader.cxx | 123 +++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 test/source/style/xstyleloader.cxx (limited to 'test/source/style') diff --git a/test/source/style/xstyleloader.cxx b/test/source/style/xstyleloader.cxx new file mode 100644 index 0000000000..4b58758d9e --- /dev/null +++ b/test/source/style/xstyleloader.cxx @@ -0,0 +1,123 @@ +/* -*- 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 +#include + +using namespace comphelper; +using namespace css; +using namespace css::uno; + +namespace apitest +{ +void XStyleLoader::testLoadStylesFromURL() +{ + uno::Reference xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference xDoc(getTargetDoc(), uno::UNO_SET_THROW); + const OUString aFileURL = getTestURL(); + + uno::Sequence aOptions = xStyleLoader->getStyleLoaderOptions(); + xStyleLoader->loadStylesFromURL(aFileURL, aOptions); + + uno::Reference xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::testLoadStylesFromDocument() +{ + uno::Reference xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference xDoc(getTargetDoc(), uno::UNO_SET_THROW); + uno::Reference xSrcComponent(getSourceComponent(), UNO_SET_THROW); + + uno::Sequence aOptions = xStyleLoader->getStyleLoaderOptions(); + xStyleLoader->loadStylesFromDocument(xSrcComponent, aOptions); + + uno::Reference xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::testLoadStylesFromStream() +{ + uno::Reference xStyleLoader(init(), uno::UNO_QUERY_THROW); + + uno::Reference xDoc(getTargetDoc(), uno::UNO_SET_THROW); + const OUString aFileURL = getTestURL(); + const uno::Reference xInputStream + = OStorageHelper::GetInputStreamFromURL(aFileURL, getProcessComponentContext()); + + uno::Sequence aOptions = xStyleLoader->getStyleLoaderOptions(); + auto nLength = aOptions.getLength(); + aOptions.realloc(nLength + 1); + beans::PropertyValue aInputStream; + aInputStream.Name = "InputStream"; + uno::Any aTmp; + aTmp <<= xInputStream; + aInputStream.Value = aTmp; + aOptions.getArray()[nLength] = aInputStream; + + xStyleLoader->loadStylesFromURL("private:stream", aOptions); + + uno::Reference xFamilySupplier(xDoc, UNO_QUERY_THROW); + checkStyleProperties(xFamilySupplier); +} + +void XStyleLoader::checkStyleProperties( + uno::Reference const& xFamilySupplier) +{ + // check if targetDocument has myStyle + uno::Reference xFamilies(xFamilySupplier->getStyleFamilies(), + UNO_SET_THROW); + uno::Reference xCellStyles(xFamilies->getByName("CellStyles"), + UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle")); + + // test the backgroundcolor is correctly imported + uno::Reference xMyStyle(xCellStyles->getByName("myStyle"), UNO_QUERY_THROW); + uno::Reference xPropSet(xMyStyle, UNO_QUERY_THROW); + + uno::Any aBackColor = xPropSet->getPropertyValue("CellBackColor"); + uno::Any expectedBackColor(sal_Int32(16724787)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor", expectedBackColor, aBackColor); + + // test default pageStyle + + uno::Reference xPageStyles(xFamilies->getByName("PageStyles"), + UNO_QUERY_THROW); + uno::Reference xPagePropSet(xPageStyles->getByName("Default"), + UNO_QUERY_THROW); + + uno::Any aPageBackColor = xPagePropSet->getPropertyValue("BackColor"); + uno::Any expectedPageBackColor(sal_Int32(13434879)); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor", expectedPageBackColor, + aPageBackColor); +} + +} // namespace apitest + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3