1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/config.h>
12 #include <comphelper/propertyvalue.hxx>
14 #include <chart2uno.hxx>
16 #include <com/sun/star/chart/ChartDataRowSource.hpp>
17 #include <com/sun/star/chart2/data/XDataSource.hpp>
19 #include "helper/qahelper.hxx"
21 using namespace ::com::sun::star
;
22 using namespace ::com::sun::star::uno
;
24 class ScChart2DataProviderTest
: public ScModelTestBase
27 ScChart2DataProviderTest();
29 void testHeaderExpansion();
31 CPPUNIT_TEST_SUITE(ScChart2DataProviderTest
);
32 CPPUNIT_TEST(testHeaderExpansion
);
33 CPPUNIT_TEST_SUITE_END();
36 static void lcl_createAndCheckDataProvider(ScDocument
& rDoc
, const OUString
& cellRange
,
37 bool hasCategories
, bool firstCellAsLabel
,
38 sal_Int32 expectedRows
, sal_Int32 expectedCols
)
40 uno::Reference
<chart2::data::XDataProvider
> xDataProvider
= new ScChart2DataProvider(&rDoc
);
41 CPPUNIT_ASSERT(xDataProvider
.is());
43 uno::Sequence
<beans::PropertyValue
> aArgs
{
44 comphelper::makePropertyValue(u
"CellRangeRepresentation"_ustr
, cellRange
),
45 comphelper::makePropertyValue(u
"HasCategories"_ustr
, hasCategories
),
46 comphelper::makePropertyValue(u
"FirstCellAsLabel"_ustr
, firstCellAsLabel
),
47 comphelper::makePropertyValue(u
"DataRowSource"_ustr
, chart::ChartDataRowSource_COLUMNS
)
50 uno::Reference
<chart2::data::XDataSource
> xDataSource
= xDataProvider
->createDataSource(aArgs
);
51 CPPUNIT_ASSERT(xDataSource
.is());
53 css::uno::Sequence
<uno::Reference
<chart2::data::XLabeledDataSequence
>> xSequences
54 = xDataSource
->getDataSequences();
56 CPPUNIT_ASSERT_EQUAL(expectedRows
, xSequences
.getLength());
58 sal_Int32 nStartRow
= hasCategories
? 1 : 0;
59 for (sal_Int32 nIdx
= nStartRow
; nIdx
< xSequences
.getLength(); ++nIdx
)
61 Reference
<chart2::data::XDataSequence
> xValues(xSequences
[nIdx
]->getValues());
64 sal_Int32 colsNum
= xValues
->getData().getLength();
65 CPPUNIT_ASSERT_EQUAL(expectedCols
, colsNum
);
70 void ScChart2DataProviderTest::testHeaderExpansion()
72 createScDoc("ods/chart2dataprovider.ods");
74 ScDocument
* pDoc
= getScDoc();
76 lcl_createAndCheckDataProvider(*pDoc
, u
"$Sheet1.$A$1:$D$4"_ustr
, false, false, 4, 4);
77 lcl_createAndCheckDataProvider(*pDoc
, u
"$Sheet1.$A$1:$D$4"_ustr
, true, true, 4, 3);
79 lcl_createAndCheckDataProvider(*pDoc
, u
"$Sheet1.$A$17:$D$20"_ustr
, true, true, 3, 2);
81 lcl_createAndCheckDataProvider(*pDoc
, u
"$Sheet1.$A$25:$D$28"_ustr
, true, true, 4, 2);
84 ScChart2DataProviderTest::ScChart2DataProviderTest()
85 : ScModelTestBase(u
"sc/qa/unit/data"_ustr
)
89 CPPUNIT_TEST_SUITE_REGISTRATION(ScChart2DataProviderTest
);
91 CPPUNIT_PLUGIN_IMPLEMENT();
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */