chart2/qa/extras/uichart.cxx | 72 +++++++++++++++++++++++++++++++++++++++ sc/qa/uitest/chart2/tdf136011.py | 51 --------------------------- 2 files changed, 72 insertions(+), 51 deletions(-)
New commits: commit 8e3258f7d62ec154f2d80af2f39028a4c40fa12f Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Dec 7 12:00:57 2022 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Dec 7 14:45:54 2022 +0000 tdf#136011: move UItest to CppUnittest Change-Id: Id8ea0fcfef8598f163febe2aa2564b0ce9d0657f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143769 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sc/qa/uitest/data/tdf136011.ods b/chart2/qa/extras/data/ods/tdf136011.ods similarity index 100% rename from sc/qa/uitest/data/tdf136011.ods rename to chart2/qa/extras/data/ods/tdf136011.ods diff --git a/chart2/qa/extras/uichart.cxx b/chart2/qa/extras/uichart.cxx index 2d70428a7547..a6f63fa5986d 100644 --- a/chart2/qa/extras/uichart.cxx +++ b/chart2/qa/extras/uichart.cxx @@ -197,6 +197,78 @@ CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf107097) } } +CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf136011) +{ + for (sal_Int32 nChart = 0; nChart < 2; ++nChart) + { + loadFromURL(u"ods/tdf136011.ods"); + uno::Reference<chart::XChartDocument> xChartDoc( + getChartCompFromSheet(0, nChart, mxComponent), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xChartDoc.is()); + uno::Reference<chart::XChartDataArray> xChartData(xChartDoc->getData(), + uno::UNO_QUERY_THROW); + + uno::Sequence<OUString> aExpectedColumnDescriptions = xChartData->getColumnDescriptions(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aExpectedColumnDescriptions.getLength()); + + uno::Sequence<OUString> aExpectedRowDescriptions = xChartData->getRowDescriptions(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(9), aExpectedRowDescriptions.getLength()); + + Sequence<Sequence<double>> aExpectedData = xChartData->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(9), aExpectedData.getLength()); + + uno::Sequence<beans::PropertyValue> aPropertyValues = { + comphelper::makePropertyValue("ToObject", "Object " + OUString::number(nChart + 1)), + }; + dispatchCommand(mxComponent, ".uno:GoToObject", aPropertyValues); + Scheduler::ProcessEventsToIdle(); + + dispatchCommand(mxComponent, ".uno:Copy", {}); + Scheduler::ProcessEventsToIdle(); + + // create a new document + load("private:factory/scalc"); + + dispatchCommand(mxComponent, ".uno:Paste", {}); + Scheduler::ProcessEventsToIdle(); + + uno::Reference<chart2::XChartDocument> xChartDoc2 = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT(xChartDoc2.is()); + + uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc2->getDataProvider(), + UNO_QUERY_THROW); + Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), aColumnDesc.getLength()); + for (size_t i = 0; i < 3; ++i) + CPPUNIT_ASSERT_EQUAL(aExpectedColumnDescriptions[i], aColumnDesc[i]); + + Sequence<OUString> aRowDesc = xDataArray->getRowDescriptions(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(9), aRowDesc.getLength()); + + // Without the fix in place, this test would have failed with + // - Expected: Test 1 1 + // - Actual : Test 1 + for (size_t i = 0; i < 9; ++i) + CPPUNIT_ASSERT_EQUAL(aExpectedRowDescriptions[i], aRowDesc[i]); + + Sequence<Sequence<double>> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(9), aData.getLength()); + + for (sal_Int32 nRowIdx = 0; nRowIdx < 9; ++nRowIdx) + { + for (sal_Int32 nColIdx = 0; nColIdx < 3; ++nColIdx) + { + double nValue = aData[nRowIdx][nColIdx]; + double nExpected = aExpectedData[nRowIdx][nColIdx]; + OString sMessage("Incorrect value in Col: " + OString::number(nColIdx) + + " Row: " + OString::number(nRowIdx)); + + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1); + } + } + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/uitest/chart2/tdf136011.py b/sc/qa/uitest/chart2/tdf136011.py deleted file mode 100644 index a5ea560e5cbe..000000000000 --- a/sc/qa/uitest/chart2/tdf136011.py +++ /dev/null @@ -1,51 +0,0 @@ -# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-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/. -# -from uitest.framework import UITestCase -from uitest.uihelper.common import get_url_for_data_file - -from libreoffice.uno.propertyvalue import mkPropertyValues - - -class tdf136011(UITestCase): - - def test_tdf136011(self): - - xObjectNames = ['Object 1', 'Object 2'] - xCategories = ['Test 1', 'Test 2', 'Test 3'] - xSubCategories = [['A', 'B', 'C'], ['1', '2', '3']] - xColumnNames = ['A', 'B', 'C'] - - # Test both charts - for i, name in enumerate(xObjectNames): - - with self.ui_test.load_file(get_url_for_data_file("tdf136011.ods")): - xCalcDoc = self.xUITest.getTopFocusWindow() - gridwin = xCalcDoc.getChild("grid_window") - - xExpectedResults = [] - for category in xCategories: - for subCategory in xSubCategories[i]: - xExpectedResults.append(category + ' ' + subCategory) - - gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": name})) - - self.xUITest.executeCommand(".uno:Copy") - - with self.ui_test.load_empty_file("calc") as calc_document: - self.xUITest.executeCommand(".uno:Paste") - - xData = calc_document.Sheets[0].Charts[0].getEmbeddedObject().Data - - self.assertEqual(xColumnNames, list(xData.ColumnDescriptions)) - - # Without the fix in place, the numbers in the categories in chart - # 'Object 2' wouldn't have been pasted to the new document - self.assertEqual(xExpectedResults, list(xData.RowDescriptions)) - -# vim: set shiftwidth=4 softtabstop=4 expandtab: