Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / chart2 / qa / extras / uichart.cxx
blobe17d0e6daa20c81339fb48bf1bb5234de588bc15
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include "charttest.hxx"
12 #include <comphelper/propertyvalue.hxx>
14 using namespace ::com::sun::star;
16 class Chart2UiChartTest : public ChartTest
18 public:
19 Chart2UiChartTest()
20 : ChartTest(u"/chart2/qa/extras/data/"_ustr)
24 void testCopyPasteToNewSheet(const uno::Reference<chart::XChartDocument>& xChartDoc,
25 OUString aObjectName, sal_Int32 nColumns, sal_Int32 nRows);
28 void Chart2UiChartTest::testCopyPasteToNewSheet(
29 const uno::Reference<chart::XChartDocument>& xChartDoc, OUString aObjectName,
30 sal_Int32 nColumns, sal_Int32 nRows)
32 CPPUNIT_ASSERT(xChartDoc.is());
33 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
35 uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
36 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", nColumns,
37 aExpectedColumnDescriptions.getLength());
39 uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
40 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", nRows,
41 aExpectedRowDescriptions.getLength());
43 Sequence<Sequence<double>> aExpectedData = xChartData->getData();
45 uno::Sequence<beans::PropertyValue> aPropertyValues = {
46 comphelper::makePropertyValue(u"ToObject"_ustr, aObjectName),
48 dispatchCommand(mxComponent, u".uno:GoToObject"_ustr, aPropertyValues);
50 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
52 // create a new document
53 loadFromURL(u"private:factory/scalc"_ustr);
55 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
57 uno::Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(0);
58 CPPUNIT_ASSERT(xChartDoc2.is());
60 uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc2->getDataProvider(),
61 UNO_QUERY_THROW);
63 Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions();
64 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in destination file", nColumns,
65 aColumnDesc.getLength());
66 for (sal_Int32 i = 0; i < nColumns; ++i)
68 OString sMessage("Incorrect description in column: " + OString::number(i));
69 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
70 aColumnDesc[i]);
73 Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions();
74 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in destination file", nRows,
75 aRowDesc.getLength());
76 for (sal_Int32 i = 0; i < nRows; ++i)
78 OString sMessage("Incorrect description in row: " + OString::number(i));
79 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i], aRowDesc[i]);
82 Sequence<Sequence<double>> aData = xDataArray->getData();
84 for (sal_Int32 nRowIdx = 0; nRowIdx < nRows; ++nRowIdx)
86 for (sal_Int32 nColIdx = 0; nColIdx < nColumns; ++nColIdx)
88 double nValue = aData[nRowIdx][nColIdx];
89 double nExpected = aExpectedData[nRowIdx][nColIdx];
90 OString sMessage("Incorrect value in Col: " + OString::number(nColIdx)
91 + " Row: " + OString::number(nRowIdx));
93 if (std::isnan(nValue))
95 // On paste, 0 becomes NaN, check whether it's expected
96 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), 0.0, nExpected, 1e-1);
98 else
100 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1);
106 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf99969)
108 loadFromFile(u"ods/tdf99969.ods");
109 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
110 uno::UNO_QUERY_THROW);
111 sal_Int32 nColumns = 2;
112 sal_Int32 nRows = 6;
113 CPPUNIT_ASSERT(xChartDoc.is());
114 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
116 uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
117 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file", nColumns,
118 aExpectedColumnDescriptions.getLength());
120 uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file", nRows,
122 aExpectedRowDescriptions.getLength());
124 Sequence<Sequence<double>> aExpectedData = xChartData->getData();
126 dispatchCommand(mxComponent, u".uno:GoToCell"_ustr,
127 { comphelper::makePropertyValue(u"ToPoint"_ustr, uno::Any(u"C2:L25"_ustr)) });
129 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
131 // create a new document
132 loadFromURL(u"private:factory/scalc"_ustr);
134 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
136 uno::Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(0);
137 CPPUNIT_ASSERT(xChartDoc2.is());
139 uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc2->getDataProvider(),
140 UNO_QUERY_THROW);
142 Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions();
143 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in destination file", nColumns,
144 aColumnDesc.getLength());
145 for (sal_Int32 i = 0; i < nColumns; ++i)
147 // Without the fix in place, this test would have failed with
148 // - Expected: ABC
149 // - Actual :
150 // - Incorrect description in column: 0
151 OString sMessage("Incorrect description in column: " + OString::number(i));
152 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
153 aColumnDesc[i]);
156 Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions();
157 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in destination file", nRows,
158 aRowDesc.getLength());
159 for (sal_Int32 i = 0; i < nRows; ++i)
161 OString sMessage("Incorrect description in row: " + OString::number(i));
162 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i], aRowDesc[i]);
165 Sequence<Sequence<double>> aData = xDataArray->getData();
167 for (sal_Int32 nRowIdx = 0; nRowIdx < nRows; ++nRowIdx)
169 for (sal_Int32 nColIdx = 0; nColIdx < nColumns; ++nColIdx)
171 double nValue = aData[nRowIdx][nColIdx];
172 double nExpected = aExpectedData[nRowIdx][nColIdx];
173 OString sMessage("Incorrect value in Col: " + OString::number(nColIdx)
174 + " Row: " + OString::number(nRowIdx));
176 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue);
181 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf120348)
183 loadFromFile(u"ods/tdf120348.ods");
184 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
185 uno::UNO_QUERY_THROW);
187 // Without the fix in place, this test would have failed with
188 // - Expected: 0
189 // - Actual : 3.33625955201419
190 // - Incorrect value in Col: 2 Row: 51
191 testCopyPasteToNewSheet(xChartDoc, u"Object 2"_ustr, 4, 158);
194 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf151091)
196 std::vector<OUString> aExpected
197 = { u"Ωφέλιμο"_ustr, u"Επικίνδυνο"_ustr, u"Απόσταση"_ustr, u"Μάσκα"_ustr, u"Εμβόλιο"_ustr };
199 loadFromFile(u"ods/tdf151091.ods");
200 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
201 uno::UNO_QUERY_THROW);
202 CPPUNIT_ASSERT(xChartDoc.is());
203 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
204 uno::Sequence<OUString> aSeriesList = xChartData->getColumnDescriptions();
205 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aSeriesList.getLength());
207 for (size_t i = 0; i < 5; ++i)
208 CPPUNIT_ASSERT_EQUAL(aExpected[i], aSeriesList[i]);
210 uno::Sequence<beans::PropertyValue> aPropertyValues = {
211 comphelper::makePropertyValue(u"ToObject"_ustr, u"Object 1"_ustr),
213 dispatchCommand(mxComponent, u".uno:GoToObject"_ustr, aPropertyValues);
215 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
217 // create a new writer document
218 loadFromURL(u"private:factory/swriter"_ustr);
220 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
222 aSeriesList = getWriterChartColumnDescriptions();
224 // Without the fix in place, this test would have failed with
225 // - Expected: 5
226 // - Actual : 1
227 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5), aSeriesList.getLength());
229 for (size_t i = 0; i < 5; ++i)
230 CPPUNIT_ASSERT_EQUAL(aExpected[i], aSeriesList[i]);
233 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf107097)
235 loadFromFile(u"ods/tdf107097.ods");
236 uno::Reference<chart::XChartDocument> xChartDoc(getPivotChartDocFromSheet(1),
237 uno::UNO_QUERY_THROW);
238 testCopyPasteToNewSheet(xChartDoc, u"Object 1"_ustr, 4, 12);
241 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf136011)
243 loadFromFile(u"ods/tdf136011.ods");
244 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
245 uno::UNO_QUERY_THROW);
246 testCopyPasteToNewSheet(xChartDoc, u"Object 1"_ustr, 3, 9);
248 loadFromFile(u"ods/tdf136011.ods");
249 uno::Reference<chart::XChartDocument> xChartDoc2(getChartCompFromSheet(0, 1),
250 uno::UNO_QUERY_THROW);
252 // Without the fix in place, this test would have failed with
253 // - Expected: Test 1 1
254 // - Actual : Test 1
255 // - Incorrect description in row: 0
256 testCopyPasteToNewSheet(xChartDoc2, u"Object 2"_ustr, 3, 9);
259 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf62057)
261 loadFromFile(u"ods/tdf62057.ods");
262 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
263 uno::UNO_QUERY_THROW);
265 // Without the fix in place, this test would have failed with
266 // - Expected: 2
267 // - Actual : 7
268 // - Incorrect number of columns in destination file
269 testCopyPasteToNewSheet(xChartDoc, u"Object 1"_ustr, 2, 6);
272 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf98690)
274 loadFromFile(u"xlsx/tdf98690.xlsx");
275 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
276 uno::UNO_QUERY_THROW);
278 CPPUNIT_ASSERT(xChartDoc.is());
279 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
280 uno::Sequence<OUString> aSeriesList = xChartData->getColumnDescriptions();
281 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), aSeriesList.getLength());
283 uno::Sequence<beans::PropertyValue> aPropertyValues = {
284 comphelper::makePropertyValue(u"ToObject"_ustr, u"Chart 2"_ustr),
286 dispatchCommand(mxComponent, u".uno:GoToObject"_ustr, aPropertyValues);
288 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
290 // create a new document
291 loadFromURL(u"private:factory/scalc"_ustr);
293 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
295 uno::Reference<chart::XChartDocument> xChartDoc2(getChartCompFromSheet(0, 0),
296 uno::UNO_QUERY_THROW);
297 CPPUNIT_ASSERT(xChartDoc2.is());
298 uno::Reference<chart::XChartDataArray> xChartData2(xChartDoc2->getData(), uno::UNO_QUERY_THROW);
299 uno::Sequence<OUString> aSeriesList2 = xChartData2->getColumnDescriptions();
301 // Without the fix in place, this test would have failed with
302 // - Expected: 12
303 // - Actual : 0
304 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12), aSeriesList2.getLength());
307 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf101894)
309 loadFromFile(u"ods/tdf101894.ods");
310 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
311 uno::UNO_QUERY_THROW);
313 CPPUNIT_ASSERT(xChartDoc.is());
314 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
316 uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
317 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file",
318 static_cast<sal_Int32>(12),
319 aExpectedColumnDescriptions.getLength());
321 uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
322 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file",
323 static_cast<sal_Int32>(8), aExpectedRowDescriptions.getLength());
325 Sequence<Sequence<double>> aExpectedData = xChartData->getData();
327 // Create a copy of the sheet and move to the end
328 uno::Sequence<beans::PropertyValue> aArgs(
329 comphelper::InitPropertySequence({ { "DocName", uno::Any(u"tdf101894"_ustr) },
330 { "Index", uno::Any(sal_uInt16(32767)) },
331 { "Copy", uno::Any(true) } }));
332 dispatchCommand(mxComponent, u".uno:Move"_ustr, aArgs);
334 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
335 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
336 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xIA->getCount());
338 for (sal_Int32 sheetIndex = 0; sheetIndex < 2; ++sheetIndex)
340 uno::Reference<chart::XChartDocument> xChartDoc2(getChartCompFromSheet(sheetIndex, 0),
341 uno::UNO_QUERY_THROW);
342 CPPUNIT_ASSERT(xChartDoc2.is());
343 uno::Reference<chart::XChartDataArray> xChartData2(xChartDoc2->getData(),
344 uno::UNO_QUERY_THROW);
346 uno::Sequence<OUString> aColumnDescriptions = xChartData2->getColumnDescriptions();
347 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file",
348 static_cast<sal_Int32>(12), aColumnDescriptions.getLength());
349 for (sal_Int32 i = 0; i < 12; ++i)
351 OString sMessage("Incorrect description in column: " + OString::number(i));
352 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
353 aColumnDescriptions[i]);
356 uno::Sequence<OUString> aRowDescriptions = xChartData2->getRowDescriptions();
357 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file",
358 static_cast<sal_Int32>(8), aRowDescriptions.getLength());
359 for (sal_Int32 i = 0; i < 8; ++i)
361 OString sMessage("Incorrect description in row: " + OString::number(i));
362 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i],
363 aRowDescriptions[i]);
366 Sequence<Sequence<double>> aData = xChartData2->getData();
368 for (sal_Int32 nRowIdx = 0; nRowIdx < 8; ++nRowIdx)
370 for (sal_Int32 nColIdx = 0; nColIdx < 12; ++nColIdx)
372 double nValue = aData[nRowIdx][nColIdx];
373 double nExpected = aExpectedData[nRowIdx][nColIdx];
374 OString sMessage("Incorrect value in Col: " + OString::number(nColIdx)
375 + " Row: " + OString::number(nRowIdx));
377 // Without the fix in place, this test would have failed with
378 // - Expected: 1
379 // - Actual : 2.2250738585072e-308
380 // - Incorrect value in Col: 0 Row: 0
381 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1);
387 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testCopyPasteChartWithDotInSheetName)
389 loadFromFile(u"ods/chartWithDotInSheetName.ods");
390 uno::Reference<chart::XChartDocument> xChartDoc(getChartCompFromSheet(0, 0),
391 uno::UNO_QUERY_THROW);
393 CPPUNIT_ASSERT(xChartDoc.is());
394 uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), uno::UNO_QUERY_THROW);
396 uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions();
397 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file",
398 static_cast<sal_Int32>(4),
399 aExpectedColumnDescriptions.getLength());
401 uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions();
402 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file",
403 static_cast<sal_Int32>(7), aExpectedRowDescriptions.getLength());
405 Sequence<Sequence<double>> aExpectedData = xChartData->getData();
407 dispatchCommand(mxComponent, u".uno:SelectAll"_ustr, {});
408 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
410 uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
411 { { "Name", uno::Any(u"NewTab"_ustr) }, { "Index", uno::Any(sal_uInt16(2)) } }));
412 dispatchCommand(mxComponent, u".uno:Insert"_ustr, aArgs);
414 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
415 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
416 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xIA->getCount());
418 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
420 for (sal_Int32 sheetIndex = 0; sheetIndex < 2; ++sheetIndex)
422 uno::Reference<chart::XChartDocument> xChartDoc2(getChartCompFromSheet(sheetIndex, 0),
423 uno::UNO_QUERY_THROW);
424 CPPUNIT_ASSERT(xChartDoc2.is());
425 uno::Reference<chart::XChartDataArray> xChartData2(xChartDoc2->getData(),
426 uno::UNO_QUERY_THROW);
428 uno::Sequence<OUString> aColumnDescriptions = xChartData2->getColumnDescriptions();
429 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of columns in origin file",
430 static_cast<sal_Int32>(4), aColumnDescriptions.getLength());
431 for (sal_Int32 i = 0; i < 4; ++i)
433 OString sMessage("Incorrect description in column: " + OString::number(i));
434 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedColumnDescriptions[i],
435 aColumnDescriptions[i]);
438 uno::Sequence<OUString> aRowDescriptions = xChartData2->getRowDescriptions();
439 CPPUNIT_ASSERT_EQUAL_MESSAGE("Incorrect number of rows in origin file",
440 static_cast<sal_Int32>(7), aRowDescriptions.getLength());
441 for (sal_Int32 i = 0; i < 7; ++i)
443 OString sMessage("Incorrect description in row: " + OString::number(i));
444 CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), aExpectedRowDescriptions[i],
445 aRowDescriptions[i]);
448 Sequence<Sequence<double>> aData = xChartData2->getData();
450 for (sal_Int32 nRowIdx = 0; nRowIdx < 7; ++nRowIdx)
452 for (sal_Int32 nColIdx = 0; nColIdx < 4; ++nColIdx)
454 double nValue = aData[nRowIdx][nColIdx];
455 double nExpected = aExpectedData[nRowIdx][nColIdx];
456 OString sMessage("Incorrect value in Col: " + OString::number(nColIdx)
457 + " Row: " + OString::number(nRowIdx));
459 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1);
465 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf158223)
467 loadFromFile(u"ods/tdf158223.ods");
469 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
470 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
471 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xIA->getCount());
473 for (sal_Int32 sheetIndex = 0; sheetIndex < 2; ++sheetIndex)
475 OUString sExpectedValuesX("$Tabelle" + OUString::number(sheetIndex + 1) + ".$A$2:$A$11");
476 OUString sExpectedValuesY("$Tabelle" + OUString::number(sheetIndex + 1) + ".$B$2:$B$11");
477 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(sheetIndex);
478 Reference<chart2::data::XDataSequence> xValuesX
479 = getDataSequenceFromDocByRole(xChartDoc, u"values-x");
480 CPPUNIT_ASSERT_EQUAL(sExpectedValuesX, xValuesX->getSourceRangeRepresentation());
481 Reference<chart2::data::XDataSequence> xValuesY
482 = getDataSequenceFromDocByRole(xChartDoc, u"values-y");
483 CPPUNIT_ASSERT_EQUAL(sExpectedValuesY, xValuesY->getSourceRangeRepresentation());
486 // Remove last sheet
487 uno::Sequence<beans::PropertyValue> aArgs(
488 comphelper::InitPropertySequence({ { "Index", uno::Any(sal_uInt16(3)) } }));
489 dispatchCommand(mxComponent, u".uno:Remove"_ustr, aArgs);
491 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xIA->getCount());
493 for (sal_Int32 sheetIndex = 0; sheetIndex < 2; ++sheetIndex)
495 OUString sExpectedValuesX("$Tabelle" + OUString::number(sheetIndex + 1) + ".$A$2:$A$11");
496 OUString sExpectedValuesY("$Tabelle" + OUString::number(sheetIndex + 1) + ".$B$2:$B$11");
497 uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(sheetIndex);
498 Reference<chart2::data::XDataSequence> xValuesX
499 = getDataSequenceFromDocByRole(xChartDoc, u"values-x");
501 // Without the fix in place, this test would have failed with
502 // - Expected: $Tabelle2.$A$2:$A$11
503 // - Actual : $Tabelle2.$A$2:$Tabelle1.$A$11
504 CPPUNIT_ASSERT_EQUAL(sExpectedValuesX, xValuesX->getSourceRangeRepresentation());
505 Reference<chart2::data::XDataSequence> xValuesY
506 = getDataSequenceFromDocByRole(xChartDoc, u"values-y");
507 CPPUNIT_ASSERT_EQUAL(sExpectedValuesY, xValuesY->getSourceRangeRepresentation());
511 CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf153706)
513 // Load a spreadsheet with a to-page XY scatter chart with the sheet as data source
514 loadFromFile(u"ods/tdf153706_XY_scatter_chart.ods");
516 // Select the cell range around the chart, and copy the range to clipboard, including the chart
517 dispatchCommand(mxComponent, u".uno:GoToCell"_ustr,
518 { comphelper::makePropertyValue(u"ToPoint"_ustr, u"D1:K23"_ustr) });
519 dispatchCommand(mxComponent, u".uno:Copy"_ustr, {});
521 // create a new document
522 loadFromURL(u"private:factory/scalc"_ustr);
524 // Paste; this must create a chart with own data source having a proper copy of the data
525 dispatchCommand(mxComponent, u".uno:Paste"_ustr, {});
527 css::uno::Reference xChartDoc(getChartDocFromSheet(0), css::uno::UNO_SET_THROW);
528 auto xDataArray(xChartDoc->getDataProvider().queryThrow<chart::XChartDataArray>());
530 css::uno::Sequence<Sequence<double>> aData = xDataArray->getData();
531 CPPUNIT_ASSERT_EQUAL(sal_Int32(3), aData.getLength());
532 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aData[0].getLength());
533 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aData[1].getLength());
534 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), aData[2].getLength());
535 CPPUNIT_ASSERT_EQUAL(2.0, aData[0][0]);
536 CPPUNIT_ASSERT_EQUAL(3.0, aData[0][1]);
537 CPPUNIT_ASSERT_EQUAL(3.0, aData[1][0]);
538 CPPUNIT_ASSERT_EQUAL(2.0, aData[1][1]);
539 CPPUNIT_ASSERT_EQUAL(4.0, aData[2][0]);
540 CPPUNIT_ASSERT_EQUAL(1.0, aData[2][1]);
542 // Without the fix, this would fail with
543 // - Expected: 1
544 // - Actual : 2
545 // i.e., the X values were treated as another Y series
546 CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
548 auto xSeries(getDataSeriesFromDoc(xChartDoc, 0).queryThrow<chart2::data::XDataSource>());
549 auto sequences = xSeries->getDataSequences();
550 // Without the fix, this would fail with
551 // - Expected: 2
552 // - Actual : 1
553 CPPUNIT_ASSERT_EQUAL(sal_Int32(2), sequences.getLength());
555 auto propX(sequences[0]->getValues().queryThrow<beans::XPropertySet>());
556 // Without the fix, this would fail with
557 // - Expected: values-x
558 // - Actual : values-y
559 CPPUNIT_ASSERT_EQUAL(u"values-x"_ustr, propX->getPropertyValue(u"Role"_ustr).get<OUString>());
561 auto propY(sequences[1]->getValues().queryThrow<beans::XPropertySet>());
562 CPPUNIT_ASSERT_EQUAL(u"values-y"_ustr, propY->getPropertyValue(u"Role"_ustr).get<OUString>());
565 CPPUNIT_PLUGIN_IMPLEMENT();
567 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */