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 #ifndef INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
11 #define INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
13 #include <test/bootstrapfixture.hxx>
14 #include <unotest/macros_test.hxx>
15 #include <comphelper/processfactory.hxx>
16 #include <comphelper/propertysequence.hxx>
18 #include <com/sun/star/lang/XComponent.hpp>
19 #include <com/sun/star/frame/Desktop.hpp>
21 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
22 #include <com/sun/star/container/XIndexAccess.hpp>
23 #include <com/sun/star/table/XTableChartsSupplier.hpp>
24 #include <com/sun/star/table/XTableChart.hpp>
25 #include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
26 #include <com/sun/star/table/XTablePivotChart.hpp>
27 #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/frame/XStorable.hpp>
31 #include <unotools/tempfile.hxx>
33 #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
34 #include <com/sun/star/chart2/XChartDocument.hpp>
35 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
36 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
37 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
38 #include <com/sun/star/chart2/XFormattedString.hpp>
39 #include <com/sun/star/chart2/XTitle.hpp>
40 #include <com/sun/star/chart2/XTitled.hpp>
41 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
42 #include <com/sun/star/chart2/data/XDataSource.hpp>
43 #include <com/sun/star/chart/XChartDataArray.hpp>
44 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
45 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
46 #include <com/sun/star/chart/XChartDocument.hpp>
47 #include <com/sun/star/text/XTextEmbeddedObjectsSupplier.hpp>
48 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
49 #include <com/sun/star/util/NumberFormat.hpp>
51 #include <unonames.hxx>
56 #include <com/sun/star/embed/Aspects.hpp>
57 #include <com/sun/star/embed/XVisualObject.hpp>
58 #include <com/sun/star/chart2/RelativeSize.hpp>
61 using namespace css::uno
;
63 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XDataSeries
; } } } }
64 namespace com
{ namespace sun
{ namespace star
{ namespace chart2
{ class XDiagram
; } } } }
65 namespace com
{ namespace sun
{ namespace star
{ namespace table
{ class XTableCharts
; } } } }
66 namespace com
{ namespace sun
{ namespace star
{ namespace table
{ class XTablePivotCharts
; } } } }
68 class ChartTest
: public test::BootstrapFixture
, public unotest::MacrosTest
71 ChartTest():mbSkipValidation(false) {}
72 void load( const OUString
& rDir
, const OUString
& rFileName
);
73 std::shared_ptr
<utl::TempFile
> save( const OUString
& rFileName
);
74 std::shared_ptr
<utl::TempFile
> reload( const OUString
& rFileName
);
75 uno::Sequence
< OUString
> getImpressChartColumnDescriptions( const OUString
& pDir
, const char* pName
);
76 OUString
getFileExtension( const OUString
& rFileName
);
78 uno::Reference
< chart::XChartDocument
> getChartDocFromImpress( const OUString
& pDir
, const char* pName
);
80 uno::Reference
<chart::XChartDocument
> getChartDocFromDrawImpress( sal_Int32 nPage
, sal_Int32 nShape
);
82 uno::Reference
<chart::XChartDocument
> getChartDocFromWriter( sal_Int32 nShape
);
83 awt::Size
getPageSize( const Reference
< chart2::XChartDocument
> & xChartDoc
);
84 awt::Size
getSize(css::uno::Reference
<chart2::XDiagram
> xDiagram
, const awt::Size
& rPageSize
);
86 virtual void setUp() override
;
87 virtual void tearDown() override
;
90 Reference
< lang::XComponent
> mxComponent
;
91 OUString maServiceName
;
92 bool mbSkipValidation
; // if you set this flag for a new test I'm going to haunt you!
95 OUString
ChartTest::getFileExtension( const OUString
& aFileName
)
97 sal_Int32 nDotLocation
= aFileName
.lastIndexOf('.');
98 CPPUNIT_ASSERT(nDotLocation
!= -1);
99 return aFileName
.copy(nDotLocation
+1); // Skip the dot.
102 void ChartTest::load( const OUString
& aDir
, const OUString
& aName
)
104 OUString extension
= getFileExtension(aName
);
105 if (extension
== "ods" || extension
== "xlsx" || extension
== "fods")
107 maServiceName
= "com.sun.star.sheet.SpreadsheetDocument";
109 else if (extension
== "docx")
111 maServiceName
= "com.sun.star.text.TextDocument";
113 else if (extension
== "odg")
115 maServiceName
= "com.sun.star.drawing.DrawingDocument";
117 if (mxComponent
.is())
118 mxComponent
->dispose();
119 mxComponent
= loadFromDesktop(m_directories
.getURLFromSrc(aDir
) + aName
, maServiceName
);
120 CPPUNIT_ASSERT(mxComponent
.is());
123 std::shared_ptr
<utl::TempFile
> ChartTest::save(const OUString
& rFilterName
)
125 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
126 auto aArgs(::comphelper::InitPropertySequence({
127 { "FilterName", Any(rFilterName
) }
129 std::shared_ptr
<utl::TempFile
> pTempFile
= std::make_shared
<utl::TempFile
>();
130 pTempFile
->EnableKillingFile();
131 xStorable
->storeToURL(pTempFile
->GetURL(), aArgs
);
136 std::shared_ptr
<utl::TempFile
> ChartTest::reload(const OUString
& rFilterName
)
138 std::shared_ptr
<utl::TempFile
> pTempFile
= save(rFilterName
);
139 mxComponent
->dispose();
140 mxComponent
= loadFromDesktop(pTempFile
->GetURL(), maServiceName
);
141 std::cout
<< pTempFile
->GetURL();
142 if(rFilterName
== "Calc Office Open XML")
144 validate(pTempFile
->GetFileName(), test::OOXML
);
146 else if(rFilterName
== "Office Open XML Text")
148 // validate(pTempFile->GetFileName(), test::OOXML);
150 else if(rFilterName
== "calc8")
152 if(!mbSkipValidation
)
153 validate(pTempFile
->GetFileName(), test::ODF
);
155 else if(rFilterName
== "MS Excel 97")
157 if(!mbSkipValidation
)
158 validate(pTempFile
->GetFileName(), test::MSBINARY
);
160 CPPUNIT_ASSERT(mxComponent
.is());
164 void ChartTest::setUp()
166 test::BootstrapFixture::setUp();
168 mxDesktop
.set( css::frame::Desktop::create( comphelper::getComponentContext(getMultiServiceFactory()) ) );
171 void ChartTest::tearDown()
174 mxComponent
->dispose();
176 test::BootstrapFixture::tearDown();
180 Reference
< lang::XComponent
> getChartCompFromSheet( sal_Int32 nSheet
, uno::Reference
< lang::XComponent
> const & xComponent
)
182 // let us assume that we only have one chart per sheet
184 uno::Reference
< sheet::XSpreadsheetDocument
> xDoc(xComponent
, UNO_QUERY_THROW
);
186 uno::Reference
< container::XIndexAccess
> xIA(xDoc
->getSheets(), UNO_QUERY_THROW
);
188 uno::Reference
< table::XTableChartsSupplier
> xChartSupplier( xIA
->getByIndex(nSheet
), UNO_QUERY_THROW
);
190 uno::Reference
< table::XTableCharts
> xCharts
= xChartSupplier
->getCharts();
191 CPPUNIT_ASSERT(xCharts
.is());
193 uno::Reference
< container::XIndexAccess
> xIACharts(xCharts
, UNO_QUERY_THROW
);
194 uno::Reference
< table::XTableChart
> xChart( xIACharts
->getByIndex(0), UNO_QUERY_THROW
);
196 uno::Reference
< document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xChart
, UNO_QUERY_THROW
);
198 uno::Reference
< lang::XComponent
> xChartComp( xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
204 Reference
< chart2::XChartDocument
> getChartDocFromSheet( sal_Int32 nSheet
, uno::Reference
< lang::XComponent
> const & xComponent
)
206 uno::Reference
< chart2::XChartDocument
> xChartDoc ( getChartCompFromSheet(nSheet
, xComponent
), UNO_QUERY_THROW
);
210 uno::Reference
<table::XTablePivotCharts
> getTablePivotChartsFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
212 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(xComponent
, UNO_QUERY_THROW
);
214 uno::Reference
<container::XIndexAccess
> xIA(xDoc
->getSheets(), UNO_QUERY_THROW
);
216 uno::Reference
<table::XTablePivotChartsSupplier
> xChartSupplier(xIA
->getByIndex(nSheet
), UNO_QUERY_THROW
);
218 uno::Reference
<table::XTablePivotCharts
> xTablePivotCharts
= xChartSupplier
->getPivotCharts();
219 CPPUNIT_ASSERT(xTablePivotCharts
.is());
221 return xTablePivotCharts
;
224 Reference
<lang::XComponent
> getPivotChartCompFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
226 uno::Reference
<table::XTablePivotCharts
> xTablePivotCharts
= getTablePivotChartsFromSheet(nSheet
, xComponent
);
228 uno::Reference
<container::XIndexAccess
> xIACharts(xTablePivotCharts
, UNO_QUERY_THROW
);
229 uno::Reference
<table::XTablePivotChart
> xTablePivotChart(xIACharts
->getByIndex(0), UNO_QUERY_THROW
);
231 uno::Reference
<document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xTablePivotChart
, UNO_QUERY_THROW
);
233 uno::Reference
<lang::XComponent
> xChartComp(xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
238 Reference
<chart2::XChartDocument
> getPivotChartDocFromSheet(sal_Int32 nSheet
, uno::Reference
<lang::XComponent
> const & xComponent
)
240 uno::Reference
<chart2::XChartDocument
> xChartDoc(getPivotChartCompFromSheet(nSheet
, xComponent
), UNO_QUERY_THROW
);
244 Reference
<chart2::XChartDocument
> getPivotChartDocFromSheet(uno::Reference
<table::XTablePivotCharts
> const & xTablePivotCharts
, sal_Int32 nIndex
)
246 uno::Reference
<container::XIndexAccess
> xIACharts(xTablePivotCharts
, UNO_QUERY_THROW
);
247 uno::Reference
<table::XTablePivotChart
> xTablePivotChart(xIACharts
->getByIndex(nIndex
), UNO_QUERY_THROW
);
249 uno::Reference
<document::XEmbeddedObjectSupplier
> xEmbObjectSupplier(xTablePivotChart
, UNO_QUERY_THROW
);
251 uno::Reference
<lang::XComponent
> xChartComp(xEmbObjectSupplier
->getEmbeddedObject(), UNO_SET_THROW
);
253 uno::Reference
<chart2::XChartDocument
> xChartDoc(xChartComp
, UNO_QUERY_THROW
);
257 Reference
< chart2::XChartType
> getChartTypeFromDoc( Reference
< chart2::XChartDocument
> const & xChartDoc
,
258 sal_Int32 nChartType
, sal_Int32 nCooSys
= 0 )
260 CPPUNIT_ASSERT( xChartDoc
.is() );
262 Reference
<chart2::XDiagram
> xDiagram
= xChartDoc
->getFirstDiagram();
263 CPPUNIT_ASSERT( xDiagram
.is() );
265 Reference
< chart2::XCoordinateSystemContainer
> xCooSysContainer( xDiagram
, UNO_QUERY_THROW
);
267 Sequence
< Reference
< chart2::XCoordinateSystem
> > xCooSysSequence( xCooSysContainer
->getCoordinateSystems());
268 CPPUNIT_ASSERT( xCooSysSequence
.getLength() > nCooSys
);
270 Reference
< chart2::XChartTypeContainer
> xChartTypeContainer( xCooSysSequence
[nCooSys
], UNO_QUERY_THROW
);
272 Sequence
< Reference
< chart2::XChartType
> > xChartTypeSequence( xChartTypeContainer
->getChartTypes() );
273 CPPUNIT_ASSERT( xChartTypeSequence
.getLength() > nChartType
);
275 return xChartTypeSequence
[nChartType
];
278 Reference
<chart2::XAxis
> getAxisFromDoc(
279 const Reference
<chart2::XChartDocument
>& xChartDoc
, sal_Int32 nCooSys
, sal_Int32 nAxisDim
, sal_Int32 nAxisIndex
)
281 Reference
<chart2::XDiagram
> xDiagram
= xChartDoc
->getFirstDiagram();
282 CPPUNIT_ASSERT(xDiagram
.is());
284 Reference
<chart2::XCoordinateSystemContainer
> xCooSysContainer(xDiagram
, UNO_QUERY_THROW
);
286 Sequence
<Reference
<chart2::XCoordinateSystem
> > xCooSysSequence
= xCooSysContainer
->getCoordinateSystems();
287 CPPUNIT_ASSERT(xCooSysSequence
.getLength() > nCooSys
);
289 Reference
<chart2::XCoordinateSystem
> xCoord
= xCooSysSequence
[nCooSys
];
290 CPPUNIT_ASSERT(xCoord
.is());
292 Reference
<chart2::XAxis
> xAxis
= xCoord
->getAxisByDimension(nAxisDim
, nAxisIndex
);
293 CPPUNIT_ASSERT(xAxis
.is());
298 sal_Int32
getNumberOfDataSeries(uno::Reference
<chart2::XChartDocument
> const & xChartDoc
,
299 sal_Int32 nChartType
= 0, sal_Int32 nCooSys
= 0)
301 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc
, nChartType
, nCooSys
);
302 Reference
<chart2::XDataSeriesContainer
> xDataSeriesContainer(xChartType
, UNO_QUERY_THROW
);
304 uno::Sequence
<uno::Reference
<chart2::XDataSeries
>> xSeriesSequence(xDataSeriesContainer
->getDataSeries());
305 return xSeriesSequence
.getLength();
308 Reference
< chart2::XDataSeries
> getDataSeriesFromDoc(uno::Reference
<chart2::XChartDocument
> const & xChartDoc
,
309 sal_Int32 nDataSeries
, sal_Int32 nChartType
= 0,
310 sal_Int32 nCooSys
= 0)
312 Reference
< chart2::XChartType
> xChartType
= getChartTypeFromDoc( xChartDoc
, nChartType
, nCooSys
);
313 Reference
< chart2::XDataSeriesContainer
> xDataSeriesContainer( xChartType
, UNO_QUERY_THROW
);
315 Sequence
< Reference
< chart2::XDataSeries
> > xSeriesSequence( xDataSeriesContainer
->getDataSeries() );
316 CPPUNIT_ASSERT( xSeriesSequence
.getLength() > nDataSeries
);
318 Reference
< chart2::XDataSeries
> xSeries
= xSeriesSequence
[nDataSeries
];
323 Reference
< chart2::data::XDataSequence
> getLabelDataSequenceFromDoc(
324 Reference
< chart2::XChartDocument
> const & xChartDoc
,
325 sal_Int32 nDataSeries
= 0, sal_Int32 nChartType
= 0 )
327 Reference
< chart2::XDataSeries
> xDataSeries
=
328 getDataSeriesFromDoc( xChartDoc
, nDataSeries
, nChartType
);
329 CPPUNIT_ASSERT(xDataSeries
.is());
330 Reference
< chart2::data::XDataSource
> xDataSource( xDataSeries
, uno::UNO_QUERY_THROW
);
331 Sequence
< Reference
< chart2::data::XLabeledDataSequence
> > xDataSequences
=
332 xDataSource
->getDataSequences();
333 for(sal_Int32 i
= 0; i
< xDataSequences
.getLength(); ++i
)
335 Reference
< chart2::data::XDataSequence
> xLabelSeq
= xDataSequences
[i
]->getLabel();
342 CPPUNIT_FAIL("no Label sequence found");
345 Reference
< chart2::data::XDataSequence
> getDataSequenceFromDocByRole(
346 Reference
< chart2::XChartDocument
> const & xChartDoc
, const OUString
& rRole
,
347 sal_Int32 nDataSeries
= 0, sal_Int32 nChartType
= 0 )
349 Reference
< chart2::XDataSeries
> xDataSeries
=
350 getDataSeriesFromDoc( xChartDoc
, nDataSeries
, nChartType
);
351 CPPUNIT_ASSERT(xDataSeries
.is());
352 Reference
< chart2::data::XDataSource
> xDataSource( xDataSeries
, uno::UNO_QUERY_THROW
);
353 Sequence
< Reference
< chart2::data::XLabeledDataSequence
> > xDataSequences
=
354 xDataSource
->getDataSequences();
355 for(sal_Int32 i
= 0; i
< xDataSequences
.getLength(); ++i
)
357 Reference
< chart2::data::XDataSequence
> xLabelSeq
= xDataSequences
[i
]->getValues();
358 uno::Reference
< beans::XPropertySet
> xProps(xLabelSeq
, uno::UNO_QUERY
);
362 OUString aRoleName
= xProps
->getPropertyValue("Role").get
<OUString
>();
364 if(aRoleName
== rRole
)
368 return Reference
< chart2::data::XDataSequence
> ();
371 uno::Sequence
< OUString
> getWriterChartColumnDescriptions( Reference
< lang::XComponent
> const & mxComponent
)
373 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(mxComponent
, uno::UNO_QUERY
);
374 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
375 uno::Reference
<drawing::XShape
> xShape(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
376 CPPUNIT_ASSERT( xShape
.is() );
377 uno::Reference
<beans::XPropertySet
> xPropertySet(xShape
, uno::UNO_QUERY
);
378 uno::Reference
< chart2::XChartDocument
> xChartDoc
;
379 xChartDoc
.set( xPropertySet
->getPropertyValue( "Model" ), uno::UNO_QUERY
);
380 CPPUNIT_ASSERT( xChartDoc
.is() );
381 CPPUNIT_ASSERT( xChartDoc
->getDataProvider().is() );
382 uno::Reference
<beans::XPropertySet
> xProp(xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
383 uno::Reference
< chart2::XAnyDescriptionAccess
> xAnyDescriptionAccess ( xChartDoc
->getDataProvider(), uno::UNO_QUERY_THROW
);
384 uno::Sequence
< OUString
> seriesList
= xAnyDescriptionAccess
->getColumnDescriptions();
388 std::vector
<std::vector
<double> > getDataSeriesYValuesFromChartType( const Reference
<chart2::XChartType
>& xCT
)
390 Reference
<chart2::XDataSeriesContainer
> xDSCont(xCT
, uno::UNO_QUERY
);
391 CPPUNIT_ASSERT(xDSCont
.is());
392 Sequence
<uno::Reference
<chart2::XDataSeries
> > aDataSeriesSeq
= xDSCont
->getDataSeries();
395 rtl::math::setNan(&fNan
);
397 std::vector
<std::vector
<double> > aRet
;
398 for (sal_Int32 i
= 0; i
< aDataSeriesSeq
.getLength(); ++i
)
400 uno::Reference
<chart2::data::XDataSource
> xDSrc(aDataSeriesSeq
[i
], uno::UNO_QUERY
);
401 CPPUNIT_ASSERT(xDSrc
.is());
402 uno::Sequence
<Reference
<chart2::data::XLabeledDataSequence
> > aDataSeqs
= xDSrc
->getDataSequences();
403 for (sal_Int32 j
= 0; j
< aDataSeqs
.getLength(); ++j
)
405 Reference
<chart2::data::XDataSequence
> xValues
= aDataSeqs
[j
]->getValues();
406 CPPUNIT_ASSERT(xValues
.is());
407 Reference
<beans::XPropertySet
> xPropSet(xValues
, uno::UNO_QUERY
);
412 xPropSet
->getPropertyValue("Role") >>= aRoleName
;
413 if (aRoleName
== "values-y")
415 uno::Sequence
<uno::Any
> aData
= xValues
->getData();
416 std::vector
<double> aValues
;
417 aValues
.reserve(aData
.getLength());
418 for (sal_Int32 nVal
= 0; nVal
< aData
.getLength(); ++nVal
)
421 if (aData
[nVal
] >>= fVal
)
422 aValues
.push_back(fVal
);
424 aValues
.push_back(fNan
);
426 aRet
.push_back(aValues
);
434 std::vector
<uno::Sequence
<uno::Any
> > getDataSeriesLabelsFromChartType( const Reference
<chart2::XChartType
>& xCT
)
436 OUString aLabelRole
= xCT
->getRoleOfSequenceForSeriesLabel();
438 Reference
<chart2::XDataSeriesContainer
> xDSCont(xCT
, uno::UNO_QUERY
);
439 CPPUNIT_ASSERT(xDSCont
.is());
440 Sequence
<uno::Reference
<chart2::XDataSeries
> > aDataSeriesSeq
= xDSCont
->getDataSeries();
442 std::vector
<uno::Sequence
<uno::Any
> > aRet
;
443 for (sal_Int32 i
= 0; i
< aDataSeriesSeq
.getLength(); ++i
)
445 uno::Reference
<chart2::data::XDataSource
> xDSrc(aDataSeriesSeq
[i
], uno::UNO_QUERY
);
446 CPPUNIT_ASSERT(xDSrc
.is());
447 uno::Sequence
<Reference
<chart2::data::XLabeledDataSequence
> > aDataSeqs
= xDSrc
->getDataSequences();
448 for (sal_Int32 j
= 0; j
< aDataSeqs
.getLength(); ++j
)
450 Reference
<chart2::data::XDataSequence
> xValues
= aDataSeqs
[j
]->getValues();
451 CPPUNIT_ASSERT(xValues
.is());
452 Reference
<beans::XPropertySet
> xPropSet(xValues
, uno::UNO_QUERY
);
457 xPropSet
->getPropertyValue("Role") >>= aRoleName
;
458 if (aRoleName
== aLabelRole
)
460 Reference
<chart2::data::XLabeledDataSequence
> xLabel
= aDataSeqs
[j
];
461 CPPUNIT_ASSERT(xLabel
.is());
462 Reference
<chart2::data::XDataSequence
> xDS2
= xLabel
->getLabel();
463 CPPUNIT_ASSERT(xDS2
.is());
464 uno::Sequence
<uno::Any
> aData
= xDS2
->getData();
465 aRet
.push_back(aData
);
473 uno::Reference
< chart::XChartDocument
> ChartTest::getChartDocFromImpress( const OUString
& pDir
, const char* pName
)
475 mxComponent
= loadFromDesktop(m_directories
.getURLFromSrc(pDir
) + OUString::createFromAscii(pName
), "com.sun.star.comp.Draw.PresentationDocument");
476 uno::Reference
< drawing::XDrawPagesSupplier
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
477 uno::Reference
< drawing::XDrawPage
> xPage(
478 xDoc
->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW
);
479 uno::Reference
< beans::XPropertySet
> xShapeProps(
480 xPage
->getByIndex(0), uno::UNO_QUERY
);
481 CPPUNIT_ASSERT(xShapeProps
.is());
482 uno::Reference
< frame::XModel
> xDocModel
;
483 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
484 CPPUNIT_ASSERT(xDocModel
.is());
485 uno::Reference
< chart::XChartDocument
> xChartDoc( xDocModel
, uno::UNO_QUERY_THROW
);
490 uno::Reference
<chart::XChartDocument
> ChartTest::getChartDocFromDrawImpress(
491 sal_Int32 nPage
, sal_Int32 nShape
)
493 uno::Reference
<chart::XChartDocument
> xEmpty
;
495 uno::Reference
<drawing::XDrawPagesSupplier
> xPages(mxComponent
, uno::UNO_QUERY
);
499 uno::Reference
<drawing::XDrawPage
> xPage(
500 xPages
->getDrawPages()->getByIndex(nPage
), uno::UNO_QUERY_THROW
);
502 uno::Reference
<beans::XPropertySet
> xShapeProps(xPage
->getByIndex(nShape
), uno::UNO_QUERY
);
503 if (!xShapeProps
.is())
506 uno::Reference
<frame::XModel
> xDocModel
;
507 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
511 uno::Reference
<chart::XChartDocument
> xChartDoc(xDocModel
, uno::UNO_QUERY
);
515 uno::Reference
<chart::XChartDocument
> ChartTest::getChartDocFromWriter( sal_Int32 nShape
)
517 // DO NOT use XDrawPageSupplier since SwVirtFlyDrawObj are not created
518 // during import, only in layout!
519 Reference
<text::XTextEmbeddedObjectsSupplier
> xEOS(mxComponent
, uno::UNO_QUERY
);
520 CPPUNIT_ASSERT(xEOS
.is());
521 Reference
<container::XIndexAccess
> xEmbeddeds(xEOS
->getEmbeddedObjects(), uno::UNO_QUERY
);
522 CPPUNIT_ASSERT(xEmbeddeds
.is());
524 Reference
<beans::XPropertySet
> xShapeProps(xEmbeddeds
->getByIndex(nShape
), uno::UNO_QUERY
);
525 CPPUNIT_ASSERT(xShapeProps
.is());
527 Reference
<frame::XModel
> xDocModel
;
528 xShapeProps
->getPropertyValue("Model") >>= xDocModel
;
529 CPPUNIT_ASSERT(xDocModel
.is());
531 uno::Reference
<chart::XChartDocument
> xChartDoc(xDocModel
, uno::UNO_QUERY
);
535 uno::Sequence
< OUString
> ChartTest::getImpressChartColumnDescriptions( const OUString
& pDir
, const char* pName
)
537 uno::Reference
< chart::XChartDocument
> xChartDoc
= getChartDocFromImpress( pDir
, pName
);
538 uno::Reference
< chart::XChartDataArray
> xChartData ( xChartDoc
->getData(), uno::UNO_QUERY_THROW
);
539 uno::Sequence
< OUString
> seriesList
= xChartData
->getColumnDescriptions();
543 OUString
getTitleString( const Reference
<chart2::XTitled
>& xTitled
)
545 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
546 CPPUNIT_ASSERT(xTitle
.is());
547 uno::Sequence
<uno::Reference
<chart2::XFormattedString
> > aFSSeq
= xTitle
->getText();
549 for (sal_Int32 i
= 0; i
< aFSSeq
.getLength(); ++i
)
550 aText
+= aFSSeq
[i
]->getString();
555 sal_Int32
getNumberFormat( const Reference
<chart2::XChartDocument
>& xChartDoc
, const OUString
& sFormat
)
557 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
558 Reference
<util::XNumberFormats
> xNumberFormats
= xNFS
->getNumberFormats();
559 CPPUNIT_ASSERT(xNumberFormats
.is());
561 return xNumberFormats
->queryKey(sFormat
, css::lang::Locale(), false);
564 sal_Int32
getNumberFormatFromAxis( const Reference
<chart2::XAxis
>& xAxis
)
566 Reference
<beans::XPropertySet
> xPS(xAxis
, uno::UNO_QUERY
);
567 CPPUNIT_ASSERT(xPS
.is());
568 sal_Int32 nNumberFormat
= -1;
569 bool bSuccess
= xPS
->getPropertyValue(CHART_UNONAME_NUMFMT
) >>= nNumberFormat
;
570 CPPUNIT_ASSERT(bSuccess
);
572 return nNumberFormat
;
575 sal_Int16
getNumberFormatType( const Reference
<chart2::XChartDocument
>& xChartDoc
, sal_Int32 nNumberFormat
)
577 Reference
<util::XNumberFormatsSupplier
> xNFS(xChartDoc
, uno::UNO_QUERY_THROW
);
578 Reference
<util::XNumberFormats
> xNumberFormats
= xNFS
->getNumberFormats();
579 CPPUNIT_ASSERT(xNumberFormats
.is());
581 Reference
<beans::XPropertySet
> xNumPS
= xNumberFormats
->getByKey(nNumberFormat
);
582 CPPUNIT_ASSERT(xNumPS
.is());
584 sal_Int16 nType
= util::NumberFormat::UNDEFINED
;
585 xNumPS
->getPropertyValue("Type") >>= nType
;
590 awt::Size
ChartTest::getPageSize( const Reference
< chart2::XChartDocument
> & xChartDoc
)
592 awt::Size
aSize( 0, 0 );
593 uno::Reference
< com::sun::star::embed::XVisualObject
> xVisualObject( xChartDoc
, uno::UNO_QUERY
);
594 CPPUNIT_ASSERT( xVisualObject
.is() );
595 aSize
= xVisualObject
->getVisualAreaSize( com::sun::star::embed::Aspects::MSOLE_CONTENT
);
599 awt::Size
ChartTest::getSize(css::uno::Reference
<chart2::XDiagram
> xDiagram
, const awt::Size
& rPageSize
)
601 Reference
< beans::XPropertySet
> xProp(xDiagram
, uno::UNO_QUERY
);
602 chart2::RelativeSize aRelativeSize
;
603 xProp
->getPropertyValue( "RelativeSize" ) >>= aRelativeSize
;
604 double fX
= aRelativeSize
.Primary
* rPageSize
.Width
;
605 double fY
= aRelativeSize
.Secondary
* rPageSize
.Height
;
607 aSize
.Width
= static_cast< sal_Int32
>( ::rtl::math::round( fX
) );
608 aSize
.Height
= static_cast< sal_Int32
>( ::rtl::math::round( fY
) );
612 #endif // INCLUDED_CHART2_QA_EXTRAS_CHARTTEST_HXX
614 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */