From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- sc/qa/unit/chart2dataprovider.cxx | 93 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 sc/qa/unit/chart2dataprovider.cxx (limited to 'sc/qa/unit/chart2dataprovider.cxx') diff --git a/sc/qa/unit/chart2dataprovider.cxx b/sc/qa/unit/chart2dataprovider.cxx new file mode 100644 index 0000000000..5b10ee7f8a --- /dev/null +++ b/sc/qa/unit/chart2dataprovider.cxx @@ -0,0 +1,93 @@ +/* -*- 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 + +#include + +#include + +#include +#include + +#include "helper/qahelper.hxx" + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +class ScChart2DataProviderTest : public ScModelTestBase +{ +public: + ScChart2DataProviderTest(); + + void testHeaderExpansion(); + + CPPUNIT_TEST_SUITE(ScChart2DataProviderTest); + CPPUNIT_TEST(testHeaderExpansion); + CPPUNIT_TEST_SUITE_END(); +}; + +static void lcl_createAndCheckDataProvider(ScDocument& rDoc, const OUString& cellRange, + bool hasCategories, bool firstCellAsLabel, + sal_Int32 expectedRows, sal_Int32 expectedCols) +{ + uno::Reference xDataProvider = new ScChart2DataProvider(&rDoc); + CPPUNIT_ASSERT(xDataProvider.is()); + + uno::Sequence aArgs{ + comphelper::makePropertyValue("CellRangeRepresentation", cellRange), + comphelper::makePropertyValue("HasCategories", hasCategories), + comphelper::makePropertyValue("FirstCellAsLabel", firstCellAsLabel), + comphelper::makePropertyValue("DataRowSource", chart::ChartDataRowSource_COLUMNS) + }; + + uno::Reference xDataSource = xDataProvider->createDataSource(aArgs); + CPPUNIT_ASSERT(xDataSource.is()); + + css::uno::Sequence> 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 xValues(xSequences[nIdx]->getValues()); + if (xValues.is()) + { + sal_Int32 colsNum = xValues->getData().getLength(); + CPPUNIT_ASSERT_EQUAL(expectedCols, colsNum); + } + } +} + +void ScChart2DataProviderTest::testHeaderExpansion() +{ + createScDoc("ods/chart2dataprovider.ods"); + + ScDocument* pDoc = getScDoc(); + + lcl_createAndCheckDataProvider(*pDoc, "$Sheet1.$A$1:$D$4", false, false, 4, 4); + lcl_createAndCheckDataProvider(*pDoc, "$Sheet1.$A$1:$D$4", true, true, 4, 3); + + lcl_createAndCheckDataProvider(*pDoc, "$Sheet1.$A$17:$D$20", true, true, 3, 2); + + lcl_createAndCheckDataProvider(*pDoc, "$Sheet1.$A$25:$D$28", true, true, 4, 2); +} + +ScChart2DataProviderTest::ScChart2DataProviderTest() + : ScModelTestBase("sc/qa/unit/data") +{ +} + +CPPUNIT_TEST_SUITE_REGISTRATION(ScChart2DataProviderTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3