/* -*- 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/.
*/
#include"charttest.hxx"
#include <comphelper/propertyvalue.hxx>
usingnamespace ::com::sun::star;
class Chart2UiChartTest : public ChartTest
{ public:
Chart2UiChartTest()
: ChartTest(u"/chart2/qa/extras/data/"_ustr)
{
}
uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", nColumns,
aExpectedColumnDescriptions.getLength());
uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", nRows,
aExpectedRowDescriptions.getLength());
Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in destination file", nColumns,
aColumnDesc.getLength()); for (sal_Int32 i = 0; i < nColumns; ++i)
{
OString sMessage("Incorrect description in column: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
aColumnDesc[i]);
}
Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in destination file", nRows,
aRowDesc.getLength()); for (sal_Int32 i = 0; i < nRows; ++i)
{
OString sMessage("Incorrect description in row: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i], aRowDesc[i]);
}
uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", nColumns,
aExpectedColumnDescriptions.getLength());
uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", nRows,
aExpectedRowDescriptions.getLength());
Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in destination file", nColumns,
aColumnDesc.getLength()); for (sal_Int32 i = 0; i < nColumns; ++i)
{ // Without the fix in place, this test would have failed with // - Expected: ABC // - Actual : // - Incorrect description in column: 0
OString sMessage("Incorrect description in column: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
aColumnDesc[i]);
}
Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in destination file", nRows,
aRowDesc.getLength()); for (sal_Int32 i = 0; i < nRows; ++i)
{
OString sMessage("Incorrect description in row: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i], aRowDesc[i]);
}
// Without the fix in place, this test would have failed with // - Expected: 0 // - Actual : 3.33625955201419 // - Incorrect value in Col: 2 Row: 51
testCopyPasteToNewSheet(xChartDoc, u"Object 2"_ustr, 4, 158);
}
// Without the fix in place, this test would have failed with // - Expected: 5 // - Actual : 1
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aSeriesList.getLength());
for (size_t i = 0; i < 5; ++i)
CPPUNIT_ASSERT_EQUAL(aExpected[i], aSeriesList[i]);
}
// Without the fix in place, this test would have failed with // - Expected: Test 1 1 // - Actual : Test 1 // - Incorrect description in row: 0
testCopyPasteToNewSheet(xChartDoc2, u"Object 2"_ustr, 3, 9);
}
// Without the fix in place, this test would have failed with // - Expected: 2 // - Actual : 7 // - Incorrect number of columns in destination file
testCopyPasteToNewSheet(xChartDoc, u"Object 1"_ustr, 2, 6);
}
// Without the fix in place, this test would have failed with // - Expected: 12 // - Actual : 0
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12), aSeriesList2.getLength());
}
uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", static_cast<sal_Int32>(12),
aExpectedColumnDescriptions.getLength());
uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", static_cast<sal_Int32>(8), aExpectedRowDescriptions.getLength());
// Create a copy of the sheet and move to the end
uno::Sequence<beans::PropertyValue> aArgs(
comphelper::InitPropertySequence({ { "DocName", uno::Any(u"tdf101894"_ustr) },
{ "Index", uno::Any(sal_uInt16(32767)) },
{ "Copy", uno::Any(true) } }));
dispatchCommand(mxComponent, u".uno:Move"_ustr, aArgs);
uno::Sequence<OUString> aColumnDescriptions = xChartData2->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", static_cast<sal_Int32>(12), aColumnDescriptions.getLength()); for (sal_Int32 i = 0; i < 12; ++i)
{
OString sMessage("Incorrect description in column: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
aColumnDescriptions[i]);
}
uno::Sequence<OUString> aRowDescriptions = xChartData2->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", static_cast<sal_Int32>(8), aRowDescriptions.getLength()); for (sal_Int32 i = 0; i < 8; ++i)
{
OString sMessage("Incorrect description in row: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i],
aRowDescriptions[i]);
}
// Without the fix in place, this test would have failed with // - Expected: 1 // - Actual : 2.2250738585072e-308 // - Incorrect value in Col: 0 Row: 0
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1);
}
}
}
}
uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", static_cast<sal_Int32>(4),
aExpectedColumnDescriptions.getLength());
uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", static_cast<sal_Int32>(7), aExpectedRowDescriptions.getLength());
uno::Sequence<OUString> aColumnDescriptions = xChartData2->getColumnDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", static_cast<sal_Int32>(4), aColumnDescriptions.getLength()); for (sal_Int32 i = 0; i < 4; ++i)
{
OString sMessage("Incorrect description in column: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
aColumnDescriptions[i]);
}
uno::Sequence<OUString> aRowDescriptions = xChartData2->getRowDescriptions();
CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", static_cast<sal_Int32>(7), aRowDescriptions.getLength()); for (sal_Int32 i = 0; i < 7; ++i)
{
OString sMessage("Incorrect description in row: " + OString::number(i));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i],
aRowDescriptions[i]);
}
// Without the fix in place, this test would have failed with // - Expected: $Tabelle2.$A$2:$A$11 // - Actual : $Tabelle2.$A$2:$Tabelle1.$A$11
CPPUNIT_ASSERT_EQUAL(sExpectedValuesX, xValuesX->getSourceRangeRepresentation());
Reference<chart2::data::XDataSequence> xValuesY
= getDataSequenceFromDocByRole(xChartDoc, u"values-y");
CPPUNIT_ASSERT_EQUAL(sExpectedValuesY, xValuesY->getSourceRangeRepresentation());
}
}
CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf153706)
{ // Load a spreadsheet with a to-page XY scatter chart with the sheet as data source
loadFromFile(u"ods/tdf153706_XY_scatter_chart.ods");
// Select the cell range around the chart, and copy the range to clipboard, including the chart
dispatchCommand(mxComponent, u".uno:GoToCell"_ustr,
{ comphelper::makePropertyValue(u"ToPoint"_ustr, u"D1:K23"_ustr) });
dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
// create a new document
loadFromURL(u"private:factory/scalc"_ustr);
// Paste; this must create a chart with own data source having a proper copy of the data
dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
css::uno::Reference xChartDoc(getChartDocFromSheet(0), css::uno::UNO_SET_THROW); auto xDataArray(xChartDoc->getDataProvider().queryThrow<chart::XChartDataArray>());
// Without the fix, this would fail with // - Expected: 1 // - Actual : 2 // i.e., the X values were treated as another Y series
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
auto xSeries(getDataSeriesFromDoc(xChartDoc, 0).queryThrow<chart2::data::XDataSource>()); auto sequences = xSeries->getDataSequences(); // Without the fix, this would fail with // - Expected: 2 // - Actual : 1
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), sequences.getLength());
auto propX(sequences[0]->getValues().queryThrow<beans::XPropertySet>()); // Without the fix, this would fail with // - Expected: values-x // - Actual : values-y
CPPUNIT_ASSERT_EQUAL(u"values-x"_ustr, propX->getPropertyValue(u"Role"_ustr).get<OUString>());
auto propY(sequences[1]->getValues().queryThrow<beans::XPropertySet>());
CPPUNIT_ASSERT_EQUAL(u"values-y"_ustr, propY->getPropertyValue(u"Role"_ustr).get<OUString>());
}
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.