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>
11 #include <test/bootstrapfixture.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 ScBootstrapFixture
27 ScChart2DataProviderTest();
29 virtual void setUp() override
;
30 virtual void tearDown() override
;
32 void testHeaderExpansion();
34 CPPUNIT_TEST_SUITE(ScChart2DataProviderTest
);
35 CPPUNIT_TEST(testHeaderExpansion
);
36 CPPUNIT_TEST_SUITE_END();
39 uno::Reference
<uno::XInterface
> m_xCalcComponent
;
42 static void lcl_createAndCheckDataProvider(ScDocument
& rDoc
, const OUString
& cellRange
,
43 bool hasCategories
, bool firstCellAsLabel
,
44 sal_Int32 expectedRows
, sal_Int32 expectedCols
)
46 uno::Reference
<chart2::data::XDataProvider
> xDataProvider
= new ScChart2DataProvider(&rDoc
);
47 CPPUNIT_ASSERT(xDataProvider
.is());
49 uno::Sequence
<beans::PropertyValue
> aArgs(4);
51 aArgs
[0].Name
= "CellRangeRepresentation";
52 aArgs
[0].Value
<<= cellRange
;
54 aArgs
[1].Name
= "HasCategories";
55 aArgs
[1].Value
<<= hasCategories
;
57 aArgs
[2].Name
= "FirstCellAsLabel";
58 aArgs
[2].Value
<<= firstCellAsLabel
;
60 aArgs
[3].Name
= "DataRowSource";
61 aArgs
[3].Value
<<= chart::ChartDataRowSource_COLUMNS
;
63 uno::Reference
<chart2::data::XDataSource
> xDataSource
= xDataProvider
->createDataSource(aArgs
);
64 CPPUNIT_ASSERT(xDataSource
.is());
66 css::uno::Sequence
<uno::Reference
<chart2::data::XLabeledDataSequence
>> xSequences
67 = xDataSource
->getDataSequences();
69 CPPUNIT_ASSERT_EQUAL(expectedRows
, xSequences
.getLength());
71 sal_Int32 nStartRow
= hasCategories
? 1 : 0;
72 for (sal_Int32 nIdx
= nStartRow
; nIdx
< xSequences
.getLength(); ++nIdx
)
74 Reference
<chart2::data::XDataSequence
> xValues(xSequences
[nIdx
]->getValues());
77 sal_Int32 colsNum
= xValues
->getData().getLength();
78 CPPUNIT_ASSERT_EQUAL(expectedCols
, colsNum
);
83 void ScChart2DataProviderTest::testHeaderExpansion()
85 ScDocShellRef xDocSh
= loadDoc("chart2dataprovider.", FORMAT_ODS
);
86 CPPUNIT_ASSERT_MESSAGE("Failed to load ch.ods.", xDocSh
.is());
88 ScDocument
& rDoc
= xDocSh
->GetDocument();
90 lcl_createAndCheckDataProvider(rDoc
, "$Sheet1.$A$1:$D$4", false, false, 4, 4);
91 lcl_createAndCheckDataProvider(rDoc
, "$Sheet1.$A$1:$D$4", true, true, 4, 3);
93 lcl_createAndCheckDataProvider(rDoc
, "$Sheet1.$A$17:$D$20", true, true, 3, 2);
95 lcl_createAndCheckDataProvider(rDoc
, "$Sheet1.$A$25:$D$28", true, true, 4, 2);
100 ScChart2DataProviderTest::ScChart2DataProviderTest()
101 : ScBootstrapFixture("sc/qa/unit/data")
105 void ScChart2DataProviderTest::setUp()
107 test::BootstrapFixture::setUp();
109 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
110 // which is a private symbol to us, gets called
112 = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
113 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent
.is());
116 void ScChart2DataProviderTest::tearDown()
118 uno::Reference
<lang::XComponent
>(m_xCalcComponent
, UNO_QUERY_THROW
)->dispose();
119 test::BootstrapFixture::tearDown();
122 CPPUNIT_TEST_SUITE_REGISTRATION(ScChart2DataProviderTest
);
124 CPPUNIT_PLUGIN_IMPLEMENT();
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */