diff options
author | Vasily Melenchuk <Vasily.Melenchuk@cib.de> | 2017-11-29 16:29:52 +0300 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-12-15 22:04:08 +0100 |
commit | be46bc5d20ad82be1d9c8513a83584ecee9edbc2 (patch) | |
tree | 91e05fab8ef74683b79ed5a4021fcee98e2c8bb8 | |
parent | 8de8e0ce218dbb9e74d2a41517d5f6b1d36f478f (diff) |
tdf#113861: Unittest for chart datatable labels expansion
Change-Id: I4ed9019fc1e637e344ab1cb80f650b32aa034a9a
Reviewed-on: https://gerrit.libreoffice.org/45670
Reviewed-on: https://gerrit.libreoffice.org/46541
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | sc/CppunitTest_sc_chart2dataprovider.mk | 122 | ||||
-rw-r--r-- | sc/Module_sc.mk | 1 | ||||
-rw-r--r-- | sc/inc/chart2uno.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/chart2dataprovider.cxx | 129 | ||||
-rw-r--r-- | sc/qa/unit/data/ods/chart2dataprovider.ods | bin | 0 -> 10229 bytes |
5 files changed, 253 insertions, 1 deletions
diff --git a/sc/CppunitTest_sc_chart2dataprovider.mk b/sc/CppunitTest_sc_chart2dataprovider.mk new file mode 100644 index 000000000000..7ef131b7f147 --- /dev/null +++ b/sc/CppunitTest_sc_chart2dataprovider.mk @@ -0,0 +1,122 @@ +# -*- 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,sc_chart2dataprovider)) + +$(eval $(call gb_CppunitTest_add_exception_objects,sc_chart2dataprovider, \ + sc/qa/unit/chart2dataprovider \ +)) + +$(eval $(call gb_CppunitTest_use_externals,sc_chart2dataprovider, \ + boost_headers \ + mdds_headers \ + libxml2 \ +)) + +$(eval $(call gb_CppunitTest_use_libraries,sc_chart2dataprovider, \ + basegfx \ + comphelper \ + cppu \ + cppuhelper \ + drawinglayer \ + editeng \ + for \ + forui \ + i18nlangtag \ + msfilter \ + oox \ + sal \ + salhelper \ + sax \ + sb \ + sc \ + scqahelper \ + sfx \ + sot \ + subsequenttest \ + svl \ + svt \ + svx \ + svxcore \ + test \ + tk \ + tl \ + ucbhelper \ + unotest \ + utl \ + vbahelper \ + vcl \ + xo \ + $(gb_UWINAPI) \ +)) + +$(eval $(call gb_CppunitTest_set_include,sc_chart2dataprovider,\ + -I$(SRCDIR)/sc/source/ui/inc \ + -I$(SRCDIR)/sc/inc \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_CppunitTest_use_sdk_api,sc_chart2dataprovider)) + +$(eval $(call gb_CppunitTest_use_ure,sc_chart2dataprovider)) +$(eval $(call gb_CppunitTest_use_vcl,sc_chart2dataprovider)) + +$(eval $(call gb_CppunitTest_use_components,sc_chart2dataprovider,\ + basic/util/sb \ + chart2/source/chartcore \ + chart2/source/controller/chartcontroller \ + comphelper/util/comphelp \ + configmgr/source/configmgr \ + dbaccess/util/dba \ + embeddedobj/util/embobj \ + eventattacher/source/evtatt \ + filter/source/config/cache/filterconfig1 \ + forms/util/frm \ + framework/util/fwk \ + i18npool/source/search/i18nsearch \ + i18npool/util/i18npool \ + linguistic/source/lng \ + oox/util/oox \ + package/source/xstor/xstor \ + package/util/package2 \ + sax/source/expatwrap/expwrap \ + scaddins/source/analysis/analysis \ + scaddins/source/datefunc/date \ + sc/util/sc \ + sc/util/scfilt \ + sfx2/util/sfx \ + sot/util/sot \ + svl/util/svl \ + svl/source/fsstor/fsstorage \ + svtools/util/svt \ + toolkit/util/tk \ + ucb/source/core/ucb1 \ + ucb/source/ucp/file/ucpfile1 \ + ucb/source/ucp/tdoc/ucptdoc1 \ + unotools/util/utl \ + unoxml/source/rdf/unordf \ + unoxml/source/service/unoxml \ + uui/util/uui \ + xmloff/util/xo \ + xmlsecurity/util/xmlsecurity \ +)) + +ifeq ($(OS),WNT) +$(eval $(call gb_CppunitTest_use_components,sc_chart2dataprovider,\ + xmlsecurity/util/xsec_xmlsec.windows \ +)) +else +$(eval $(call gb_CppunitTest_use_components,sc_chart2dataprovider,\ + xmlsecurity/util/xsec_xmlsec \ +)) +endif + +$(eval $(call gb_CppunitTest_use_configuration,sc_chart2dataprovider)) + +# vim: set noet sw=4 ts=4: diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk index 2a06f629bb46..bfdf6f277aa3 100644 --- a/sc/Module_sc.mk +++ b/sc/Module_sc.mk @@ -147,6 +147,7 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sc,\ CppunitTest_sc_datapilottablesobj \ CppunitTest_sc_databaserangesobj \ CppunitTest_sc_consolidationdescriptorobj \ + CppunitTest_sc_chart2dataprovider \ )) $(eval $(call gb_Module_add_perfcheck_targets,sc,\ diff --git a/sc/inc/chart2uno.hxx b/sc/inc/chart2uno.hxx index 795561b642fa..fb19a502a4c9 100644 --- a/sc/inc/chart2uno.hxx +++ b/sc/inc/chart2uno.hxx @@ -53,7 +53,7 @@ class ScDocument; // DataProvider -class ScChart2DataProvider : public +class SC_DLLPUBLIC ScChart2DataProvider : public ::cppu::WeakImplHelper< css::chart2::data::XDataProvider, css::chart2::data::XSheetDataProvider, diff --git a/sc/qa/unit/chart2dataprovider.cxx b/sc/qa/unit/chart2dataprovider.cxx new file mode 100644 index 000000000000..e5536d391997 --- /dev/null +++ b/sc/qa/unit/chart2dataprovider.cxx @@ -0,0 +1,129 @@ +/* -*- 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 <sal/config.h> +#include <test/bootstrapfixture.hxx> + +#include <docsh.hxx> +#include <chart2uno.hxx> +#include <charthelper.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/chart2/data/XLabeledDataSequence2.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> + +#include "helper/qahelper.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScChart2DataProviderTest : public ScBootstrapFixture +{ +public: + ScChart2DataProviderTest(); + + virtual void setUp() override; + virtual void tearDown() override; + + void testHeaderExpansion(); + + CPPUNIT_TEST_SUITE(ScChart2DataProviderTest); + CPPUNIT_TEST(testHeaderExpansion); + CPPUNIT_TEST_SUITE_END(); + +private: + uno::Reference<uno::XInterface> m_xCalcComponent; +}; + +void lcl_createAndCheckDataProvider(ScDocument& rDoc, const OUString& cellRange, bool hasCategories, + bool firstCellAsLabel, sal_Int32 expectedRows, + sal_Int32 expectedCols) +{ + uno::Reference<chart2::data::XDataProvider> xDataProvider = new ScChart2DataProvider(&rDoc); + CPPUNIT_ASSERT(xDataProvider.is()); + + uno::Sequence<beans::PropertyValue> aArgs(4); + + aArgs[0].Name = "CellRangeRepresentation"; + aArgs[0].Value <<= cellRange; + + aArgs[1].Name = "HasCategories"; + aArgs[1].Value <<= hasCategories; + + aArgs[2].Name = "FirstCellAsLabel"; + aArgs[2].Value <<= firstCellAsLabel; + + aArgs[3].Name = "DataRowSource"; + aArgs[3].Value <<= chart::ChartDataRowSource_COLUMNS; + + uno::Reference<chart2::data::XDataSource> xDataSource = xDataProvider->createDataSource(aArgs); + CPPUNIT_ASSERT(xDataSource.is()); + + css::uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>> xSequences + = xDataSource->getDataSequences(); + + CPPUNIT_ASSERT_EQUAL(expectedRows, xSequences.getLength()); + + sal_Int32 nStartRow = hasCategories ? 1 : 0; + for (sal_Int32 nIdx = nStartRow; nIdx < xSequences.getLength(); ++nIdx) + { + Reference<chart2::data::XDataSequence> xValues(xSequences[nIdx]->getValues()); + if (xValues.is()) + { + sal_Int32 colsNum = xValues->getData().getLength(); + CPPUNIT_ASSERT_EQUAL(expectedCols, colsNum); + } + } +} + +void ScChart2DataProviderTest::testHeaderExpansion() +{ + ScDocShellRef xDocSh = loadDoc("chart2dataprovider.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load ch.ods.", xDocSh.is()); + + ScDocument& rDoc = xDocSh->GetDocument(); + + lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$1:$D$4", false, false, 4, 4); + lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$1:$D$4", true, true, 4, 3); + + lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$17:$D$20", true, true, 3, 2); + + lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$25:$D$28", true, true, 4, 2); + + xDocSh->DoClose(); +} + +ScChart2DataProviderTest::ScChart2DataProviderTest() + : ScBootstrapFixture("sc/qa/unit/data") +{ +} + +void ScChart2DataProviderTest::setUp() +{ + test::BootstrapFixture::setUp(); + + // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure, + // which is a private symbol to us, gets called + m_xCalcComponent + = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument"); + CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is()); +} + +void ScChart2DataProviderTest::tearDown() +{ + uno::Reference<lang::XComponent>(m_xCalcComponent, UNO_QUERY_THROW)->dispose(); + test::BootstrapFixture::tearDown(); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChart2DataProviderTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/qa/unit/data/ods/chart2dataprovider.ods b/sc/qa/unit/data/ods/chart2dataprovider.ods Binary files differnew file mode 100644 index 000000000000..7352b4d30cb5 --- /dev/null +++ b/sc/qa/unit/data/ods/chart2dataprovider.ods |