bump product version to 7.2.5.1
[LibreOffice.git] / test / source / style / xstyleloader.cxx
blobfd3f8eec5303235743a2105c19bde94de9ca9702
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/style/xstyleloader.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/container/XNameContainer.hpp>
14 #include <com/sun/star/io/XInputStream.hpp>
15 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
16 #include <com/sun/star/style/XStyle.hpp>
17 #include <com/sun/star/style/XStyleLoader2.hpp>
19 #include <com/sun/star/uno/Any.hxx>
20 #include <com/sun/star/uno/Reference.hxx>
21 #include <com/sun/star/uno/Sequence.hxx>
23 #include <rtl/ustring.hxx>
24 #include <cppunit/TestAssert.h>
25 #include <comphelper/processfactory.hxx>
26 #include <comphelper/storagehelper.hxx>
28 using namespace comphelper;
29 using namespace css;
30 using namespace css::uno;
32 namespace apitest
34 void XStyleLoader::testLoadStylesFromURL()
36 uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW);
38 uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW);
39 const OUString aFileURL = getTestURL();
41 uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions();
42 xStyleLoader->loadStylesFromURL(aFileURL, aOptions);
44 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW);
45 checkStyleProperties(xFamilySupplier);
48 void XStyleLoader::testLoadStylesFromDocument()
50 uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW);
52 uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW);
53 uno::Reference<lang::XComponent> xSrcComponent(getSourceComponent(), UNO_SET_THROW);
55 uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions();
56 xStyleLoader->loadStylesFromDocument(xSrcComponent, aOptions);
58 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW);
59 checkStyleProperties(xFamilySupplier);
62 void XStyleLoader::testLoadStylesFromStream()
64 uno::Reference<style::XStyleLoader2> xStyleLoader(init(), uno::UNO_QUERY_THROW);
66 uno::Reference<sheet::XSpreadsheetDocument> xDoc(getTargetDoc(), uno::UNO_SET_THROW);
67 const OUString aFileURL = getTestURL();
68 const uno::Reference<io::XInputStream> xInputStream
69 = OStorageHelper::GetInputStreamFromURL(aFileURL, getProcessComponentContext());
71 uno::Sequence<beans::PropertyValue> aOptions = xStyleLoader->getStyleLoaderOptions();
72 auto nLength = aOptions.getLength();
73 aOptions.realloc(nLength + 1);
74 beans::PropertyValue aInputStream;
75 aInputStream.Name = "InputStream";
76 uno::Any aTmp;
77 aTmp <<= xInputStream;
78 aInputStream.Value = aTmp;
79 aOptions[nLength] = aInputStream;
81 xStyleLoader->loadStylesFromURL("private:stream", aOptions);
83 uno::Reference<style::XStyleFamiliesSupplier> xFamilySupplier(xDoc, UNO_QUERY_THROW);
84 checkStyleProperties(xFamilySupplier);
87 void XStyleLoader::checkStyleProperties(
88 uno::Reference<style::XStyleFamiliesSupplier> const& xFamilySupplier)
90 // check if targetDocument has myStyle
91 uno::Reference<container::XNameAccess> xFamilies(xFamilySupplier->getStyleFamilies(),
92 UNO_SET_THROW);
93 uno::Reference<container::XNameContainer> xCellStyles(xFamilies->getByName("CellStyles"),
94 UNO_QUERY_THROW);
96 CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle"));
98 // test the backgroundcolor is correctly imported
99 uno::Reference<style::XStyle> xMyStyle(xCellStyles->getByName("myStyle"), UNO_QUERY_THROW);
100 uno::Reference<beans::XPropertySet> xPropSet(xMyStyle, UNO_QUERY_THROW);
102 uno::Any aBackColor = xPropSet->getPropertyValue("CellBackColor");
103 uno::Any expectedBackColor(sal_Int32(16724787));
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor", expectedBackColor, aBackColor);
107 // test default pageStyle
109 uno::Reference<container::XNameContainer> xPageStyles(xFamilies->getByName("PageStyles"),
110 UNO_QUERY_THROW);
111 uno::Reference<beans::XPropertySet> xPagePropSet(xPageStyles->getByName("Default"),
112 UNO_QUERY_THROW);
114 uno::Any aPageBackColor = xPagePropSet->getPropertyValue("BackColor");
115 uno::Any expectedPageBackColor(sal_Int32(13434879));
117 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor", expectedPageBackColor,
118 aPageBackColor);
121 } // namespace apitest
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */