rtl::Static->thread-safe static in unotools
[LibreOffice.git] / sc / qa / unit / chart2dataprovider.cxx
blob31af9ba6eef9294618f12850c332079892143e6d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <sal/config.h>
12 #include <comphelper/propertyvalue.hxx>
13 #include <test/bootstrapfixture.hxx>
15 #include <docsh.hxx>
16 #include <chart2uno.hxx>
18 #include <com/sun/star/chart/ChartDataRowSource.hpp>
19 #include <com/sun/star/chart2/data/XDataSource.hpp>
21 #include "helper/qahelper.hxx"
23 using namespace ::com::sun::star;
24 using namespace ::com::sun::star::uno;
26 class ScChart2DataProviderTest : public ScBootstrapFixture
28 public:
29 ScChart2DataProviderTest();
31 virtual void setUp() override;
32 virtual void tearDown() override;
34 void testHeaderExpansion();
36 CPPUNIT_TEST_SUITE(ScChart2DataProviderTest);
37 CPPUNIT_TEST(testHeaderExpansion);
38 CPPUNIT_TEST_SUITE_END();
40 private:
41 uno::Reference<uno::XInterface> m_xCalcComponent;
44 static void lcl_createAndCheckDataProvider(ScDocument& rDoc, const OUString& cellRange,
45 bool hasCategories, bool firstCellAsLabel,
46 sal_Int32 expectedRows, sal_Int32 expectedCols)
48 uno::Reference<chart2::data::XDataProvider> xDataProvider = new ScChart2DataProvider(&rDoc);
49 CPPUNIT_ASSERT(xDataProvider.is());
51 uno::Sequence<beans::PropertyValue> aArgs{
52 comphelper::makePropertyValue("CellRangeRepresentation", cellRange),
53 comphelper::makePropertyValue("HasCategories", hasCategories),
54 comphelper::makePropertyValue("FirstCellAsLabel", firstCellAsLabel),
55 comphelper::makePropertyValue("DataRowSource", chart::ChartDataRowSource_COLUMNS)
58 uno::Reference<chart2::data::XDataSource> xDataSource = xDataProvider->createDataSource(aArgs);
59 CPPUNIT_ASSERT(xDataSource.is());
61 css::uno::Sequence<uno::Reference<chart2::data::XLabeledDataSequence>> xSequences
62 = xDataSource->getDataSequences();
64 CPPUNIT_ASSERT_EQUAL(expectedRows, xSequences.getLength());
66 sal_Int32 nStartRow = hasCategories ? 1 : 0;
67 for (sal_Int32 nIdx = nStartRow; nIdx < xSequences.getLength(); ++nIdx)
69 Reference<chart2::data::XDataSequence> xValues(xSequences[nIdx]->getValues());
70 if (xValues.is())
72 sal_Int32 colsNum = xValues->getData().getLength();
73 CPPUNIT_ASSERT_EQUAL(expectedCols, colsNum);
78 void ScChart2DataProviderTest::testHeaderExpansion()
80 ScDocShellRef xDocSh = loadDoc(u"chart2dataprovider.", FORMAT_ODS);
81 CPPUNIT_ASSERT_MESSAGE("Failed to load ch.ods.", xDocSh.is());
83 ScDocument& rDoc = xDocSh->GetDocument();
85 lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$1:$D$4", false, false, 4, 4);
86 lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$1:$D$4", true, true, 4, 3);
88 lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$17:$D$20", true, true, 3, 2);
90 lcl_createAndCheckDataProvider(rDoc, "$Sheet1.$A$25:$D$28", true, true, 4, 2);
92 xDocSh->DoClose();
95 ScChart2DataProviderTest::ScChart2DataProviderTest()
96 : ScBootstrapFixture("sc/qa/unit/data")
100 void ScChart2DataProviderTest::setUp()
102 test::BootstrapFixture::setUp();
104 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
105 // which is a private symbol to us, gets called
106 m_xCalcComponent
107 = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
108 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
111 void ScChart2DataProviderTest::tearDown()
113 uno::Reference<lang::XComponent>(m_xCalcComponent, UNO_QUERY_THROW)->dispose();
114 test::BootstrapFixture::tearDown();
117 CPPUNIT_TEST_SUITE_REGISTRATION(ScChart2DataProviderTest);
119 CPPUNIT_PLUGIN_IMPLEMENT();
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */