Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : */
9 :
10 : #include <test/sheet/xstyleloader.hxx>
11 :
12 : #include <com/sun/star/beans/XPropertySet.hpp>
13 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
14 :
15 : #include <com/sun/star/container/XNameContainer.hpp>
16 :
17 : #include <com/sun/star/style/XStyleLoader.hpp>
18 : #include <com/sun/star/style/XStyleLoader2.hpp>
19 :
20 : #include <com/sun/star/style/XStyle.hpp>
21 :
22 : #include <rtl/ustring.hxx>
23 : #include "cppunit/extensions/HelperMacros.h"
24 :
25 : using namespace css;
26 : using namespace css::uno;
27 :
28 : namespace apitest {
29 :
30 :
31 1 : void XStyleLoader::testLoadStylesFromURL()
32 : {
33 :
34 1 : uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW);
35 :
36 2 : OUString aFileURL = getTestURL();
37 :
38 2 : uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW);
39 2 : uno::Reference< style::XStyleLoader > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
40 :
41 2 : uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions();
42 :
43 1 : xTargetStyleLoader->loadStylesFromURL(aFileURL, aOptions);
44 :
45 2 : checkStyleProperties(xFamilySupplier);
46 :
47 1 : }
48 :
49 1 : void XStyleLoader::testLoadStylesFromDocument()
50 : {
51 :
52 1 : uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW);
53 :
54 2 : uno::Reference< lang::XComponent > xSourceDoc (getSourceComponent(), UNO_QUERY_THROW);
55 :
56 2 : uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW);
57 2 : uno::Reference< style::XStyleLoader2 > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
58 :
59 2 : uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions();
60 :
61 1 : xTargetStyleLoader->loadStylesFromDocument(xSourceDoc, aOptions);
62 :
63 2 : checkStyleProperties(xFamilySupplier);
64 :
65 1 : }
66 :
67 2 : void XStyleLoader::checkStyleProperties( uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier)
68 : {
69 : // check if targetDocument has myStyle
70 2 : uno::Reference< container::XNameAccess > xFamilies(xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
71 4 : uno::Reference< container::XNameContainer > xCellStyles(xFamilies->getByName("CellStyles"), UNO_QUERY_THROW);
72 :
73 2 : CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle"));
74 :
75 : // test the backgroundcolor is correctly imported
76 4 : uno::Reference< style::XStyle > xMyStyle (xCellStyles->getByName("myStyle"), UNO_QUERY_THROW);
77 4 : uno::Reference< beans::XPropertySet > xPropSet (xMyStyle, UNO_QUERY_THROW);
78 :
79 4 : OUString aCellStyleName("CellBackColor");
80 4 : uno::Any aBackColor = xPropSet->getPropertyValue(aCellStyleName);
81 4 : uno::Any expectedBackColor(sal_Int32(16724787));
82 :
83 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor" , expectedBackColor, aBackColor);
84 :
85 : // test default pageStyle
86 :
87 4 : uno::Reference< container::XNameContainer > xPageStyles(xFamilies->getByName("PageStyles"), UNO_QUERY_THROW);
88 4 : uno::Reference<beans::XPropertySet> xPagePropSet(xPageStyles->getByName("Default"), UNO_QUERY_THROW);
89 :
90 4 : uno::Any aPageBackColor = xPagePropSet->getPropertyValue("BackColor");
91 4 : uno::Any expectedPageBackColor(sal_Int32(13434879));
92 :
93 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor" , expectedPageBackColor, aPageBackColor);
94 2 : }
95 :
96 90 : }
97 :
98 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|