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>
This commit is contained in:
parent
c802c5f390
commit
6e9b99ffe0
5 changed files with 167 additions and 61 deletions
58
chart2/CppunitTest_chart2_uichart.mk
Normal file
58
chart2/CppunitTest_chart2_uichart.mk
Normal file
|
@ -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:
|
|
@ -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)
|
||||
|
|
108
chart2/qa/extras/uichart.cxx
Normal file
108
chart2/qa/extras/uichart.cxx
Normal file
|
@ -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: */
|
|
@ -1,61 +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.calc.document import get_cell_by_position
|
||||
from libreoffice.uno.propertyvalue import mkPropertyValues
|
||||
|
||||
|
||||
class tdf120348(UITestCase):
|
||||
|
||||
def test_tdf120348(self):
|
||||
|
||||
with self.ui_test.load_file(get_url_for_data_file("tdf120348.ods")) as calc_doc:
|
||||
xCalcDoc = self.xUITest.getTopFocusWindow()
|
||||
gridwin = xCalcDoc.getChild("grid_window")
|
||||
|
||||
xFirstMatrix = []
|
||||
for row in range(1, 159):
|
||||
xRow = []
|
||||
for column in range(5, 9):
|
||||
xRow.append(round(get_cell_by_position(calc_doc, 0, column, row).getValue(), 5))
|
||||
xFirstMatrix.append(xRow)
|
||||
|
||||
gridwin.executeAction("SELECT", mkPropertyValues({"OBJECT": "Object 2"}))
|
||||
|
||||
self.xUITest.executeCommand(".uno:Copy")
|
||||
|
||||
with self.ui_test.load_empty_file("calc") as calc_document:
|
||||
|
||||
xCalcDoc = self.xUITest.getTopFocusWindow()
|
||||
gridwin = xCalcDoc.getChild("grid_window")
|
||||
|
||||
self.xUITest.executeCommand(".uno:Paste")
|
||||
|
||||
xData = calc_document.Sheets[0].Charts[0].getEmbeddedObject().Data
|
||||
|
||||
columnNames = ('Finland', 'Sweden', 'Poland', '')
|
||||
self.assertEqual(columnNames, xData.ColumnDescriptions)
|
||||
|
||||
xSecondMatrix = []
|
||||
for row in xData.Data:
|
||||
xRow = []
|
||||
for value in row:
|
||||
xRow.append(round(value, 5))
|
||||
xSecondMatrix.append(xRow)
|
||||
|
||||
# Without the fix in place, this test would have failed with
|
||||
# First differing element 51:
|
||||
# [3.31618, 3.65089, 3.33626, 0.0]
|
||||
# [3.31618, 3.65089, 0.0, 0.0]
|
||||
|
||||
self.assertEqual(xFirstMatrix, xSecondMatrix)
|
||||
|
||||
# vim: set shiftwidth=4 softtabstop=4 expandtab:
|
Loading…
Reference in a new issue