/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// test that y error bars are there
Reference< beans::XPropertySet > xErrorBarYProps;
xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
testErrorBar(xErrorBarYProps);
}
// test that y error bars are there
Reference< beans::XPropertySet > xErrorBarYProps;
xPropSet->getPropertyValue(CHART_UNONAME_ERRORBAR_Y) >>= xErrorBarYProps;
testErrorBar(xErrorBarYProps);
}
}
// test y error bars property
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:errDir", "val", u"y");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:spPr/a:ln", "w", u"12600");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[1]/c:spPr/a:ln/a:solidFill/a:srgbClr", "val", u"ff0000");
// test x error bars property
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:errDir", "val", u"x");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:spPr/a:ln", "w", u"9360");
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:scatterChart/c:ser/c:errBars[2]/c:spPr/a:ln/a:solidFill/a:srgbClr", "val", u"595959");
}
// This method tests the preservation of properties for trendlines / regression curves // in an export -> import cycle using different file formats - ODS, XLS and XLSX.
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testTrendline)
{ // Validation fails with // Error: tag name "chart:symbol-image" is not allowed. Possible tag names are: <label-separator>
skipValidation();
loadFromFile(u"ods/trendline.ods");
checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
saveAndReload(u"calc8"_ustr);
checkTrendlinesInChart(getDataSeriesFromDoc( getChartDocFromSheet( 0), 0 ));
}
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testStockChart)
{ /* For attached file Stock_Chart.docx, in chart1.xml, * <c:stockChart>, there are four types of series as * Open,Low,High and Close. * For Open series, in <c:idx val="0" /> * an attribute val of index should start from 1 and not from 0. * Which was problem area.
*/
loadFromFile(u"docx/testStockChart.docx");
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testCrosses)
{ // test crosses val="autoZero" with DOCX
{
loadFromFile(u"docx/Bar_horizontal_cone.docx");
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:crosses", "val", u"autoZero");
} // tdf#142351: test crossesAt val="-50" with XLSX
{
loadFromFile(u"xlsx/tdf142351.xlsx");
save(u"Calc Office Open XML"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"xl/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// Test the export.
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:externalData");
}
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testEmbeddingsGrabBag)
{ // The problem was that .xlsx files were missing from docx file from embeddings folder // after saving file. // This test case tests whether embeddings files grabbagged properly in correct object.
loadFromFile(u"docx/testMultiplechartembeddings.docx" );
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aGrabBag(0);
xTextDocumentPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBag;
CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty bool bEmbeddings = false; constchar* const testEmbeddedFileNames[] {"word/embeddings/Microsoft_Excel_Worksheet3.xlsx", "word/embeddings/Microsoft_Excel_Worksheet2.xlsx", "word/embeddings/Microsoft_Excel_Worksheet1.xlsx"}; for (beans::PropertyValue const& prop : aGrabBag)
{ if (prop.Name == "OOXEmbeddings")
{
bEmbeddings = true;
uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
OUString aEmbeddedfileName;
CPPUNIT_ASSERT(prop.Value >>= aEmbeddingsList); // PropertyValue of proper type
sal_Int32 length = aEmbeddingsList.getLength();
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), length); for(int j = 0; j < length; ++j)
{
aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
aEmbeddedfileName = aEmbeddingsList[j].Name;
CPPUNIT_ASSERT(aEmbeddingXlsxStream); // Reference not empty
CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
}
}
}
CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
}
// FIXME: validation error in OOXML export: Errors: 9
skipValidation();
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:spPr/a:ln/a:noFill");
}
//The below test case tests the built in marker 'x' for Office 2010 in Line charts
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290LineChartMarkerX)
{
loadFromFile(u"docx/fdo78290_Line_Chart_Marker_x.docx");
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
}
// We can also use the built in marker 'x' in scatter chart, hence writing the test case for the same.
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290ScatterChartMarkerX)
{
loadFromFile(u"docx/fdo78290_Scatter_Chart_Marker_x.docx");
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:scatterChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
}
// Also in a combination of charts like a column chart and line chart, we can use the built in marker 'x' // for the line chart too. hence put a test case for the combination chart also.
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testFdo78290CombinationChartMarkerX)
{
loadFromFile(u"docx/fdo78290_Combination_Chart_Marker_x.docx");
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:symbol[1]","val",u"x");
assertXPath(pXmlDoc, "/c:chartSpace[1]/c:chart[1]/c:plotArea[1]/c:lineChart[1]/c:ser[1]/c:marker[1]/c:size[1]","val",u"7");
}
sal_Int32 nNumFmt = getNumberFormatFromAxis(xAxisX);
sal_Int16 nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("X axis should be percentage format.", (nType & util::NumberFormat::PERCENT));
bool bNumFmtLinked = false;
Reference<beans::XPropertySet> xPS(xAxisX, uno::UNO_QUERY_THROW);
xPS->getPropertyValue(u"LinkNumberFormatToSource"_ustr) >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("X axis should have its number format linked to source.", bNumFmtLinked);
nNumFmt = getNumberFormatFromAxis(xAxisY);
nType = getNumberFormatType(xChartDoc, nNumFmt);
CPPUNIT_ASSERT_MESSAGE("Y axis should be a normal number format.", (nType & util::NumberFormat::NUMBER));
bNumFmtLinked = true;
xPS.set(xAxisY, uno::UNO_QUERY_THROW);
xPS->getPropertyValue(u"LinkNumberFormatToSource"_ustr) >>= bNumFmtLinked;
CPPUNIT_ASSERT_MESSAGE("Y axis should not have its number format linked to source.", !bNumFmtLinked);
};
if ( bNumFmtLinkedActual )
CPPUNIT_ASSERT_MESSAGE( "Y axis should have its number format linked to source.", bNumFmtLinked ); else
{
CPPUNIT_ASSERT_MESSAGE( "Y axis should not have its number format linked to source.", !bNumFmtLinked );
sal_Int32 nNumFmt = getNumberFormatFromAxis( xAxisY );
sal_Int16 nType = getNumberFormatType( xChartDoc, nNumFmt ); if ( nNumFmtTypeFlag == util::NumberFormat::PERCENT )
CPPUNIT_ASSERT_MESSAGE( "Y axis should be percentage format.", ( nType & util::NumberFormat::PERCENT ) ); else
CPPUNIT_ASSERT_MESSAGE( "Y axis should be number format.", ( nType & util::NumberFormat::NUMBER ) );
}
};
// Write the document(xls) with changes made close it, load it and check if changes are intact
saveAndReload( u"MS Excel 97"_ustr );
xChartDoc = getChartDocFromSheet( 0 );
verify( xChartDoc, false, util::NumberFormat::NUMBER );
}
// Check to make sure that data points 0 and 2 have local properties.
Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
CPPUNIT_ASSERT(xPropSet.is());
Sequence<sal_Int32> aIndices;
xPropSet->getPropertyValue(u"AttributedDataPoints"_ustr) >>= aIndices; /* CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be 2 data points with local properties.", sal_Int32(2), aIndices.getLength()); CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aIndices[0]); CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aIndices[1]);
*/
for (size_t i = 0; i < std::size(aDataPoints); ++i)
{
xPropSet = xDataSeries->getDataPointByIndex(aDataPoints[i].mnIndex);
CPPUNIT_ASSERT(xPropSet.is());
Color nColor;
xPropSet->getPropertyValue(CHART_UNONAME_LABEL_BORDER_COLOR) >>= nColor; if (nShape == 0)
CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color is wrong.", aDataPoints[i].mnColor, nColor); else
CPPUNIT_ASSERT_EQUAL_MESSAGE("Border color should be green.", COL_LIGHTGREEN, nColor);
}
};
// "Automatic" chart background fill in docx should be loaded as solid white.
Reference<beans::XPropertySet> xPropSet = xChartDoc->getPageBackground();
CPPUNIT_ASSERT(xPropSet.is());
drawing::FillStyle eStyle = xPropSet->getPropertyValue(u"FillStyle"_ustr).get<drawing::FillStyle>();
sal_Int32 nColor = xPropSet->getPropertyValue(u"FillColor"_ustr).get<sal_Int32>();
CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid fill.",
drawing::FillStyle_SOLID, eStyle);
CPPUNIT_ASSERT_EQUAL_MESSAGE("'Automatic' chart background fill in docx should be loaded as solid white.",
sal_Int32(0x00FFFFFF), sal_Int32(nColor & 0x00FFFFFF)); // highest 2 bytes are transparency which we ignore here.
// Chart 1 has 4 bars of which 1st and 3rd have labels with borders around them.
verify(xChartDoc, 0);
xChartDoc.set(getChartDocFromWriter(1), uno::UNO_QUERY);
// Chart 2 has all its data labels with identical borders.
verify(xChartDoc, 1);
// FIXME: validation error in OOXML export: Errors: 3
skipValidation();
// FIXME: validation error in OOXML export: Errors: 1
skipValidation();
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// We must not export label position attributes for 3D bar charts. The // same rule also applies to several other 3D charts, apparently.
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLblPos", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
}
// FIXME: validation error in OOXML export: Errors: 9
skipValidation();
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// This was "t", should be one of the allowed values.
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLbl[2]/c:dLblPos", "val", u"outEnd");
}
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// We must not export label position attributes for radar charts.
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLblPos", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:radarChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
}
// FIXME: validation error in OOXML export: Errors: 1
skipValidation();
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// We must not export label position attributes for doughnut charts.
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLblPos", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:doughnutChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
}
// FIXME: validation error in OOXML export: Errors: 1
skipValidation();
save(u"Office Open XML Text"_ustr);
xmlDocUniquePtr pXmlDoc = parseExport(u"word/charts/chart1.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// We must not export label position attributes for area charts.
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLblPos", 0);
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:areaChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
}
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testDataLabelDefaultLineChartDOCX)
{ // This file was created by Word 2007, which doesn't provide default data // label position (2010 does). Make sure its default data label position // is RIGHT when exporting.
xChartDoc.set(getChartDocFromWriter(0), uno::UNO_QUERY);
Reference<chart2::XDataSeries> xDataSeries = getDataSeriesFromDoc(xChartDoc, 0);
Reference<beans::XPropertySet> xPropSet(xDataSeries, uno::UNO_QUERY);
CPPUNIT_ASSERT(xPropSet.is());
sal_Int32 nLabelPlacement = -1; if (xPropSet->getPropertyValue(u"LabelPlacement"_ustr) >>= nLabelPlacement) // This option may not be set. Check its value only when it's set.
CPPUNIT_ASSERT_EQUAL_MESSAGE("Line chart's default label placement should be 'right'.", chart::DataLabelPlacement::RIGHT, nLabelPlacement );
}
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testShapeFollowedByChart)
{ /* If there is a scenario where a chart is followed by a shape which is being exported as an alternate content then, the docPr Id is being repeated, ECMA 20.4.2.5 says that the docPr Id should be unique, ensuring the same here.
*/
loadFromFile(u"docx/FDO74430.docx");
// FIXME: validation error in OOXML export: Errors: 5
skipValidation();
save(u"Office Open XML Text"_ustr );
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
CPPUNIT_ASSERT(pXmlDoc);
// Make sure the original chart has 'a', 'b', 'c' as its data labels.
std::vector<uno::Sequence<uno::Any> > aLabels = getDataSeriesLabelsFromChartType(xCT);
CPPUNIT_ASSERT_EQUAL(size_t(3), aLabels.size());
CPPUNIT_ASSERT_EQUAL(u"a"_ustr, aLabels[0][0].get<OUString>());
CPPUNIT_ASSERT_EQUAL(u"b"_ustr, aLabels[1][0].get<OUString>());
CPPUNIT_ASSERT_EQUAL(u"c"_ustr, aLabels[2][0].get<OUString>());
// Reload the doc and check again. The labels should not change.
saveAndReload(u"writer8"_ustr);
CPPUNIT_TEST_FIXTURE(Chart2ExportTest, testEmbeddingsOleObjectGrabBag)
{ // The problem was that .bin files were missing from docx file from embeddings folder // after saving file. // This test case tests whether embeddings files grabbagged properly in correct object.
loadFromFile(u"docx/testchartoleobjectembeddings.docx" );
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xTextDocumentPropertySet(xTextDocument, uno::UNO_QUERY);
uno::Sequence<beans::PropertyValue> aGrabBag(0);
xTextDocumentPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aGrabBag;
CPPUNIT_ASSERT(aGrabBag.hasElements()); // Grab Bag not empty bool bEmbeddings = false; constchar* const testEmbeddedFileNames[] = {"word/embeddings/oleObject1.bin"}; for (beans::PropertyValue const& prop : aGrabBag)
{ if (prop.Name == "OOXEmbeddings")
{
bEmbeddings = true;
uno::Sequence<beans::PropertyValue> aEmbeddingsList(0);
uno::Reference<io::XInputStream> aEmbeddingXlsxStream;
OUString aEmbeddedfileName;
CPPUNIT_ASSERT(prop.Value >>= aEmbeddingsList); // PropertyValue of proper type
sal_Int32 length = aEmbeddingsList.getLength();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), length); for(int j = 0; j < length; ++j)
{
aEmbeddingsList[j].Value >>= aEmbeddingXlsxStream;
aEmbeddedfileName = aEmbeddingsList[j].Name;
CPPUNIT_ASSERT(aEmbeddingXlsxStream); // Reference not empty
CPPUNIT_ASSERT_EQUAL(OUString::createFromAscii(testEmbeddedFileNames[j]),aEmbeddedfileName);
}
}
}
CPPUNIT_ASSERT(bEmbeddings); // Grab Bag has all the expected elements
}
// test the overlap value of a simple Stacked Column Chart
uno::Reference< chart2::XChartDocument > xChartDoc = getChartDocFromSheet( 0);
checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 0);
// test the overlap value of a Percent Stacked Bar Chart
xChartDoc = getChartDocFromSheet( 1);
checkSheetForGapWidthAndOverlap(getChartTypeFromDoc( xChartDoc, 0 ), 100, 35);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.