LCOV - code coverage report
Current view: top level - test/source/sheet - xstyleloader.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 35 100.0 %
Date: 2014-11-03 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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           2 : void XStyleLoader::testLoadStylesFromURL()
      32             : {
      33             : 
      34           2 :   uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW);
      35             : 
      36           4 :   OUString aFileURL = getTestURL();
      37             : 
      38           4 :   uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW);
      39           4 :   uno::Reference< style::XStyleLoader > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
      40             : 
      41           4 :   uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions();
      42             : 
      43           2 :   xTargetStyleLoader->loadStylesFromURL(aFileURL, aOptions);
      44             : 
      45           4 :   checkStyleProperties(xFamilySupplier);
      46             : 
      47           2 : }
      48             : 
      49           2 : void XStyleLoader::testLoadStylesFromDocument()
      50             : {
      51             : 
      52           2 :   uno::Reference< sheet::XSpreadsheetDocument > xTargetDoc(init(), UNO_QUERY_THROW);
      53             : 
      54           4 :   uno::Reference< lang::XComponent > xSourceDoc (getSourceComponent(), UNO_QUERY_THROW);
      55             : 
      56           4 :   uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier (xTargetDoc, UNO_QUERY_THROW);
      57           4 :   uno::Reference< style::XStyleLoader2 > xTargetStyleLoader (xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
      58             : 
      59           4 :   uno::Sequence< beans::PropertyValue > aOptions = xTargetStyleLoader->getStyleLoaderOptions();
      60             : 
      61           2 :   xTargetStyleLoader->loadStylesFromDocument(xSourceDoc, aOptions);
      62             : 
      63           4 :   checkStyleProperties(xFamilySupplier);
      64             : 
      65           2 : }
      66             : 
      67           4 : void XStyleLoader::checkStyleProperties( uno::Reference< style::XStyleFamiliesSupplier > xFamilySupplier)
      68             : {
      69             :     // check if targetDocument has myStyle
      70           4 :   uno::Reference< container::XNameAccess > xFamilies(xFamilySupplier->getStyleFamilies(), UNO_QUERY_THROW);
      71           8 :   uno::Reference< container::XNameContainer > xCellStyles(xFamilies->getByName("CellStyles"), UNO_QUERY_THROW);
      72             : 
      73           4 :   CPPUNIT_ASSERT_MESSAGE("Style not imported", xCellStyles->hasByName("myStyle"));
      74             : 
      75             :   // test the backgroundcolor is correctly imported
      76           8 :   uno::Reference< style::XStyle > xMyStyle (xCellStyles->getByName("myStyle"), UNO_QUERY_THROW);
      77           8 :   uno::Reference< beans::XPropertySet > xPropSet (xMyStyle, UNO_QUERY_THROW);
      78             : 
      79           8 :   OUString aCellStyleName("CellBackColor");
      80           8 :   uno::Any aBackColor = xPropSet->getPropertyValue(aCellStyleName);
      81           8 :   uno::Any expectedBackColor(sal_Int32(16724787));
      82             : 
      83           4 :   CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong CellBackColor" , expectedBackColor, aBackColor);
      84             : 
      85             :   // test default pageStyle
      86             : 
      87           8 :   uno::Reference< container::XNameContainer > xPageStyles(xFamilies->getByName("PageStyles"), UNO_QUERY_THROW);
      88           8 :   uno::Reference<beans::XPropertySet> xPagePropSet(xPageStyles->getByName("Default"), UNO_QUERY_THROW);
      89             : 
      90           8 :   uno::Any aPageBackColor = xPagePropSet->getPropertyValue("BackColor");
      91           8 :   uno::Any expectedPageBackColor(sal_Int32(13434879));
      92             : 
      93           8 :   CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong page style BackColor" , expectedPageBackColor, aPageBackColor);
      94           4 : }
      95             : 
      96         144 : }
      97             : 
      98             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10