LCOV - code coverage report
Current view: top level - chart2/qa/extras - charttest.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 265 277 95.7 %
Date: 2014-11-03 Functions: 25 26 96.2 %
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             : #ifndef INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
      11             : #define INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
      12             : 
      13             : #include <test/bootstrapfixture.hxx>
      14             : #include <unotest/macros_test.hxx>
      15             : #include <comphelper/processfactory.hxx>
      16             : 
      17             : #include <com/sun/star/lang/XComponent.hpp>
      18             : #include <com/sun/star/frame/Desktop.hpp>
      19             : 
      20             : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
      21             : #include <com/sun/star/sheet/XSpreadsheet.hpp>
      22             : #include <com/sun/star/container/XIndexAccess.hpp>
      23             : #include <com/sun/star/table/XTableChartsSupplier.hpp>
      24             : #include <com/sun/star/table/XTableCharts.hpp>
      25             : #include <com/sun/star/table/XTableChart.hpp>
      26             : #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
      27             : #include <com/sun/star/beans/XPropertySet.hpp>
      28             : #include <com/sun/star/frame/XStorable.hpp>
      29             : #include <com/sun/star/beans/PropertyValue.hpp>
      30             : 
      31             : #include <unotools/tempfile.hxx>
      32             : 
      33             : #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
      34             : #include <com/sun/star/chart2/XChartDocument.hpp>
      35             : #include <com/sun/star/chart2/XDiagram.hpp>
      36             : #include <com/sun/star/chart2/XDataSeries.hpp>
      37             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      38             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      39             : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
      40             : #include <com/sun/star/chart2/XFormattedString.hpp>
      41             : #include <com/sun/star/chart2/XTitle.hpp>
      42             : #include <com/sun/star/chart2/XTitled.hpp>
      43             : #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
      44             : #include <com/sun/star/chart2/data/XDataSource.hpp>
      45             : #include <com/sun/star/chart/XChartDataArray.hpp>
      46             : #include <com/sun/star/chart/XComplexDescriptionAccess.hpp>
      47             : #include <com/sun/star/chart/DataLabelPlacement.hpp>
      48             : #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
      49             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      50             : #include <com/sun/star/drawing/FillStyle.hpp>
      51             : #include <com/sun/star/chart/XChartDocument.hpp>
      52             : #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
      53             : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
      54             : #include <com/sun/star/util/NumberFormat.hpp>
      55             : 
      56             : #include <unonames.hxx>
      57             : 
      58             : #include <iostream>
      59             : 
      60             : #include <libxml/xmlwriter.h>
      61             : #include <libxml/xpath.h>
      62             : 
      63             : #include <boost/shared_ptr.hpp>
      64             : #include <boost/make_shared.hpp>
      65             : 
      66             : using namespace com::sun::star;
      67             : using namespace com::sun::star::uno;
      68             : 
      69         136 : class ChartTest : public test::BootstrapFixture, public unotest::MacrosTest
      70             : {
      71             : public:
      72         136 :     ChartTest():mbSkipValidation(false) {}
      73             :     void load( const OUString& rDir, const OUString& rFileName );
      74             :     boost::shared_ptr<utl::TempFile> reload( const OUString& rFileName );
      75             :     uno::Sequence < OUString > getImpressChartColumnDescriptions( const char* pDir, const char* pName );
      76             :     OUString getFileExtension( const OUString& rFileName );
      77             : 
      78             :     uno::Reference< chart::XChartDocument > getChartDocFromImpress( const char* pDir, const char* pName );
      79             : 
      80             :     uno::Reference<chart::XChartDocument> getChartDocFromDrawImpress( sal_Int32 nPage, sal_Int32 nShape );
      81             : 
      82             :     uno::Reference<chart::XChartDocument> getChartDocFromWriter( sal_Int32 nShape );
      83             : 
      84             :     virtual void setUp() SAL_OVERRIDE;
      85             :     virtual void tearDown() SAL_OVERRIDE;
      86             : 
      87             : protected:
      88             :     Reference< lang::XComponent > mxComponent;
      89             :     OUString maServiceName;
      90             :     bool mbSkipValidation; // if you set this flag for a new test I'm going to haunt you!
      91             : };
      92             : 
      93         130 : OUString ChartTest::getFileExtension( const OUString& aFileName )
      94             : {
      95         130 :     sal_Int32 nDotLocation = aFileName.lastIndexOf('.');
      96         130 :     CPPUNIT_ASSERT(nDotLocation != -1);
      97         130 :     return aFileName.copy(nDotLocation+1); // Skip the dot.
      98             : }
      99             : 
     100         130 : void ChartTest::load( const OUString& aDir, const OUString& aName )
     101             : {
     102         130 :     OUString extension = getFileExtension(aName);
     103         130 :     if (extension == "ods" || extension == "xlsx" || extension == "fods")
     104             :     {
     105          50 :         maServiceName = "com.sun.star.sheet.SpreadsheetDocument";
     106             :     }
     107          80 :     else if (extension == "docx")
     108             :     {
     109          62 :         maServiceName = "com.sun.star.text.TextDocument";
     110             :     }
     111          18 :     else if (extension == "odg")
     112             :     {
     113           0 :         maServiceName = "com.sun.star.drawing.DrawingDocument";
     114             :     }
     115             : 
     116         130 :     mxComponent = loadFromDesktop(getURLFromSrc(aDir) + aName, maServiceName);
     117         130 :     CPPUNIT_ASSERT(mxComponent.is());
     118         130 : }
     119             : 
     120          78 : boost::shared_ptr<utl::TempFile> ChartTest::reload(const OUString& rFilterName)
     121             : {
     122          78 :     uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
     123         156 :     uno::Sequence<beans::PropertyValue> aArgs(1);
     124          78 :     aArgs[0].Name = "FilterName";
     125          78 :     aArgs[0].Value <<= rFilterName;
     126          78 :     boost::shared_ptr<utl::TempFile> pTempFile = boost::make_shared<utl::TempFile>();
     127          78 :     pTempFile->EnableKillingFile();
     128          78 :     xStorable->storeToURL(pTempFile->GetURL(), aArgs);
     129          78 :     mxComponent->dispose();
     130          78 :     mxComponent = loadFromDesktop(pTempFile->GetURL(), maServiceName);
     131          78 :     std::cout << pTempFile->GetURL();
     132          78 :     if(rFilterName == "Calc Office Open XML")
     133             :     {
     134          10 :         validate(pTempFile->GetFileName(), test::OOXML);
     135             :     }
     136          68 :     else if(rFilterName == "Office Open XML Text")
     137             :     {
     138             :         // validate(pTempFile->GetFileName(), test::OOXML);
     139             :     }
     140          12 :     else if(rFilterName == "calc8")
     141             :     {
     142           8 :         if(!mbSkipValidation)
     143           6 :             validate(pTempFile->GetFileName(), test::ODF);
     144             :     }
     145             : 
     146          78 :     CPPUNIT_ASSERT(mxComponent.is());
     147         156 :     return pTempFile;
     148             : }
     149             : 
     150         136 : void ChartTest::setUp()
     151             : {
     152         136 :     test::BootstrapFixture::setUp();
     153             : 
     154         136 :     mxDesktop.set( com::sun::star::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) );
     155         136 : }
     156             : 
     157         136 : void ChartTest::tearDown()
     158             : {
     159         136 :     if(mxComponent.is())
     160         136 :         mxComponent->dispose();
     161             : 
     162         136 :     test::BootstrapFixture::tearDown();
     163             : 
     164         136 : }
     165             : 
     166          92 : Reference< lang::XComponent > getChartCompFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent )
     167             : {
     168             :     // let us assume that we only have one chart per sheet
     169             : 
     170          92 :     uno::Reference< sheet::XSpreadsheetDocument > xDoc(xComponent, UNO_QUERY_THROW);
     171          92 :     CPPUNIT_ASSERT(xDoc.is());
     172             : 
     173         184 :     uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
     174          92 :     CPPUNIT_ASSERT(xIA.is());
     175             : 
     176         184 :     uno::Reference< table::XTableChartsSupplier > xChartSupplier( xIA->getByIndex(nSheet), UNO_QUERY_THROW);
     177          92 :     CPPUNIT_ASSERT(xChartSupplier.is());
     178             : 
     179         184 :     uno::Reference< table::XTableCharts > xCharts = xChartSupplier->getCharts();
     180          92 :     CPPUNIT_ASSERT(xCharts.is());
     181             : 
     182         184 :     uno::Reference< container::XIndexAccess > xIACharts(xCharts, UNO_QUERY_THROW);
     183         184 :     uno::Reference< table::XTableChart > xChart( xIACharts->getByIndex(0), UNO_QUERY_THROW);
     184          92 :     CPPUNIT_ASSERT(xChart.is());
     185             : 
     186         184 :     uno::Reference< document::XEmbeddedObjectSupplier > xEmbObjectSupplier(xChart, UNO_QUERY_THROW);
     187          92 :     CPPUNIT_ASSERT(xEmbObjectSupplier.is());
     188             : 
     189          92 :     uno::Reference< lang::XComponent > xChartComp( xEmbObjectSupplier->getEmbeddedObject(), UNO_QUERY_THROW );
     190          92 :     CPPUNIT_ASSERT(xChartComp.is());
     191             : 
     192         184 :     return xChartComp;
     193             : 
     194             : }
     195             : 
     196          84 : Reference< chart2::XChartDocument > getChartDocFromSheet( sal_Int32 nSheet, uno::Reference< lang::XComponent > xComponent )
     197             : {
     198          84 :     uno::Reference< chart2::XChartDocument > xChartDoc ( getChartCompFromSheet(nSheet, xComponent), UNO_QUERY_THROW );
     199          84 :     CPPUNIT_ASSERT(xChartDoc.is());
     200          84 :     return xChartDoc;
     201             : }
     202             : 
     203          98 : Reference< chart2::XChartType > getChartTypeFromDoc( Reference< chart2::XChartDocument > xChartDoc,
     204             :                                                                 sal_Int32 nChartType, sal_Int32 nCooSys = 0 )
     205             : {
     206          98 :     CPPUNIT_ASSERT( xChartDoc.is() );
     207             : 
     208          98 :     Reference <chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram();
     209          98 :     CPPUNIT_ASSERT( xDiagram.is() );
     210             : 
     211         196 :     Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, UNO_QUERY_THROW );
     212          98 :     CPPUNIT_ASSERT( xCooSysContainer.is() );
     213             : 
     214         196 :     Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems());
     215          98 :     CPPUNIT_ASSERT( xCooSysSequence.getLength() > nCooSys );
     216             : 
     217         196 :     Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[nCooSys], UNO_QUERY_THROW );
     218          98 :     CPPUNIT_ASSERT( xChartTypeContainer.is() );
     219             : 
     220         196 :     Sequence< Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() );
     221          98 :     CPPUNIT_ASSERT( xChartTypeSequence.getLength() > nChartType );
     222             : 
     223         196 :     return xChartTypeSequence[nChartType];
     224             : }
     225             : 
     226          16 : Reference<chart2::XAxis> getAxisFromDoc(
     227             :     const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nCooSys, sal_Int32 nAxisDim, sal_Int32 nAxisIndex )
     228             : {
     229          16 :     Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
     230          16 :     CPPUNIT_ASSERT(xDiagram.is());
     231             : 
     232          32 :     Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, UNO_QUERY_THROW);
     233          16 :     CPPUNIT_ASSERT(xCooSysContainer.is());
     234             : 
     235          32 :     Sequence<Reference<chart2::XCoordinateSystem> > xCooSysSequence = xCooSysContainer->getCoordinateSystems();
     236          16 :     CPPUNIT_ASSERT(xCooSysSequence.getLength() > nCooSys);
     237             : 
     238          32 :     Reference<chart2::XCoordinateSystem> xCoord = xCooSysSequence[nCooSys];
     239          16 :     CPPUNIT_ASSERT(xCoord.is());
     240             : 
     241          16 :     Reference<chart2::XAxis> xAxis = xCoord->getAxisByDimension(nAxisDim, nAxisIndex);
     242          16 :     CPPUNIT_ASSERT(xAxis.is());
     243             : 
     244          32 :     return xAxis;
     245             : }
     246             : 
     247          48 : Reference< chart2::XDataSeries > getDataSeriesFromDoc( uno::Reference< chart2::XChartDocument > xChartDoc,
     248             :                                                                 sal_Int32 nDataSeries, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     249             : {
     250          48 :     Reference< chart2::XChartType > xChartType = getChartTypeFromDoc( xChartDoc, nChartType, nCooSys );
     251          96 :     Reference< chart2::XDataSeriesContainer > xDataSeriesContainer( xChartType, UNO_QUERY_THROW );
     252          48 :     CPPUNIT_ASSERT ( xDataSeriesContainer.is() );
     253             : 
     254          96 :     Sequence< Reference< chart2::XDataSeries > > xSeriesSequence( xDataSeriesContainer->getDataSeries() );
     255          48 :     CPPUNIT_ASSERT( xSeriesSequence.getLength() > nDataSeries );
     256             : 
     257          48 :     Reference< chart2::XDataSeries > xSeries = xSeriesSequence[nDataSeries];
     258             : 
     259          96 :     return xSeries;
     260             : }
     261             : 
     262           4 : Reference< chart2::data::XDataSequence > getLabelDataSequenceFromDoc(
     263             :         Reference< chart2::XChartDocument > xChartDoc,
     264             :         sal_Int32 nDataSeries = 0, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     265             : {
     266             :     Reference< chart2::XDataSeries > xDataSeries =
     267           4 :         getDataSeriesFromDoc( xChartDoc, nDataSeries, nChartType, nCooSys );
     268           4 :     CPPUNIT_ASSERT(xDataSeries.is());
     269           8 :     Reference< chart2::data::XDataSource > xDataSource( xDataSeries, uno::UNO_QUERY_THROW );
     270             :     Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences =
     271           8 :         xDataSource->getDataSequences();
     272           8 :     for(sal_Int32 i = 0; i < xDataSequences.getLength(); ++i)
     273             :     {
     274           8 :         Reference< chart2::data::XDataSequence> xLabelSeq = xDataSequences[i]->getLabel();
     275           8 :         if(!xLabelSeq.is())
     276           4 :             continue;
     277             : 
     278           4 :         return xLabelSeq;
     279           0 :     }
     280             : 
     281           0 :     CPPUNIT_FAIL("no Label sequence found");
     282           4 :     return Reference< chart2::data::XDataSequence > ();
     283             : }
     284             : 
     285           2 : Reference< chart2::data::XDataSequence > getDataSequenceFromDocByRole(
     286             :         Reference< chart2::XChartDocument > xChartDoc, const OUString& rRole,
     287             :         sal_Int32 nDataSeries = 0, sal_Int32 nChartType = 0, sal_Int32 nCooSys = 0 )
     288             : {
     289             :     Reference< chart2::XDataSeries > xDataSeries =
     290           2 :         getDataSeriesFromDoc( xChartDoc, nDataSeries, nChartType, nCooSys );
     291           2 :     CPPUNIT_ASSERT(xDataSeries.is());
     292           4 :     Reference< chart2::data::XDataSource > xDataSource( xDataSeries, uno::UNO_QUERY_THROW );
     293             :     Sequence< Reference< chart2::data::XLabeledDataSequence > > xDataSequences =
     294           4 :         xDataSource->getDataSequences();
     295           4 :     for(sal_Int32 i = 0; i < xDataSequences.getLength(); ++i)
     296             :     {
     297           4 :         Reference< chart2::data::XDataSequence> xLabelSeq = xDataSequences[i]->getValues();
     298           6 :         uno::Reference< beans::XPropertySet > xProps(xLabelSeq, uno::UNO_QUERY);
     299           4 :         if(!xProps.is())
     300           0 :             continue;
     301             : 
     302           6 :         OUString aRoleName = xProps->getPropertyValue("Role").get<OUString>();
     303             : 
     304           4 :         if(aRoleName == rRole)
     305           2 :             return xLabelSeq;
     306           2 :     }
     307             : 
     308           0 :     CPPUNIT_FAIL("no Label sequence found");
     309           2 :     return Reference< chart2::data::XDataSequence > ();
     310             : }
     311             : 
     312           4 : uno::Sequence < OUString > getWriterChartColumnDescriptions( Reference< lang::XComponent > mxComponent )
     313             : {
     314           4 :     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     315           8 :     uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
     316           8 :     uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
     317           4 :     CPPUNIT_ASSERT( xShape.is() );
     318           8 :     uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
     319           8 :     uno::Reference< chart2::XChartDocument > xChartDoc;
     320           4 :     xChartDoc.set( xPropertySet->getPropertyValue( "Model" ), uno::UNO_QUERY );
     321           4 :     CPPUNIT_ASSERT( xChartDoc.is() );
     322           4 :     CPPUNIT_ASSERT( xChartDoc->getDataProvider().is() );
     323           8 :     uno::Reference<beans::XPropertySet> xProp(xChartDoc->getDataProvider(), uno::UNO_QUERY );
     324           8 :     uno::Reference< chart2::XAnyDescriptionAccess > xAnyDescriptionAccess ( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
     325           4 :     CPPUNIT_ASSERT( xAnyDescriptionAccess.is() );
     326           4 :     uno::Sequence< OUString > seriesList = xAnyDescriptionAccess->getColumnDescriptions();
     327           8 :     return seriesList;
     328             : }
     329             : 
     330           2 : std::vector<std::vector<double> > getDataSeriesYValuesFromChartType( const Reference<chart2::XChartType>& xCT )
     331             : {
     332           2 :     Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY);
     333           2 :     CPPUNIT_ASSERT(xDSCont.is());
     334           4 :     Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries();
     335             : 
     336             :     double fNan;
     337           2 :     rtl::math::setNan(&fNan);
     338             : 
     339           2 :     std::vector<std::vector<double> > aRet;
     340           8 :     for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i)
     341             :     {
     342           6 :         uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY);
     343           6 :         CPPUNIT_ASSERT(xDSrc.is());
     344          12 :         uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences();
     345          18 :         for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j)
     346             :         {
     347          12 :             Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues();
     348          12 :             CPPUNIT_ASSERT(xValues.is());
     349          24 :             Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY);
     350          12 :             if (!xPropSet.is())
     351           0 :                 continue;
     352             : 
     353          24 :             OUString aRoleName;
     354          12 :             xPropSet->getPropertyValue("Role") >>= aRoleName;
     355          12 :             if (aRoleName == "values-y")
     356             :             {
     357           6 :                 uno::Sequence<uno::Any> aData = xValues->getData();
     358          12 :                 std::vector<double> aValues;
     359           6 :                 aValues.reserve(aData.getLength());
     360          30 :                 for (sal_Int32 nVal = 0; nVal < aData.getLength(); ++nVal)
     361             :                 {
     362             :                     double fVal;
     363          24 :                     if (aData[nVal] >>= fVal)
     364          24 :                         aValues.push_back(fVal);
     365             :                     else
     366           0 :                         aValues.push_back(fNan);
     367             :                 }
     368          12 :                 aRet.push_back(aValues);
     369             :             }
     370          12 :         }
     371           6 :     }
     372             : 
     373           4 :     return aRet;
     374             : }
     375             : 
     376          12 : std::vector<uno::Sequence<uno::Any> > getDataSeriesLabelsFromChartType( const Reference<chart2::XChartType>& xCT )
     377             : {
     378          12 :     OUString aLabelRole = xCT->getRoleOfSequenceForSeriesLabel();
     379             : 
     380          24 :     Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY);
     381          12 :     CPPUNIT_ASSERT(xDSCont.is());
     382          24 :     Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries();
     383             : 
     384          12 :     std::vector<uno::Sequence<uno::Any> > aRet;
     385          48 :     for (sal_Int32 i = 0; i < aDataSeriesSeq.getLength(); ++i)
     386             :     {
     387          36 :         uno::Reference<chart2::data::XDataSource> xDSrc(aDataSeriesSeq[i], uno::UNO_QUERY);
     388          36 :         CPPUNIT_ASSERT(xDSrc.is());
     389          72 :         uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences();
     390          86 :         for (sal_Int32 j = 0; j < aDataSeqs.getLength(); ++j)
     391             :         {
     392          50 :             Reference<chart2::data::XDataSequence> xValues = aDataSeqs[j]->getValues();
     393          50 :             CPPUNIT_ASSERT(xValues.is());
     394         100 :             Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY);
     395          50 :             if (!xPropSet.is())
     396           0 :                 continue;
     397             : 
     398         100 :             OUString aRoleName;
     399          50 :             xPropSet->getPropertyValue("Role") >>= aRoleName;
     400          50 :             if (aRoleName == aLabelRole)
     401             :             {
     402          32 :                 Reference<chart2::data::XLabeledDataSequence> xLabel = aDataSeqs[j];
     403          32 :                 CPPUNIT_ASSERT(xLabel.is());
     404          64 :                 Reference<chart2::data::XDataSequence> xDS2 = xLabel->getLabel();
     405          32 :                 CPPUNIT_ASSERT(xDS2.is());
     406          64 :                 uno::Sequence<uno::Any> aData = xDS2->getData();
     407          64 :                 aRet.push_back(aData);
     408             :             }
     409          50 :         }
     410          36 :     }
     411             : 
     412          24 :     return aRet;
     413             : }
     414             : 
     415           6 : uno::Reference< chart::XChartDocument > ChartTest::getChartDocFromImpress( const char* pDir, const char* pName )
     416             : {
     417           6 :     mxComponent = loadFromDesktop(getURLFromSrc(pDir) + OUString::createFromAscii(pName), "com.sun.star.comp.Draw.PresentationDocument");
     418           6 :     uno::Reference< drawing::XDrawPagesSupplier > xDoc(mxComponent, uno::UNO_QUERY_THROW );
     419             :     uno::Reference< drawing::XDrawPage > xPage(
     420          12 :         xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW );
     421           6 :     CPPUNIT_ASSERT(xPage.is());
     422             :     uno::Reference< beans::XPropertySet > xShapeProps(
     423          12 :         xPage->getByIndex(0), uno::UNO_QUERY );
     424           6 :     CPPUNIT_ASSERT(xShapeProps.is());
     425          12 :     uno::Reference< frame::XModel > xDocModel;
     426           6 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     427           6 :     CPPUNIT_ASSERT(xDocModel.is());
     428           6 :     uno::Reference< chart::XChartDocument > xChartDoc( xDocModel, uno::UNO_QUERY_THROW );
     429             : 
     430          12 :     return xChartDoc;
     431             : }
     432             : 
     433          16 : uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromDrawImpress(
     434             :     sal_Int32 nPage, sal_Int32 nShape )
     435             : {
     436          16 :     uno::Reference<chart::XChartDocument> xEmpty;
     437             : 
     438          32 :     uno::Reference<drawing::XDrawPagesSupplier> xPages(mxComponent, uno::UNO_QUERY);
     439          16 :     if (!xPages.is())
     440           0 :         return xEmpty;
     441             : 
     442             :     uno::Reference<drawing::XDrawPage> xPage(
     443          32 :         xPages->getDrawPages()->getByIndex(nPage), uno::UNO_QUERY_THROW);
     444          16 :     if (!xPage.is())
     445           0 :         return xEmpty;
     446             : 
     447          32 :     uno::Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(nShape), uno::UNO_QUERY);
     448          16 :     if (!xShapeProps.is())
     449           0 :         return xEmpty;
     450             : 
     451          32 :     uno::Reference<frame::XModel> xDocModel;
     452          16 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     453          16 :     if (!xDocModel.is())
     454           0 :         return xEmpty;
     455             : 
     456          32 :     uno::Reference<chart::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY);
     457          32 :     return xChartDoc;
     458             : }
     459             : 
     460          32 : uno::Reference<chart::XChartDocument> ChartTest::getChartDocFromWriter( sal_Int32 nShape )
     461             : {
     462             :     // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created
     463             :     // during import, only in layout!
     464          32 :     Reference<text::XTextEmbeddedObjectsSupplier> xEOS(mxComponent, uno::UNO_QUERY);
     465          32 :     CPPUNIT_ASSERT(xEOS.is());
     466          64 :     Reference<container::XIndexAccess> xEmbeddeds(xEOS->getEmbeddedObjects(), uno::UNO_QUERY);
     467          32 :     CPPUNIT_ASSERT(xEmbeddeds.is());
     468             : 
     469          64 :     Reference<beans::XPropertySet> xShapeProps(xEmbeddeds->getByIndex(nShape), uno::UNO_QUERY);
     470          32 :     CPPUNIT_ASSERT(xShapeProps.is());
     471             : 
     472          64 :     Reference<frame::XModel> xDocModel;
     473          32 :     xShapeProps->getPropertyValue("Model") >>= xDocModel;
     474          32 :     CPPUNIT_ASSERT(xDocModel.is());
     475             : 
     476          32 :     uno::Reference<chart::XChartDocument> xChartDoc(xDocModel, uno::UNO_QUERY);
     477          64 :     return xChartDoc;
     478             : }
     479             : 
     480           4 : uno::Sequence < OUString > ChartTest::getImpressChartColumnDescriptions( const char* pDir, const char* pName )
     481             : {
     482           4 :     uno::Reference< chart::XChartDocument > xChartDoc = getChartDocFromImpress( pDir, pName );
     483           8 :     uno::Reference< chart::XChartDataArray > xChartData ( xChartDoc->getData(), uno::UNO_QUERY_THROW);
     484           4 :     CPPUNIT_ASSERT(xChartData.is());
     485           4 :     uno::Sequence < OUString > seriesList = xChartData->getColumnDescriptions();
     486           8 :     return seriesList;
     487             : }
     488             : 
     489          14 : OUString getTitleString( const Reference<chart2::XTitled>& xTitled )
     490             : {
     491          14 :     uno::Reference<chart2::XTitle> xTitle = xTitled->getTitleObject();
     492          14 :     CPPUNIT_ASSERT(xTitle.is());
     493          28 :     uno::Sequence<uno::Reference<chart2::XFormattedString> > aFSSeq = xTitle->getText();
     494          14 :     OUString aText;
     495          40 :     for (sal_Int32 i = 0; i < aFSSeq.getLength(); ++i)
     496          26 :         aText += aFSSeq[i]->getString();
     497             : 
     498          28 :     return aText;
     499             : }
     500             : 
     501           8 : sal_Int32 getNumberFormat( const Reference<chart2::XChartDocument>& xChartDoc, const OUString& sFormat )
     502             : {
     503           8 :     Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
     504          16 :     Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
     505           8 :     CPPUNIT_ASSERT(xNumberFormats.is());
     506             : 
     507          16 :     return xNumberFormats->queryKey(sFormat, css::lang::Locale(), sal_False);
     508             : }
     509             : 
     510          16 : sal_Int32 getNumberFormatFromAxis( const Reference<chart2::XAxis>& xAxis )
     511             : {
     512          16 :     Reference<beans::XPropertySet> xPS(xAxis, uno::UNO_QUERY);
     513          16 :     CPPUNIT_ASSERT(xPS.is());
     514          16 :     sal_Int32 nNumberFormat = -1;
     515          16 :     bool bSuccess = xPS->getPropertyValue(CHART_UNONAME_NUMFMT) >>= nNumberFormat;
     516          16 :     CPPUNIT_ASSERT(bSuccess);
     517             : 
     518          16 :     return nNumberFormat;
     519             : }
     520             : 
     521          16 : sal_Int16 getNumberFormatType( const Reference<chart2::XChartDocument>& xChartDoc, sal_Int32 nNumberFormat )
     522             : {
     523          16 :     Reference<util::XNumberFormatsSupplier> xNFS(xChartDoc, uno::UNO_QUERY_THROW);
     524          32 :     Reference<util::XNumberFormats> xNumberFormats = xNFS->getNumberFormats();
     525          16 :     CPPUNIT_ASSERT(xNumberFormats.is());
     526             : 
     527          32 :     Reference<beans::XPropertySet> xNumPS = xNumberFormats->getByKey(nNumberFormat);
     528          16 :     CPPUNIT_ASSERT(xNumPS.is());
     529             : 
     530          16 :     sal_Int16 nType = util::NumberFormat::UNDEFINED;
     531          16 :     xNumPS->getPropertyValue("Type") >>= nType;
     532             : 
     533          32 :     return nType;
     534             : }
     535             : 
     536             : #endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
     537             : 
     538             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10