diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-25 14:38:48 +0100 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-11-25 21:28:10 +0100 |
commit | 6e9b99ffe0083060176dc782986d3b441b7e48ec (patch) | |
tree | 2bd2089f4fe575275fe2ff52f581ef3af91270c3 /chart2 | |
parent | c802c5f390a30a66118f56a01e47772a54743a6a (diff) |
tdf#120348: move UItest to CppUnittest
for that, create a new CppunitTest_chart2_uichart
in chart2
Change-Id: Ie4cdaff4a1dd623c7788ed7acdd5ef135f403e84
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143305
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/CppunitTest_chart2_uichart.mk | 58 | ||||
-rw-r--r-- | chart2/Module_chart2.mk | 1 | ||||
-rw-r--r-- | chart2/qa/extras/data/ods/tdf120348.ods | bin | 0 -> 43612 bytes | |||
-rw-r--r-- | chart2/qa/extras/uichart.cxx | 108 |
4 files changed, 167 insertions, 0 deletions
diff --git a/chart2/CppunitTest_chart2_uichart.mk b/chart2/CppunitTest_chart2_uichart.mk new file mode 100644 index 000000000000..9e464e0a7c6f --- /dev/null +++ b/chart2/CppunitTest_chart2_uichart.mk @@ -0,0 +1,58 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +#************************************************************************* +# +# 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/. +# +#************************************************************************* + +$(eval $(call gb_CppunitTest_CppunitTest,chart2_uichart)) + +$(eval $(call gb_CppunitTest_use_externals,chart2_uichart, \ + boost_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_add_exception_objects,chart2_uichart, \ + chart2/qa/extras/uichart \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,chart2_uichart, \ + comphelper \ + cppu \ + cppuhelper \ + i18nlangtag \ + sal \ + sc \ + sfx \ + subsequenttest \ + svl \ + svl \ + svx \ + svxcore \ + test \ + tl \ + unotest \ + utl \ + vcl \ +)) + +$(eval $(call gb_CppunitTest_set_include,chart2_uichart,\ + -I$(SRCDIR)/chart2/qa/extras \ + -I$(SRCDIR)/chart2/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,chart2_uichart)) + +$(eval $(call gb_CppunitTest_use_ure,chart2_uichart)) +$(eval $(call gb_CppunitTest_use_vcl,chart2_uichart)) + +$(eval $(call gb_CppunitTest_use_rdb,chart2_uichart,services)) + +$(eval $(call gb_CppunitTest_use_configuration,chart2_uichart)) + +# vim: set noet sw=4 ts=4: diff --git a/chart2/Module_chart2.mk b/chart2/Module_chart2.mk index 1a26ebd2b959..5f7fd5aee961 100644 --- a/chart2/Module_chart2.mk +++ b/chart2/Module_chart2.mk @@ -37,6 +37,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,chart2,\ CppunitTest_chart2_dump \ CppunitTest_chart2_pivot_chart_test \ CppunitTest_chart2_geometry \ + CppunitTest_chart2_uichart \ )) ifeq ($(WITH_FONTS), TRUE) diff --git a/chart2/qa/extras/data/ods/tdf120348.ods b/chart2/qa/extras/data/ods/tdf120348.ods Binary files differnew file mode 100644 index 000000000000..7a593c1bff7b --- /dev/null +++ b/chart2/qa/extras/data/ods/tdf120348.ods diff --git a/chart2/qa/extras/uichart.cxx b/chart2/qa/extras/uichart.cxx new file mode 100644 index 000000000000..b6e2cb417643 --- /dev/null +++ b/chart2/qa/extras/uichart.cxx @@ -0,0 +1,108 @@ +/* -*- 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> +#include <vcl/scheduler.hxx> + +#include <com/sun/star/sheet/XSpreadsheet.hpp> + +using namespace ::com::sun::star; + +class Chart2UiChartTest : public ChartTest +{ +public: + Chart2UiChartTest() + : ChartTest("/chart2/qa/extras/data/") + { + } +}; + +CPPUNIT_TEST_FIXTURE(Chart2UiChartTest, testTdf120348) +{ + loadFromURL(u"ods/tdf120348.ods"); + uno::Reference<chart2::XChartDocument> xChartDoc = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<sheet::XSpreadsheetDocument> xDocument(mxComponent, uno::UNO_QUERY_THROW); + uno::Reference<container::XIndexAccess> xIndex(xDocument->getSheets(), uno::UNO_QUERY_THROW); + uno::Reference<sheet::XSpreadsheet> xSheet(xIndex->getByIndex(0), uno::UNO_QUERY_THROW); + + std::vector<std::vector<double>> aExpected; + + for (sal_Int32 nRowIdx = 1; nRowIdx < 159; ++nRowIdx) + { + std::vector<double> aRow; + for (sal_Int32 nColIdx = 5; nColIdx < 9; ++nColIdx) + { + uno::Reference<table::XCell> xCell = xSheet->getCellByPosition(nColIdx, nRowIdx); + aRow.push_back(xCell->getValue()); + } + aExpected.push_back(aRow); + } + + uno::Sequence<beans::PropertyValue> aPropertyValues = { + comphelper::makePropertyValue("ToObject", OUString("Object 2")), + }; + 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(); + + xChartDoc = getChartDocFromSheet(0, mxComponent); + CPPUNIT_ASSERT(xChartDoc.is()); + + uno::Reference<chart::XChartDataArray> xDataArray(xChartDoc->getDataProvider(), + UNO_QUERY_THROW); + Sequence<OUString> aColumnDesc = xDataArray->getColumnDescriptions(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4), aColumnDesc.getLength()); + CPPUNIT_ASSERT_EQUAL(OUString("Finland"), aColumnDesc[0]); + CPPUNIT_ASSERT_EQUAL(OUString("Sweden"), aColumnDesc[1]); + CPPUNIT_ASSERT_EQUAL(OUString("Poland"), aColumnDesc[2]); + CPPUNIT_ASSERT_EQUAL(OUString(""), aColumnDesc[3]); + Sequence<Sequence<double>> aData = xDataArray->getData(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(158), aData.getLength()); + + for (sal_Int32 nRowIdx = 0; nRowIdx < 158; ++nRowIdx) + { + for (sal_Int32 nColIdx = 0; nColIdx < 4; ++nColIdx) + { + double nValue = aData[nRowIdx][nColIdx]; + double nExpected = aExpected[nRowIdx][nColIdx]; + OString sMessage("Incorrect value in Col: " + OString::number(nColIdx) + + " Row: " + OString::number(nRowIdx)); + + if (std::isnan(nValue)) + { + // On paste, 0 becomes NaN, check whether it's expected + CPPUNIT_ASSERT_EQUAL_MESSAGE(sMessage.getStr(), 0.0, nExpected); + } + else + { + // Without the fix in place, this test would have failed with + // - Expected: 0 + // - Actual : 3.33625955201419 + // - Incorrect value in Col: 2 Row: 51 + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(sMessage.getStr(), nExpected, nValue, 1e-1); + } + } + } +} + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |