diff options
author | Laurent Godard <lgodard.libre@laposte.net> | 2014-08-05 17:02:49 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@collabora.co.uk> | 2014-08-08 00:38:10 +0200 |
commit | 949279c8013022ff2935d73276cd57c9af069b97 (patch) | |
tree | ed769534cd74e77bce5235041c54d0d740ad2a60 /test | |
parent | 41e05f48dd3bf08552db3675f5285276095ba0bf (diff) |
XStyleLoader2 loadStylesFromDocument - unit tests
Change-Id: Id143689f573e6f8585db9bc48a252e311ff0e721
Diffstat (limited to 'test')
-rw-r--r-- | test/Library_subsequenttest.mk | 1 | ||||
-rw-r--r-- | test/source/sheet/xstyleloader.cxx | 100 |
2 files changed, 101 insertions, 0 deletions
diff --git a/test/Library_subsequenttest.mk b/test/Library_subsequenttest.mk index 09f6c3e01604..f9b4b932e29b 100644 --- a/test/Library_subsequenttest.mk +++ b/test/Library_subsequenttest.mk @@ -62,6 +62,7 @@ $(eval $(call gb_Library_add_exception_objects,subsequenttest,\ test/source/sheet/xsheetannotation \ test/source/sheet/xsheetannotations \ test/source/sheet/xsheetoutline \ + test/source/sheet/xstyleloader \ test/source/text/xtext \ test/source/text/xtextfield \ test/source/text/xtextcontent \ diff --git a/test/source/sheet/xstyleloader.cxx b/test/source/sheet/xstyleloader.cxx new file mode 100644 index 000000000000..77a5a69a0db1 --- /dev/null +++ b/test/source/sheet/xstyleloader.cxx @@ -0,0 +1,100 @@ +/* -*- 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 <test/sheet/xstyleloader.hxx> + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> + +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/container/XNameContainer.hpp> + +#include <com/sun/star/style/XStyleLoader.hpp> +#include <com/sun/star/style/XStyleLoader2.hpp> + +#include <com/sun/star/style/XStyle.hpp> + + +#include <rtl/ustring.hxx> +#include "cppunit/extensions/HelperMacros.h" + +using namespace css; +using namespace css::uno; + +namespace apitest { + + +void XStyleLoader::testLoadStylesFromURL() +{ + + uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW); + + OUString aFileURL = getTestURL(); + + uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW); + uno::Reference< style::XStyleLoader > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW); + + uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions(); + + xTargetStyleLoader->loadStylesFromURL(aFileURL, aOptions); + + // check if targetDocument has myStyle + uno::Reference< container::XNameAccess > xFamilies(xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW); + uno::Reference< container::XNameContainer > xCellStyles(xFamilies->getByName("CellStyles"), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle")); + + // test the backgroundcolor is correctly imported + + uno::Reference< style::XStyle > xMyStyle (xCellStyles->getByName("myStyle"), UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xPropSet (xMyStyle, UNO_QUERY_THROW); + + OUString aCellStyleName("CellBackColor"); + uno::Any aBackColor = xPropSet->getPropertyValue(aCellStyleName); + uno::Any expectedBackColor(16724787); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor" , expectedBackColor, aBackColor); + +} + +void XStyleLoader::testLoadStylesFromDocument() +{ + + uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW); + + uno::Reference< lang::XComponent > xSourceDoc (getSourceComponent(), UNO_QUERY_THROW); + + uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW); + uno::Reference< style::XStyleLoader2 > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW); + + uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions(); + + xTargetStyleLoader->loadStylesFromDocument(xSourceDoc, aOptions); + + // check if targetDocument has myStyle + uno::Reference< container::XNameAccess > xFamilies(xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW); + uno::Reference< container::XNameContainer > xCellStyles(xFamilies->getByName("CellStyles"), UNO_QUERY_THROW); + + CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle")); + + // test the backgroundcolor is correctly imported + uno::Reference< style::XStyle > xMyStyle (xCellStyles->getByName("myStyle"), UNO_QUERY_THROW); + uno::Reference< beans::XPropertySet > xPropSet (xMyStyle, UNO_QUERY_THROW); + + OUString aCellStyleName("CellBackColor"); + uno::Any aBackColor = xPropSet->getPropertyValue(aCellStyleName); + uno::Any expectedBackColor(16724787); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor" , expectedBackColor, aBackColor); + +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file |