1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/sheet/xstyleloader.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
15 #include <com/sun/star/container/XNameContainer.hpp>
17 #include <com/sun/star/style/XStyleLoader.hpp>
18 #include <com/sun/star/style/XStyleLoader2.hpp>
20 #include <com/sun/star/style/XStyle.hpp>
22 #include <rtl/ustring.hxx>
23 #include "cppunit/extensions/HelperMacros.h"
26 using namespace css::uno
;
31 void XStyleLoader::testLoadStylesFromURL()
34 uno::Reference
< sheet::XSpreadsheetDocument
> xTargetDoc(init(), UNO_QUERY_THROW
);
36 OUString aFileURL
= getTestURL();
38 uno::Reference
< style::XStyleFamiliesSupplier
> xFamilySupplier (xTargetDoc
, UNO_QUERY_THROW
);
39 uno::Reference
< style::XStyleLoader
> xTargetStyleLoader (xFamilySupplier
->getStyleFamilies(), UNO_QUERY_THROW
);
41 uno::Sequence
< beans::PropertyValue
> aOptions
= xTargetStyleLoader
->getStyleLoaderOptions();
43 xTargetStyleLoader
->loadStylesFromURL(aFileURL
, aOptions
);
45 checkStyleProperties(xFamilySupplier
);
49 void XStyleLoader::testLoadStylesFromDocument()
52 uno::Reference
< sheet::XSpreadsheetDocument
> xTargetDoc(init(), UNO_QUERY_THROW
);
54 uno::Reference
< lang::XComponent
> xSourceDoc (getSourceComponent(), UNO_QUERY_THROW
);
56 uno::Reference
< style::XStyleFamiliesSupplier
> xFamilySupplier (xTargetDoc
, UNO_QUERY_THROW
);
57 uno::Reference
< style::XStyleLoader2
> xTargetStyleLoader (xFamilySupplier
->getStyleFamilies(), UNO_QUERY_THROW
);
59 uno::Sequence
< beans::PropertyValue
> aOptions
= xTargetStyleLoader
->getStyleLoaderOptions();
61 xTargetStyleLoader
->loadStylesFromDocument(xSourceDoc
, aOptions
);
63 checkStyleProperties(xFamilySupplier
);
67 void XStyleLoader::checkStyleProperties( uno::Reference
< style::XStyleFamiliesSupplier
> xFamilySupplier
)
69 // check if targetDocument has myStyle
70 uno::Reference
< container::XNameAccess
> xFamilies(xFamilySupplier
->getStyleFamilies(), UNO_QUERY_THROW
);
71 uno::Reference
< container::XNameContainer
> xCellStyles(xFamilies
->getByName("CellStyles"), UNO_QUERY_THROW
);
73 CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles
->hasByName("myStyle"));
75 // test the backgroundcolor is correctly imported
76 uno::Reference
< style::XStyle
> xMyStyle (xCellStyles
->getByName("myStyle"), UNO_QUERY_THROW
);
77 uno::Reference
< beans::XPropertySet
> xPropSet (xMyStyle
, UNO_QUERY_THROW
);
79 OUString
aCellStyleName("CellBackColor");
80 uno::Any aBackColor
= xPropSet
->getPropertyValue(aCellStyleName
);
81 uno::Any
expectedBackColor(sal_Int32(16724787));
83 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor" , expectedBackColor
, aBackColor
);
85 // test default pageStyle
87 uno::Reference
< container::XNameContainer
> xPageStyles(xFamilies
->getByName("PageStyles"), UNO_QUERY_THROW
);
88 uno::Reference
<beans::XPropertySet
> xPagePropSet(xPageStyles
->getByName("Default"), UNO_QUERY_THROW
);
90 uno::Any aPageBackColor
= xPagePropSet
->getPropertyValue("BackColor");
91 uno::Any
expectedPageBackColor(sal_Int32(13434879));
93 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor" , expectedPageBackColor
, aPageBackColor
);
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */