1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <test/calc_unoapi_test.hxx>
11 #include <test/container/xenumeration.hxx>
13 #include <com/sun/star/container/XEnumerationAccess.hpp>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/GeneralFunction.hpp>
17 #include <com/sun/star/sheet/SubTotalColumn.hpp>
18 #include <com/sun/star/sheet/XSpreadsheet.hpp>
19 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
20 #include <com/sun/star/sheet/XSpreadsheets.hpp>
21 #include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
22 #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
23 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
29 using namespace css::uno
;
33 class ScIndexEnumeration_SubTotalFieldsEnumeration
: public CalcUnoApiTest
,
34 public apitest::XEnumeration
37 ScIndexEnumeration_SubTotalFieldsEnumeration();
39 virtual uno::Reference
<uno::XInterface
> init() override
;
40 virtual void setUp() override
;
41 virtual void tearDown() override
;
43 CPPUNIT_TEST_SUITE(ScIndexEnumeration_SubTotalFieldsEnumeration
);
46 CPPUNIT_TEST(testHasMoreElements
);
47 CPPUNIT_TEST(testNextElement
);
49 CPPUNIT_TEST_SUITE_END();
52 uno::Reference
<lang::XComponent
> m_xComponent
;
55 ScIndexEnumeration_SubTotalFieldsEnumeration::ScIndexEnumeration_SubTotalFieldsEnumeration()
56 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
60 uno::Reference
<uno::XInterface
> ScIndexEnumeration_SubTotalFieldsEnumeration::init()
62 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
63 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
65 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
66 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
67 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
69 uno::Reference
<sheet::XSubTotalCalculatable
> xSTC(xSheet0
, uno::UNO_QUERY_THROW
);
70 uno::Reference
<sheet::XSubTotalDescriptor
> xSTD(xSTC
->createSubTotalDescriptor(true),
73 uno::Sequence
<sheet::SubTotalColumn
> aSubTotalColumns(1);
74 aSubTotalColumns
[0].Column
= 5;
75 aSubTotalColumns
[0].Function
= sheet::GeneralFunction_SUM
;
76 xSTD
->addNew(aSubTotalColumns
, 1);
78 uno::Reference
<container::XIndexAccess
> xIA_STD(xSTD
, uno::UNO_QUERY_THROW
);
79 uno::Reference
<container::XEnumerationAccess
> xEA(xIA_STD
, uno::UNO_QUERY_THROW
);
81 return xEA
->createEnumeration();
84 void ScIndexEnumeration_SubTotalFieldsEnumeration::setUp()
86 CalcUnoApiTest::setUp();
87 m_xComponent
= loadFromDesktop("private:factory/scalc");
88 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
91 void ScIndexEnumeration_SubTotalFieldsEnumeration::tearDown()
93 closeDocument(m_xComponent
);
94 CalcUnoApiTest::tearDown();
97 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SubTotalFieldsEnumeration
);
99 } // namespace sc_apitest
101 CPPUNIT_PLUGIN_IMPLEMENT();
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */