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 <charttest.hxx>
11 #include <com/sun/star/chart2/XChartDocument.hpp>
12 #include <com/sun/star/chart/XChartDocument.hpp>
13 #include <com/sun/star/text/XText.hpp>
14 #include <com/sun/star/drawing/HomogenMatrix3.hpp>
15 #include <com/sun/star/drawing/LineDash.hpp>
16 #include <com/sun/star/drawing/LineStyle.hpp>
17 #include <com/sun/star/drawing/FillStyle.hpp>
19 #include <editeng/unoprnms.hxx>
20 #include <rtl/ustring.hxx>
21 #include <rtl/ustrbuf.hxx>
24 #include <string_view>
32 #define DECLARE_DUMP_TEST(TestName, BaseClass, DumpMode) \
33 class TestName : public BaseClass { \
35 virtual OUString getTestName() override { return u"" #TestName ""_ustr; } \
37 TestName() : BaseClass(DumpMode) {}; \
38 CPPUNIT_TEST_SUITE(TestName); \
39 CPPUNIT_TEST(verify); \
40 CPPUNIT_TEST_SUITE_END(); \
41 virtual void verify() override;\
43 CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
44 void TestName::verify()
47 #define CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aActual) \
49 writeActual(OUString::number(aActual), u"" #aActual ""_ustr); \
52 OString sTestFileName = OUStringToOString(getTestFileName(), RTL_TEXTENCODING_UTF8); \
53 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Failing test file is: " + sTestFileName).getStr(), readExpected(u ## #aActual), OUString(OUString::number(aActual))); \
56 #define CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aActual, EPS_) \
58 writeActual(OUString::number(aActual), u"" #aActual ""_ustr); \
61 OString sTestFileName = OUStringToOString(getTestFileName(), RTL_TEXTENCODING_UTF8); \
62 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(OString("Failing test file is: " + sTestFileName).getStr(), readExpectedDouble(u ## #aActual), aActual, EPS_); \
65 #define CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(aActual) \
67 writeActual(aActual, u"" #aActual ""_ustr); \
70 OString sTestFileName = OUStringToOString(getTestFileName(), RTL_TEXTENCODING_UTF8); \
71 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Failing test file is: " + sTestFileName).getStr(), readExpected(u ## #aActual), aActual.trim()); \
74 #define CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aActual, EPS_) \
76 writeActualTransformation(aActual, u"" #aActual ""_ustr); \
79 OUString expectedTransform; \
80 if (!readAndCheckTransformation (aActual, u ## #aActual, EPS_, expectedTransform)) \
82 OString sTestFileName = OUStringToOString(getTestFileName(), RTL_TEXTENCODING_UTF8); \
83 CPPUNIT_ASSERT_EQUAL_MESSAGE(OString("Failing test file is: " + sTestFileName).getStr(), expectedTransform, transformationToOneLineString(aActual)); \
87 class Chart2DumpTest
: public ChartTest
90 Chart2DumpTest(bool bDumpMode
)
91 : ChartTest(u
"/chart2/qa/extras/chart2dump/data/"_ustr
)
93 m_bDumpMode
= bDumpMode
;
96 virtual ~Chart2DumpTest() override
100 void CPPUNIT_DUMP_ASSERT_NOTE(OUString
const & Note
) {
107 bool isInDumpMode () const {return m_bDumpMode
;}
109 virtual OUString
getTestName() { return OUString(); }
110 OUString
const & getTestFileName() const { return m_sTestFileName
; }
111 OUString
getReferenceDirName()
113 return "/chart2/qa/extras/chart2dump/reference/" + getTestName().toAsciiLowerCase() + "/";
116 void setTestFileName (const OUString
& sName
)
118 m_sTestFileName
= sName
;
120 OUString sFileName
= m_sTestFileName
;
121 assert(sFileName
.lastIndexOf('.') < sFileName
.getLength());
122 sFileName
= OUString::Concat(sFileName
.subView(0, sFileName
.lastIndexOf('.'))) + ".txt";
125 if (m_aReferenceFile
.is_open())
126 m_aReferenceFile
.close();
127 OString sReferenceFile
= OUStringToOString(Concat2View(m_directories
.getPathFromSrc(getReferenceDirName()) + sFileName
), RTL_TEXTENCODING_UTF8
);
128 m_aReferenceFile
.open(sReferenceFile
.getStr(), std::ios_base::in
);
129 CPPUNIT_ASSERT_MESSAGE(OString("Can't open reference file: " + sReferenceFile
).getStr(), m_aReferenceFile
.is_open());
133 if (m_aDumpFile
.is_open())
135 OString sDumpFile
= OUStringToOString(Concat2View(m_directories
.getPathFromSrc(getReferenceDirName()) + sFileName
), RTL_TEXTENCODING_UTF8
);
136 m_aDumpFile
.open(sDumpFile
.getStr(), std::ios_base::out
| std::ofstream::binary
| std::ofstream::trunc
);
137 CPPUNIT_ASSERT_MESSAGE(OString("Can't open dump file: " + sDumpFile
).getStr(), m_aDumpFile
.is_open());
141 virtual void verify()
143 CPPUNIT_FAIL("verify method must be overridden");
146 OUString
readExpected(std::u16string_view sCheck
)
148 assert(!m_bDumpMode
);
149 assert(m_aReferenceFile
.is_open());
151 getline(m_aReferenceFile
, sTemp
);
152 OString sAssertMessage
=
153 "The reference file does not contain the right content. Maybe it needs an update:"
154 + OUStringToOString(m_sTestFileName
, RTL_TEXTENCODING_UTF8
);
155 CPPUNIT_ASSERT_EQUAL_MESSAGE(sAssertMessage
.getStr(), OUString(OUString::Concat("// ") + sCheck
), OUString(sTemp
.data(), sTemp
.length(), RTL_TEXTENCODING_UTF8
));
156 getline(m_aReferenceFile
, sTemp
);
157 return OUString(sTemp
.data(), sTemp
.length(), RTL_TEXTENCODING_UTF8
);
160 void writeActual(std::u16string_view sActualValue
, const OUString
& sCheck
)
163 assert(m_aDumpFile
.is_open());
164 m_aDumpFile
<< "// " << sCheck
<< "\n"; // Add check string to make dump file readable
165 m_aDumpFile
<< OUString(sActualValue
) << "\n"; // Write out the checked value, will be used as reference later
168 void readNote(std::u16string_view sNote
)
170 assert(!m_bDumpMode
);
171 assert(m_aReferenceFile
.is_open());
173 getline(m_aReferenceFile
, sTemp
);
174 OString sAssertMessage
=
175 "The reference file does not contain the right content. Maybe it needs an update:"
176 + OUStringToOString(m_sTestFileName
, RTL_TEXTENCODING_UTF8
);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE(sAssertMessage
.getStr(), OUString(OUString::Concat("/// ") + sNote
), OUString(sTemp
.data(), sTemp
.length(), RTL_TEXTENCODING_UTF8
));
180 void writeNote(const OUString
& sNote
)
183 assert(m_aDumpFile
.is_open());
184 m_aDumpFile
<< "/// " << sNote
<< "\n";
187 double readExpectedDouble(std::u16string_view sCheck
)
189 OUString sExpected
= readExpected(sCheck
);
190 return sExpected
.toDouble();
193 void writeActualTransformation(const drawing::HomogenMatrix3
& rTransform
, const OUString
& sCheck
)
195 writeActual(transformationToOneLineString(rTransform
), sCheck
);
198 bool readAndCheckTransformation(const drawing::HomogenMatrix3
& rTransform
, std::u16string_view sCheck
, const double fEPS
, OUString
& rExpectedTransform
)
200 rExpectedTransform
= readExpected(sCheck
); // Reference transformation string
202 // Convert string back to a transformation;
203 drawing::HomogenMatrix3 aExpectedTransform
;
205 aExpectedTransform
.Line1
.Column1
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
206 aExpectedTransform
.Line1
.Column2
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
207 aExpectedTransform
.Line1
.Column3
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
208 aExpectedTransform
.Line2
.Column1
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
209 aExpectedTransform
.Line2
.Column2
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
210 aExpectedTransform
.Line2
.Column3
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
211 aExpectedTransform
.Line3
.Column1
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
212 aExpectedTransform
.Line3
.Column2
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
213 aExpectedTransform
.Line3
.Column3
= o3tl::toDouble(o3tl::getToken(rExpectedTransform
, 0, ';', nIdx
));
215 // Check the equality of the two transformation
216 return (std::abs(aExpectedTransform
.Line1
.Column1
- rTransform
.Line1
.Column1
) < fEPS
&&
217 std::abs(aExpectedTransform
.Line1
.Column2
- rTransform
.Line1
.Column2
) < fEPS
&&
218 std::abs(aExpectedTransform
.Line1
.Column3
- rTransform
.Line1
.Column3
) < fEPS
&&
219 std::abs(aExpectedTransform
.Line2
.Column1
- rTransform
.Line2
.Column1
) < fEPS
&&
220 std::abs(aExpectedTransform
.Line2
.Column2
- rTransform
.Line2
.Column2
) < fEPS
&&
221 std::abs(aExpectedTransform
.Line2
.Column3
- rTransform
.Line2
.Column3
) < fEPS
&&
222 std::abs(aExpectedTransform
.Line3
.Column1
- rTransform
.Line3
.Column1
) < fEPS
&&
223 std::abs(aExpectedTransform
.Line3
.Column2
- rTransform
.Line3
.Column2
) < fEPS
&&
224 std::abs(aExpectedTransform
.Line3
.Column3
- rTransform
.Line3
.Column3
) < fEPS
);
227 OUString
sequenceToOneLineString(const uno::Sequence
<OUString
>& rSeq
)
229 OUStringBuffer aBuffer
;
230 for (const OUString
& seqItem
: rSeq
)
232 aBuffer
.append(seqItem
+ ";");
234 return aBuffer
.makeStringAndClear();
237 OUString
doubleVectorToOneLineString(const std::vector
<double>& rVector
)
239 OUStringBuffer aBuffer
;
240 for (const double& vectorItem
: rVector
)
242 aBuffer
.append(OUString::number(vectorItem
) + ";");
244 return aBuffer
.makeStringAndClear();
247 OUString
transformationToOneLineString(const drawing::HomogenMatrix3
& rTransform
)
249 return OUString::number(rTransform
.Line1
.Column1
) + ";" + OUString::number(rTransform
.Line1
.Column2
) + ";" + OUString::number(rTransform
.Line1
.Column3
) + ";" +
250 OUString::number(rTransform
.Line2
.Column1
) + ";" + OUString::number(rTransform
.Line2
.Column2
) + ";" + OUString::number(rTransform
.Line2
.Column3
) + ";" +
251 OUString::number(rTransform
.Line3
.Column1
) + ";" + OUString::number(rTransform
.Line3
.Column2
) + ";" + OUString::number(rTransform
.Line3
.Column3
);
255 OUString m_sTestFileName
;
257 std::ifstream m_aReferenceFile
;
258 std::ofstream m_aDumpFile
;
261 DECLARE_DUMP_TEST(ChartDataTest
, Chart2DumpTest
, false)
263 const std::vector
<OUString
> aTestFiles
=
265 u
"simple_chart.ods"_ustr
,
266 u
"multiple_categories.ods"_ustr
269 for (const OUString
& aTestFile
: aTestFiles
)
271 setTestFileName(aTestFile
);
272 loadFromFile(getTestFileName());
273 uno::Reference
< chart::XChartDocument
> xChartDoc (getChartDocFromSheet(0), UNO_QUERY_THROW
);
276 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
277 Reference
<chart2::XTitled
> xTitled(xChartDoc
, uno::UNO_QUERY_THROW
);
278 uno::Reference
<chart2::XTitle
> xTitle
= xTitled
->getTitleObject();
281 OUString sChartTitle
= getTitleString(xTitled
);
282 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sChartTitle
);
286 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
287 CPPUNIT_ASSERT(xChartType
.is());
288 OUString sChartType
= xChartType
->getChartType();
289 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sChartType
);
291 // Check axis titles and number format
293 Reference
<chart2::XAxis
> xAxis
= getAxisFromDoc(xChartDoc2
, 0, 0, 0);
294 Reference
<chart2::XTitled
> xAxisTitled(xAxis
, UNO_QUERY_THROW
);
295 uno::Reference
<chart2::XTitle
> xAxisTitle
= xAxisTitled
->getTitleObject();
298 OUString sXAxisTitle
= getTitleString(xAxisTitled
);
299 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sXAxisTitle
);
301 sal_Int32 nXAxisNumberFormat
= getNumberFormatFromAxis(xAxis
);
302 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nXAxisNumberFormat
);
303 sal_Int16 nXAxisNumberType
= getNumberFormatType(xChartDoc2
, nXAxisNumberFormat
);
304 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nXAxisNumberType
);
307 xAxis
.set(getAxisFromDoc(xChartDoc2
, 0, 1, 0));
308 xAxisTitled
.set(xAxis
, UNO_QUERY_THROW
);
309 xAxisTitle
.set(xAxisTitled
->getTitleObject());
312 OUString sYAxisTitle
= getTitleString(xAxisTitled
);
313 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sYAxisTitle
);
315 sal_Int32 nYAxisNumberFormat
= getNumberFormatFromAxis(xAxis
);
316 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nYAxisNumberFormat
);
317 sal_Int16 nYAxisNumberType
= getNumberFormatType(xChartDoc2
, nYAxisNumberFormat
);
318 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nYAxisNumberType
);
320 // Check column labels
321 uno::Reference
< chart::XChartDataArray
> xChartData(xChartDoc
->getData(), UNO_QUERY_THROW
);
322 uno::Sequence
< OUString
> aColumnLabels
= xChartData
->getColumnDescriptions();
323 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aColumnLabels
.getLength());
324 OUString sColumnLabels
= sequenceToOneLineString(aColumnLabels
);
325 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sColumnLabels
);
328 uno::Sequence
< OUString
> aRowLabels
= xChartData
->getRowDescriptions();
329 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aRowLabels
.getLength());
330 OUString sRowLabels
= sequenceToOneLineString(aRowLabels
);
331 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sRowLabels
);
334 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
335 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aDataSeriesYValues
.size());
336 for (const std::vector
<double>& aYValuesOfSeries
: aDataSeriesYValues
)
338 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(aYValuesOfSeries
.size());
339 OUString sYValuesOfSeries
= doubleVectorToOneLineString(aYValuesOfSeries
);
340 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sYValuesOfSeries
);
343 // Check source ranges
344 for (size_t nIndex
= 0; nIndex
< aDataSeriesYValues
.size(); ++nIndex
)
346 Reference
< chart2::data::XDataSequence
> xDataSeq
= getDataSequenceFromDocByRole(xChartDoc2
, u
"values-x", nIndex
);
349 OUString aXValuesSourceRange
= xDataSeq
->getSourceRangeRepresentation();
350 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(aXValuesSourceRange
);
352 xDataSeq
.set(getDataSequenceFromDocByRole(xChartDoc2
, u
"values-y", nIndex
));
355 OUString aYValuesSourceRange
= xDataSeq
->getSourceRangeRepresentation();
356 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(aYValuesSourceRange
);
358 xDataSeq
.set(getDataSequenceFromDocByRole(xChartDoc2
, u
"categories", nIndex
));
361 OUString aCategoriesSourceRange
= xDataSeq
->getSourceRangeRepresentation();
362 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(aCategoriesSourceRange
);
368 DECLARE_DUMP_TEST(LegendTest
, Chart2DumpTest
, false)
370 const std::vector
<OUString
> aTestFiles
=
372 u
"legend_on_right_side.odp"_ustr
,
373 u
"legend_on_bottom.odp"_ustr
,
374 u
"legend_on_left_side.odp"_ustr
,
375 u
"legend_on_top.odp"_ustr
,
376 u
"many_legend_entries.odp"_ustr
,
377 u
"custom_legend_position.odp"_ustr
,
378 u
"multiple_categories.odp"_ustr
,
379 u
"minimal_legend_test.odp"_ustr
382 for (const OUString
& aTestFile
: aTestFiles
)
384 setTestFileName(aTestFile
);
385 loadFromFile(getTestFileName());
386 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), UNO_SET_THROW
);
387 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
388 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
389 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
390 CPPUNIT_ASSERT(xShapes
.is());
393 uno::Reference
<drawing::XShape
> xLegend
= getShapeByName(xShapes
, u
"CID/D=0:Legend="_ustr
);
394 CPPUNIT_ASSERT(xLegend
.is());
396 /* Check legend position and size
397 awt::Point aLegendPosition = xLegend->getPosition();
398 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendPosition.X, INT_EPS);
399 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendPosition.Y, INT_EPS);
400 awt::Size aLegendSize = xLegend->getSize();
401 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendSize.Width, INT_EPS);
402 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendSize.Height, INT_EPS);*/
404 // Check legend entries
405 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
406 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
407 CPPUNIT_ASSERT(xChartType
.is());
408 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
409 size_t nLegendEntryCount
= aDataSeriesYValues
.size();
410 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nLegendEntryCount
);
411 // Check legend entries geometry
412 for (size_t nSeriesIndex
= 0; nSeriesIndex
< nLegendEntryCount
; ++nSeriesIndex
)
414 uno::Reference
<drawing::XShape
> xLegendEntry
= getShapeByName(xShapes
, "CID/MultiClick/D=0:CS=0:CT=0:Series=" + OUString::number(nSeriesIndex
) + ":LegendEntry=0");
415 CPPUNIT_ASSERT(xLegendEntry
.is());
417 /* Check position and size
418 awt::Point aLegendEntryPosition = xLegendEntry->getPosition();
419 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendEntryPosition.X, INT_EPS);
420 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendEntryPosition.Y, INT_EPS);
421 awt::Size aLegendEntrySize = xLegendEntry->getSize();
422 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendEntrySize.Height, INT_EPS);
423 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLegendEntrySize.Width, INT_EPS);
425 // Check transformation
426 Reference< beans::XPropertySet > xLegendEntryPropSet(xLegendEntry, UNO_QUERY_THROW);
427 drawing::HomogenMatrix3 aLegendEntryTransformation;
428 xLegendEntryPropSet->getPropertyValue("Transformation") >>= aLegendEntryTransformation;
429 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aLegendEntryTransformation, INT_EPS);*/
431 uno::Reference
<container::XIndexAccess
> xLegendEntryContainer(xLegendEntry
, UNO_QUERY_THROW
);
432 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(xLegendEntryContainer
->getCount());
433 for (sal_Int32 nEntryGeometryElement
= 1; nEntryGeometryElement
< xLegendEntryContainer
->getCount(); ++nEntryGeometryElement
)
435 uno::Reference
<drawing::XShape
> xLegendEntryGeom(xLegendEntryContainer
->getByIndex(nEntryGeometryElement
), UNO_QUERY_THROW
);
438 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xLegendEntryGeom
, uno::UNO_QUERY_THROW
);
439 OUString sEntryGeomShapeType
= xShapeDescriptor
->getShapeType();
440 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sEntryGeomShapeType
);
442 // Check display color
443 Reference
< beans::XPropertySet
> xPropSet(xLegendEntryGeom
, UNO_QUERY_THROW
);
444 util::Color aEntryGeomColor
= 0;
445 xPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aEntryGeomColor
;
446 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aEntryGeomColor
));
449 // Check legend entries' text
450 uno::Reference
<container::XIndexAccess
> xLegendContainer(xLegend
, UNO_QUERY_THROW
);
451 for (sal_Int32 i
= 0; i
< xLegendContainer
->getCount(); ++i
)
453 uno::Reference
<drawing::XShape
> xShape(xLegendContainer
->getByIndex(i
), uno::UNO_QUERY
);
454 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xShape
, uno::UNO_QUERY_THROW
);
455 OUString sShapeType
= xShapeDescriptor
->getShapeType();
457 if (sShapeType
== "com.sun.star.drawing.TextShape")
459 uno::Reference
<text::XText
> xLegendEntryText
= uno::Reference
<text::XTextRange
>(xShape
, uno::UNO_QUERY_THROW
)->getText();
460 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(xLegendEntryText
->getString());
466 DECLARE_DUMP_TEST(GridTest
, Chart2DumpTest
, false)
468 const std::vector
<OUString
> aTestFiles
=
470 u
"vertical_grid.ods"_ustr
,
471 u
"horizontal_grid.ods"_ustr
,
472 u
"minor_grid.ods"_ustr
,
473 u
"formated_grid_line.ods"_ustr
476 for (const OUString
& sTestFile
: aTestFiles
)
478 setTestFileName(sTestFile
);
479 loadFromFile(getTestFileName());
480 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
481 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
482 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
483 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
484 CPPUNIT_ASSERT(xShapes
.is());
486 const std::vector
<OUString
> aGridShapeNames
=
488 u
"CID/D=0:CS=0:Axis=1,0:Grid=0"_ustr
, // Major vertical grid
489 u
"CID/D=0:CS=0:Axis=0,0:Grid=0"_ustr
, // Major horizontal grid
490 u
"CID/D=0:CS=0:Axis=1,0:Grid=0:SubGrid=0"_ustr
, // Minor vertical grid
491 u
"CID/D=0:CS=0:Axis=0,0:Grid=0:SubGrid=0"_ustr
// Minor horizontal grid
494 for (const OUString
& sGridShapeName
: aGridShapeNames
)
496 uno::Reference
<drawing::XShape
> xGrid
= getShapeByName(xShapes
, sGridShapeName
);
499 CPPUNIT_DUMP_ASSERT_NOTE(sGridShapeName
);
500 // Check position and size
501 awt::Point aGridPosition
= xGrid
->getPosition();
502 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aGridPosition
.X
, INT_EPS
);
503 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aGridPosition
.Y
, INT_EPS
);
504 awt::Size aGridSize
= xGrid
->getSize();
505 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aGridSize
.Height
, INT_EPS
);
506 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aGridSize
.Width
, INT_EPS
);
508 // Check transformation
509 Reference
< beans::XPropertySet
> xPropSet(xGrid
, UNO_QUERY_THROW
);
510 drawing::HomogenMatrix3 aGridTransformation
;
511 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aGridTransformation
;
512 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aGridTransformation
, INT_EPS
);
514 // Check line properties
515 uno::Reference
<container::XIndexAccess
> xIndexAccess(xGrid
, UNO_QUERY_THROW
);
516 uno::Reference
<drawing::XShape
> xGridLine(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
517 Reference
< beans::XPropertySet
> xGridLinePropSet(xGridLine
, UNO_QUERY_THROW
);
519 drawing::LineDash aLineDash
;
520 xGridLinePropSet
->getPropertyValue(u
"LineDash"_ustr
) >>= aLineDash
;
521 OUString sGridLineDash
=
522 OUString::number(static_cast<sal_Int32
>(aLineDash
.Style
)) + ";" + OUString::number(aLineDash
.Dots
) + ";" + OUString::number(aLineDash
.DotLen
) +
523 OUString::number(aLineDash
.Dashes
) + ";" + OUString::number(aLineDash
.DashLen
) + ";" + OUString::number(aLineDash
.Distance
);
524 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sGridLineDash
);
526 util::Color aLineColor
= 0;
527 xGridLinePropSet
->getPropertyValue(u
"LineColor"_ustr
) >>= aLineColor
;
528 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aLineColor
));
530 sal_Int32 nLineWidth
= 0;
531 xGridLinePropSet
->getPropertyValue(u
"LineWidth"_ustr
) >>= nLineWidth
;
532 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nLineWidth
);
538 DECLARE_DUMP_TEST(AxisGeometryTest
, Chart2DumpTest
, false)
540 const std::vector
<OUString
> aTestFiles
=
542 u
"default_formated_axis.odp"_ustr
,
543 u
"axis_special_positioning.odp"_ustr
,
544 u
"formated_axis_lines.odp"_ustr
,
545 u
"rotated_axis_labels.odp"_ustr
548 for (const OUString
& sTestFile
: aTestFiles
)
550 setTestFileName(sTestFile
);
551 loadFromFile(getTestFileName());
552 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), UNO_SET_THROW
);
553 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
554 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
555 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
556 CPPUNIT_ASSERT(xShapes
.is());
558 const std::vector
<OUString
> aAxisShapeNames
=
560 u
"CID/D=0:CS=0:Axis=0,0"_ustr
, // X Axis
561 u
"CID/D=0:CS=0:Axis=1,0"_ustr
, // Y Axis
564 for (const OUString
& sAxisShapeName
: aAxisShapeNames
)
566 uno::Reference
<drawing::XShape
> xXAxis
= getShapeByName(xShapes
, sAxisShapeName
);
567 CPPUNIT_ASSERT(xXAxis
.is());
569 CPPUNIT_DUMP_ASSERT_NOTE(sAxisShapeName
);
570 // Check position and size
571 awt::Point aAxisPosition
= xXAxis
->getPosition();
572 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAxisPosition
.X
, INT_EPS
);
573 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAxisPosition
.Y
, INT_EPS
);
574 awt::Size aAxisSize
= xXAxis
->getSize();
575 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAxisSize
.Height
, INT_EPS
);
576 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAxisSize
.Width
, INT_EPS
);
578 // Check transformation
579 Reference
< beans::XPropertySet
> xPropSet(xXAxis
, UNO_QUERY_THROW
);
580 drawing::HomogenMatrix3 aAxisTransformation
;
581 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aAxisTransformation
;
582 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aAxisTransformation
, INT_EPS
);
584 // Check line properties
585 uno::Reference
<container::XIndexAccess
> xIndexAccess(xXAxis
, UNO_QUERY_THROW
);
586 sal_Int32 nAxisGeometriesCount
= xIndexAccess
->getCount();
587 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nAxisGeometriesCount
);
588 uno::Reference
<drawing::XShape
> xAxisLine(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
589 Reference
< beans::XPropertySet
> xAxisLinePropSet(xAxisLine
, UNO_QUERY_THROW
);
591 drawing::LineDash aLineDash
;
592 xAxisLinePropSet
->getPropertyValue(u
"LineDash"_ustr
) >>= aLineDash
;
593 OUString sAxisLineDash
=
594 OUString::number(static_cast<sal_Int32
>(aLineDash
.Style
)) + ";" + OUString::number(aLineDash
.Dots
) + ";" + OUString::number(aLineDash
.DotLen
) +
595 OUString::number(aLineDash
.Dashes
) + ";" + OUString::number(aLineDash
.DashLen
) + ";" + OUString::number(aLineDash
.Distance
);
596 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sAxisLineDash
);
598 util::Color aAxisLineColor
= 0;
599 xAxisLinePropSet
->getPropertyValue(u
"LineColor"_ustr
) >>= aAxisLineColor
;
600 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aAxisLineColor
));
602 sal_Int32 nAxisLineWidth
= 0;
603 xAxisLinePropSet
->getPropertyValue(u
"LineWidth"_ustr
) >>= nAxisLineWidth
;
604 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nAxisLineWidth
);
609 DECLARE_DUMP_TEST(AxisLabelTest
, Chart2DumpTest
, false)
611 const std::vector
<OUString
> aTestFiles
=
613 u
"default_formated_axis.odp"_ustr
,
614 u
"rotated_axis_labels.odp"_ustr
,
615 u
"formated_axis_labels.odp"_ustr
,
616 u
"percent_stacked_column_chart.odp"_ustr
,
617 u
"tdf118150.xlsx"_ustr
,
618 u
"date-categories.pptx"_ustr
,
621 for (const OUString
& sTestFile
: aTestFiles
)
623 setTestFileName(sTestFile
);
624 loadFromFile(getTestFileName());
625 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), UNO_SET_THROW
);
626 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
627 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
628 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
629 CPPUNIT_ASSERT(xShapes
.is());
631 const std::vector
<OUString
> aAxisShapeNames
=
633 u
"CID/D=0:CS=0:Axis=0,0"_ustr
, // X Axis
634 u
"CID/D=0:CS=0:Axis=1,0"_ustr
, // Y Axis
637 for (const OUString
& sAxisShapeName
: aAxisShapeNames
)
639 uno::Reference
<drawing::XShape
> xXAxis
= getShapeByName(xShapes
, sAxisShapeName
,
640 // Axis occurs twice in chart xshape representation so need to get the one related to labels
641 [](const uno::Reference
<drawing::XShape
>& rXShape
) -> bool
643 uno::Reference
<drawing::XShapes
> xAxisShapes(rXShape
, uno::UNO_QUERY
);
644 CPPUNIT_ASSERT(xAxisShapes
.is());
645 uno::Reference
<drawing::XShape
> xChildShape(xAxisShapes
->getByIndex(0), uno::UNO_QUERY
);
646 uno::Reference
< drawing::XShapeDescriptor
> xShapeDescriptor(xChildShape
, uno::UNO_QUERY_THROW
);
647 return (xShapeDescriptor
->getShapeType() == "com.sun.star.drawing.TextShape");
649 CPPUNIT_ASSERT(xXAxis
.is());
650 CPPUNIT_DUMP_ASSERT_NOTE(sAxisShapeName
);
653 uno::Reference
<container::XIndexAccess
> xIndexAccess(xXAxis
, UNO_QUERY_THROW
);
654 sal_Int32 nAxisLabelsCount
= xIndexAccess
->getCount();
655 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nAxisLabelsCount
);
657 // Check labels's text, positioning and font properties
658 for (sal_Int32 nLabelIndex
= 0; nLabelIndex
< nAxisLabelsCount
; ++nLabelIndex
)
661 uno::Reference
<text::XTextRange
> xLabel(xIndexAccess
->getByIndex(nLabelIndex
), uno::UNO_QUERY
);
662 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(xLabel
->getString());
664 // Check size and position
665 uno::Reference
<drawing::XShape
> xLabelShape(xLabel
, uno::UNO_QUERY
);
666 /*awt::Point aLabelPosition = xLabelShape->getPosition();
667 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLabelPosition.X, INT_EPS);
668 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLabelPosition.Y, INT_EPS);
669 awt::Size aLabelSize = xLabelShape->getSize();
670 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLabelSize.Height, INT_EPS);
671 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLabelSize.Width, INT_EPS);*/
673 // Check transformation
674 Reference
< beans::XPropertySet
> xPropSet(xLabelShape
, UNO_QUERY_THROW
);
675 /*drawing::HomogenMatrix3 aLabelTransformation;
676 xPropSet->getPropertyValue("Transformation") >>= aLabelTransformation;
677 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aLabelTransformation, INT_EPS);*/
679 // Check font color and height
680 util::Color aLabelFontColor
= 0;
681 xPropSet
->getPropertyValue(u
"CharColor"_ustr
) >>= aLabelFontColor
;
682 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aLabelFontColor
));
683 float fLabelFontHeight
= 0.0f
;
684 xPropSet
->getPropertyValue(u
"CharHeight"_ustr
) >>= fLabelFontHeight
;
685 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(fLabelFontHeight
, 1E-12);
691 DECLARE_DUMP_TEST(ColumnBarChartTest
, Chart2DumpTest
, false)
693 const std::vector
<OUString
> aTestFiles
=
695 u
"normal_column_chart.ods"_ustr
,
696 u
"stacked_column_chart.ods"_ustr
,
697 u
"percent_stacked_column_chart.ods"_ustr
,
698 u
"column_chart_small_spacing.ods"_ustr
,
699 u
"normal_bar_chart.ods"_ustr
,
700 u
"stacked_bar_chart.ods"_ustr
,
701 u
"percent_stacked_bar_chart.ods"_ustr
,
704 for (const OUString
& sTestFile
: aTestFiles
)
706 setTestFileName(sTestFile
);
707 loadFromFile(getTestFileName());
708 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
709 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
710 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
711 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
712 CPPUNIT_ASSERT(xShapes
.is());
714 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
715 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
716 CPPUNIT_ASSERT(xChartType
.is());
717 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
718 size_t nSeriesCount
= aDataSeriesYValues
.size();
719 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nSeriesCount
);
721 for (size_t nSeries
= 0; nSeries
< nSeriesCount
; ++nSeries
)
723 uno::Reference
<drawing::XShape
> xSeriesColumnsOrBars
= getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=" + OUString::number(nSeries
));
724 CPPUNIT_ASSERT(xSeriesColumnsOrBars
.is());
725 CPPUNIT_DUMP_ASSERT_NOTE("Series " + OUString::number(nSeries
) + " ColumnsOrBars");
727 // Check column/bar count in the series
728 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSeriesColumnsOrBars
, UNO_QUERY_THROW
);
729 sal_Int32 nColumnOrBarCountInSeries
= xIndexAccess
->getCount();
730 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nColumnOrBarCountInSeries
);
732 // Check column/bar fill style and color
733 Reference
< beans::XPropertySet
> xColumnOrBarPropSet(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
734 drawing::FillStyle aSeriesColumnOrBarFillStyle
;
735 xColumnOrBarPropSet
->getPropertyValue(UNO_NAME_FILLSTYLE
) >>= aSeriesColumnOrBarFillStyle
;
736 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aSeriesColumnOrBarFillStyle
));
737 util::Color aSeriesColumnOrBarFillColor
= 0;
738 xColumnOrBarPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aSeriesColumnOrBarFillColor
;
739 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aSeriesColumnOrBarFillColor
));
741 for (sal_Int32 nColumnOrBar
= 0; nColumnOrBar
< nColumnOrBarCountInSeries
; ++nColumnOrBar
)
743 uno::Reference
<drawing::XShape
> xColumnOrBar(xIndexAccess
->getByIndex(nColumnOrBar
), UNO_QUERY_THROW
);
744 uno::Reference
<container::XNamed
> xNamedShape(xIndexAccess
->getByIndex(nColumnOrBar
), uno::UNO_QUERY
);
745 CPPUNIT_DUMP_ASSERT_NOTE(xNamedShape
->getName());
747 // Check size and position
748 awt::Point aColumnOrBarPosition
= xColumnOrBar
->getPosition();
749 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aColumnOrBarPosition
.X
, INT_EPS
);
750 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aColumnOrBarPosition
.Y
, INT_EPS
);
751 awt::Size aColumnOrBarSize
= xColumnOrBar
->getSize();
752 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aColumnOrBarSize
.Height
, INT_EPS
);
753 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aColumnOrBarSize
.Width
, INT_EPS
);
755 // Check transformation
756 Reference
< beans::XPropertySet
> xPropSet(xColumnOrBar
, UNO_QUERY_THROW
);
757 drawing::HomogenMatrix3 aColumnOrBarTransformation
;
758 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aColumnOrBarTransformation
;
759 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aColumnOrBarTransformation
, INT_EPS
);
765 DECLARE_DUMP_TEST(ChartWallTest
, Chart2DumpTest
, false)
767 const std::vector
<OUString
> aTestFiles
=
769 u
"chartwall_auto_adjust_with_titles.ods"_ustr
,
770 u
"chartwall_auto_adjust_without_titles.ods"_ustr
,
771 u
"chartwall_custom_positioning.ods"_ustr
774 for (const OUString
& sTestFile
: aTestFiles
)
776 setTestFileName(sTestFile
);
777 loadFromFile(getTestFileName());
778 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromDrawImpress(0, 0), UNO_SET_THROW
);
779 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
780 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
781 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
782 CPPUNIT_ASSERT(xShapes
.is());
784 uno::Reference
<drawing::XShape
> xChartWall
= getShapeByName(xShapes
, u
"CID/DiagramWall="_ustr
);
785 CPPUNIT_ASSERT(xChartWall
.is());
787 // Check position and size
788 /*awt::Point aChartWallPosition = xChartWall->getPosition();
789 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aChartWallPosition.X, INT_EPS);
790 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aChartWallPosition.Y, INT_EPS);
791 awt::Size aChartWallSize = xChartWall->getSize();
792 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aChartWallSize.Height, INT_EPS);
793 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aChartWallSize.Width, INT_EPS);*/
795 // Check transformation
796 Reference
< beans::XPropertySet
> xPropSet(xChartWall
, UNO_QUERY_THROW
);
797 /*drawing::HomogenMatrix3 aChartWallTransformation;
798 xPropSet->getPropertyValue("Transformation") >>= aChartWallTransformation;
799 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aChartWallTransformation, INT_EPS);*/
801 // Check fill properties
802 drawing::FillStyle aChartWallFillStyle
;
803 xPropSet
->getPropertyValue(UNO_NAME_FILLSTYLE
) >>= aChartWallFillStyle
;
804 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aChartWallFillStyle
));
805 util::Color aChartWallFillColor
= 0;
806 xPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aChartWallFillColor
;
807 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aChartWallFillColor
));
809 // Check line properties
811 drawing::LineDash aLineDash
;
812 xPropSet
->getPropertyValue(u
"LineDash"_ustr
) >>= aLineDash
;
813 OUString sChartWallLineDash
=
814 OUString::number(static_cast<sal_Int32
>(aLineDash
.Style
)) + ";" + OUString::number(aLineDash
.Dots
) + ";" + OUString::number(aLineDash
.DotLen
) +
815 OUString::number(aLineDash
.Dashes
) + ";" + OUString::number(aLineDash
.DashLen
) + ";" + OUString::number(aLineDash
.Distance
);
816 CPPUNIT_DUMP_ASSERT_STRINGS_EQUAL(sChartWallLineDash
);
818 util::Color aChartWallLineColor
= 0;
819 xPropSet
->getPropertyValue(u
"LineColor"_ustr
) >>= aChartWallLineColor
;
820 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aChartWallLineColor
));
822 sal_Int32 nChartWallLineWidth
= 0;
823 xPropSet
->getPropertyValue(u
"LineWidth"_ustr
) >>= nChartWallLineWidth
;
824 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nChartWallLineWidth
);
828 DECLARE_DUMP_TEST(PieChartTest
, Chart2DumpTest
, false)
830 const std::vector
<OUString
> aTestFiles
=
832 u
"normal_pie_chart.ods"_ustr
,
833 u
"rotated_pie_chart.ods"_ustr
,
834 u
"exploded_pie_chart.ods"_ustr
,
835 u
"donut_chart.ods"_ustr
,
836 u
"pie_chart_many_slices.ods"_ustr
,
839 for (const OUString
& sTestFile
: aTestFiles
)
841 setTestFileName(sTestFile
);
842 loadFromFile(getTestFileName());
843 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
844 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
845 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
846 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
847 CPPUNIT_ASSERT(xShapes
.is());
849 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
850 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
851 CPPUNIT_ASSERT(xChartType
.is());
853 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
854 size_t nSeriesCount
= aDataSeriesYValues
.size();
855 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nSeriesCount
);
857 for (size_t nSeries
= 0; nSeries
< nSeriesCount
; ++nSeries
)
859 uno::Reference
<drawing::XShape
> xSeriesSlices
= getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=" + OUString::number(nSeries
));
860 if (!xSeriesSlices
.is())
861 break; // Normal pie chart displays only one series
862 CPPUNIT_DUMP_ASSERT_NOTE("Series " + OUString::number(nSeries
) + " slices");
864 // Check slice count in the series
865 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSeriesSlices
, UNO_QUERY_THROW
);
866 sal_Int32 nSlicesCountInSeries
= xIndexAccess
->getCount();
867 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nSlicesCountInSeries
);
869 // Check slices properties
870 for (sal_Int32 nSlice
= 0; nSlice
< nSlicesCountInSeries
; ++nSlice
)
872 uno::Reference
<drawing::XShape
> xSlice(xIndexAccess
->getByIndex(nSlice
), UNO_QUERY_THROW
);
873 uno::Reference
<container::XNamed
> xNamedShape(xIndexAccess
->getByIndex(nSlice
), uno::UNO_QUERY
);
874 OUString sName
= xNamedShape
->getName();
875 CPPUNIT_DUMP_ASSERT_NOTE(sName
.copy(sName
.lastIndexOf("/D=0")));
877 // Check size and position
878 awt::Point aSlicePosition
= xSlice
->getPosition();
879 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aSlicePosition
.X
, INT_EPS
);
880 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aSlicePosition
.Y
, INT_EPS
);
881 awt::Size aSliceSize
= xSlice
->getSize();
882 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aSliceSize
.Height
, INT_EPS
);
883 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aSliceSize
.Width
, INT_EPS
);
885 // Check transformation
886 Reference
< beans::XPropertySet
> xPropSet(xSlice
, UNO_QUERY_THROW
);
887 drawing::HomogenMatrix3 aSliceTransformation
;
888 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aSliceTransformation
;
889 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aSliceTransformation
, INT_EPS
);
891 // Check slice fill style and color
892 drawing::FillStyle aSliceFillStyle
;
893 xPropSet
->getPropertyValue(UNO_NAME_FILLSTYLE
) >>= aSliceFillStyle
;
894 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aSliceFillStyle
));
895 util::Color aSliceFillColor
= 0;
896 xPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aSliceFillColor
;
897 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aSliceFillColor
));
903 DECLARE_DUMP_TEST(AreaChartTest
, Chart2DumpTest
, false)
905 const std::vector
<OUString
> aTestFiles
=
907 u
"normal_area_chart.ods"_ustr
,
908 u
"stacked_area_chart.ods"_ustr
,
909 u
"percent_stacked_area_chart.ods"_ustr
912 for (const OUString
& sTestFile
: aTestFiles
)
914 setTestFileName(sTestFile
);
915 loadFromFile(getTestFileName());
916 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
917 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
918 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
919 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
920 CPPUNIT_ASSERT(xShapes
.is());
922 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
923 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
924 CPPUNIT_ASSERT(xChartType
.is());
926 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
927 size_t nSeriesCount
= aDataSeriesYValues
.size();
928 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nSeriesCount
);
930 for (size_t nSeries
= 0; nSeries
< nSeriesCount
; ++nSeries
)
932 uno::Reference
<drawing::XShape
> xSeries
= getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=" + OUString::number(nSeries
));
933 CPPUNIT_ASSERT(xSeries
.is());
934 CPPUNIT_DUMP_ASSERT_NOTE("Series " + OUString::number(nSeries
));
936 // One area for one series
937 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSeries
, UNO_QUERY_THROW
);
938 uno::Reference
<container::XIndexAccess
> xIndexAccess2(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
); // Why this second group shape is here?
939 uno::Reference
<drawing::XShape
> xArea(xIndexAccess2
->getByIndex(0), UNO_QUERY_THROW
);
941 // Check size and position
942 awt::Point aAreaPosition
= xArea
->getPosition();
943 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAreaPosition
.X
, INT_EPS
);
944 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAreaPosition
.Y
, INT_EPS
);
945 awt::Size aAreaSize
= xArea
->getSize();
946 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAreaSize
.Height
, INT_EPS
);
947 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aAreaSize
.Width
, INT_EPS
);
949 // Check transformation
950 Reference
< beans::XPropertySet
> xPropSet(xArea
, UNO_QUERY_THROW
);
951 drawing::HomogenMatrix3 aAreaTransformation
;
952 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aAreaTransformation
;
953 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aAreaTransformation
, INT_EPS
);
955 // Check area fill style and color
956 drawing::FillStyle aAreaFillStyle
;
957 xPropSet
->getPropertyValue(UNO_NAME_FILLSTYLE
) >>= aAreaFillStyle
;
958 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aAreaFillStyle
));
959 util::Color aAreaFillColor
= 0;
960 xPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aAreaFillColor
;
961 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aAreaFillColor
));
967 DECLARE_DUMP_TEST(PointLineChartTest
, Chart2DumpTest
, false)
969 const std::vector
<OUString
> aTestFiles
=
971 u
"normal_line_chart_lines_only.ods"_ustr
,
972 u
"normal_line_chart_points_only.ods"_ustr
,
973 u
"normal_line_chart_lines_and_points.ods"_ustr
,
974 u
"stacked_line_chart_lines_only.ods"_ustr
,
975 u
"stacked_line_chart_points_only.ods"_ustr
,
976 u
"stacked_line_chart_lines_and_points.ods"_ustr
,
977 u
"percent_stacked_line_chart_lines_only.ods"_ustr
,
978 u
"percent_stacked_line_chart_points_only.ods"_ustr
,
979 u
"percent_stacked_line_chart_lines_and_points.ods"_ustr
,
980 u
"scatter_chart_points_only.ods"_ustr
,
981 u
"scatter_chart_lines_only.ods"_ustr
,
982 u
"scatter_chart_lines_and_points.ods"_ustr
,
985 for (const OUString
& sTestFile
: aTestFiles
)
987 setTestFileName(sTestFile
);
988 loadFromFile(getTestFileName());
989 uno::Reference
< chart::XChartDocument
> xChartDoc(getChartDocFromSheet(0), UNO_QUERY_THROW
);
990 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier(xChartDoc
, uno::UNO_QUERY
);
991 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
992 uno::Reference
<drawing::XShapes
> xShapes(xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
993 CPPUNIT_ASSERT(xShapes
.is());
995 uno::Reference
< chart2::XChartDocument
> xChartDoc2(xChartDoc
, UNO_QUERY_THROW
);
996 Reference
<chart2::XChartType
> xChartType
= getChartTypeFromDoc(xChartDoc2
, 0);
997 CPPUNIT_ASSERT(xChartType
.is());
999 std::vector
<std::vector
<double> > aDataSeriesYValues
= getDataSeriesYValuesFromChartType(xChartType
);
1000 size_t nSeriesCount
= aDataSeriesYValues
.size();
1001 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nSeriesCount
);
1003 for (size_t nSeries
= 0; nSeries
< nSeriesCount
; ++nSeries
)
1005 uno::Reference
<drawing::XShape
> xSeries
= getShapeByName(xShapes
, "CID/D=0:CS=0:CT=0:Series=" + OUString::number(nSeries
));
1006 CPPUNIT_ASSERT(xSeries
.is());
1007 CPPUNIT_DUMP_ASSERT_NOTE("Series " + OUString::number(nSeries
));
1009 uno::Reference
<container::XIndexAccess
> xIndexAccess(xSeries
, UNO_QUERY_THROW
);
1010 uno::Reference
<container::XIndexAccess
> xIndexAccess2(xIndexAccess
->getByIndex(0), UNO_QUERY_THROW
);
1011 uno::Reference
<drawing::XShape
> xLine(xIndexAccess2
->getByIndex(0), UNO_QUERY_THROW
);
1012 Reference
< beans::XPropertySet
> xPropSet(xLine
, UNO_QUERY_THROW
);
1014 // Check whether we have line
1015 drawing::LineStyle aSeriesLineStyle
;
1016 xPropSet
->getPropertyValue(UNO_NAME_LINESTYLE
) >>= aSeriesLineStyle
;
1017 if (aSeriesLineStyle
!= drawing::LineStyle_NONE
)
1019 CPPUNIT_DUMP_ASSERT_NOTE(u
"Lines are displayed"_ustr
);
1020 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aSeriesLineStyle
));
1022 // Check line shape geometry
1023 awt::Point aLinePosition
= xLine
->getPosition();
1024 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLinePosition
.X
, INT_EPS
);
1025 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLinePosition
.Y
, INT_EPS
);
1026 awt::Size aLineSize
= xLine
->getSize();
1027 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLineSize
.Height
, INT_EPS
);
1028 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aLineSize
.Width
, INT_EPS
);
1029 CPPUNIT_ASSERT(xPropSet
.is());
1030 drawing::HomogenMatrix3 aLineTransformation
;
1031 xPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aLineTransformation
;
1032 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aLineTransformation
, INT_EPS
);
1035 // Check points of series
1036 if (xIndexAccess
->getCount() >= 2)
1038 CPPUNIT_DUMP_ASSERT_NOTE(u
"Points are displayed"_ustr
);
1039 uno::Reference
<container::XIndexAccess
> xPointsOfSeries(xIndexAccess
->getByIndex(1), UNO_QUERY_THROW
);
1040 sal_Int32 nPointCountInSeries
= xPointsOfSeries
->getCount();
1041 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(nPointCountInSeries
);
1042 for (sal_Int32 nPoint
= 0; nPoint
< nPointCountInSeries
; ++nPoint
)
1044 uno::Reference
<container::XIndexAccess
> XPointContainer (
1045 getShapeByName(xShapes
, "CID/MultiClick/D=0:CS=0:CT=0:Series=" + OUString::number(nSeries
) + ":Point=" + OUString::number(nPoint
)), UNO_QUERY_THROW
);
1046 uno::Reference
<drawing::XShape
> XPoint(XPointContainer
->getByIndex(0), UNO_QUERY_THROW
);
1047 uno::Reference
<container::XNamed
> xNamedShape(XPointContainer
, uno::UNO_QUERY
);
1048 CPPUNIT_DUMP_ASSERT_NOTE(xNamedShape
->getName());
1050 // Check size and position
1051 awt::Point aPointPosition
= XPoint
->getPosition();
1052 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aPointPosition
.X
, INT_EPS
);
1053 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aPointPosition
.Y
, INT_EPS
);
1054 awt::Size aPointSize
= XPoint
->getSize();
1055 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aPointSize
.Height
, INT_EPS
);
1056 CPPUNIT_DUMP_ASSERT_DOUBLES_EQUAL(aPointSize
.Width
, INT_EPS
);
1058 // Check transformation
1059 Reference
< beans::XPropertySet
> xPointPropSet(XPoint
, UNO_QUERY_THROW
);
1060 drawing::HomogenMatrix3 aPointTransformation
;
1061 xPointPropSet
->getPropertyValue(u
"Transformation"_ustr
) >>= aPointTransformation
;
1062 CPPUNIT_DUMP_ASSERT_TRANSFORMATIONS_EQUAL(aPointTransformation
, INT_EPS
);
1064 // Check fill style and color
1065 drawing::FillStyle aPointFillStyle
;
1066 xPointPropSet
->getPropertyValue(UNO_NAME_FILLSTYLE
) >>= aPointFillStyle
;
1067 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aPointFillStyle
));
1068 util::Color aPointFillColor
= 0;
1069 xPointPropSet
->getPropertyValue(UNO_NAME_FILLCOLOR
) >>= aPointFillColor
;
1070 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL(static_cast<sal_Int32
>(aPointFillColor
));
1077 DECLARE_DUMP_TEST( PivotChartDataButtonTest
, Chart2DumpTest
, false )
1079 setTestFileName( u
"pivotchart_data_button.ods"_ustr
);
1080 loadFromFile(getTestFileName());
1082 // Check that we have pivot chart in the document
1083 uno::Reference
<table::XTablePivotCharts
> xTablePivotCharts
= getTablePivotChartsFromSheet( 1);
1084 uno::Reference
<container::XIndexAccess
> xIndexAccess( xTablePivotCharts
, UNO_QUERY_THROW
);
1085 CPPUNIT_ASSERT_EQUAL( sal_Int32(1), xIndexAccess
->getCount() );
1087 // Get the pivot chart document so we ca access its data
1088 uno::Reference
<chart2::XChartDocument
> xChartDoc
;
1089 xChartDoc
.set( getPivotChartDocFromSheet( xTablePivotCharts
, 0 ) );
1090 CPPUNIT_ASSERT( xChartDoc
.is() );
1092 uno::Reference
<drawing::XDrawPageSupplier
> xDrawPageSupplier( xChartDoc
, uno::UNO_QUERY
);
1093 uno::Reference
<drawing::XDrawPage
> xDrawPage
= xDrawPageSupplier
->getDrawPage();
1094 uno::Reference
<drawing::XShapes
> xShapes( xDrawPage
->getByIndex(0), uno::UNO_QUERY
);
1095 CPPUNIT_ASSERT( xShapes
.is() );
1097 // Get the shape that represents the "Data" button.
1098 uno::Reference
<drawing::XShape
> xButton
= getShapeByName( xShapes
, u
"FieldButton.Row.8"_ustr
,
1099 []( const uno::Reference
<drawing::XShape
>& xShapeNode
)
1101 return xShapeNode
->getShapeType() == "com.sun.star.drawing.TextShape";
1103 CPPUNIT_ASSERT_MESSAGE( "Cannot find Data button shape", xButton
.is() );
1105 // Make sure that there is no arrow shape with the Data button
1106 uno::Reference
<drawing::XShape
> xArrow
= getShapeByName( xShapes
, u
"FieldButton.Row.8"_ustr
,
1107 []( const uno::Reference
<drawing::XShape
>& xShapeNode
)
1109 return xShapeNode
->getShapeType() == "com.sun.star.drawing.PolyPolygonShape";
1111 CPPUNIT_ASSERT_MESSAGE( "Arrow shape should not be present for the Data button", !xArrow
.is() );
1113 // Assert the background color of the Data button
1114 util::Color aButtonFillColor
= 0;
1115 uno::Reference
<beans::XPropertySet
> xPropSet( xButton
, UNO_QUERY_THROW
);
1116 xPropSet
->getPropertyValue( UNO_NAME_FILLCOLOR
) >>= aButtonFillColor
;
1117 CPPUNIT_DUMP_ASSERT_NUMBERS_EQUAL( static_cast<sal_Int32
>( aButtonFillColor
) );
1120 CPPUNIT_PLUGIN_IMPLEMENT();
1122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */