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/container/XNameContainer.hpp>
16 #include <com/sun/star/lang/XComponent.hpp>
17 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
18 #include <com/sun/star/sheet/XSheetCellRanges.hpp>
19 #include <com/sun/star/sheet/XSpreadsheet.hpp>
20 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
21 #include <com/sun/star/sheet/XSpreadsheets.hpp>
22 #include <com/sun/star/uno/XInterface.hpp>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/Reference.hxx>
28 using namespace css::uno
;
32 class ScIndexEnumeration_SheetCellRangesEnumeration
: public CalcUnoApiTest
,
33 public apitest::XEnumeration
36 ScIndexEnumeration_SheetCellRangesEnumeration();
38 virtual uno::Reference
<uno::XInterface
> init() override
;
39 virtual void setUp() override
;
40 virtual void tearDown() override
;
42 CPPUNIT_TEST_SUITE(ScIndexEnumeration_SheetCellRangesEnumeration
);
45 CPPUNIT_TEST(testHasMoreElements
);
46 CPPUNIT_TEST(testNextElement
);
48 CPPUNIT_TEST_SUITE_END();
51 uno::Reference
<lang::XComponent
> m_xComponent
;
54 ScIndexEnumeration_SheetCellRangesEnumeration::ScIndexEnumeration_SheetCellRangesEnumeration()
55 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
59 uno::Reference
<uno::XInterface
> ScIndexEnumeration_SheetCellRangesEnumeration::init()
61 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
62 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
64 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
65 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
66 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
68 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xDoc
, uno::UNO_QUERY_THROW
);
69 uno::Reference
<sheet::XSheetCellRanges
> xSCR(
70 xMSF
->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW
);
71 uno::Reference
<container::XNameContainer
> xNC(xSCR
, uno::UNO_QUERY_THROW
);
75 aRange
<<= xSheet0
->getCellRangeByName("C1:D4");
76 xNC
->insertByName("Range1", aRange
);
77 aRange
<<= xSheet0
->getCellRangeByName("E2:F5");
78 xNC
->insertByName("Range2", aRange
);
79 aRange
<<= xSheet0
->getCellRangeByName("G2:H3");
80 xNC
->insertByName("Range3", aRange
);
81 aRange
<<= xSheet0
->getCellRangeByName("I7:J8");
82 xNC
->insertByName("Range4", aRange
);
84 for (auto x
= 0; x
< 10; ++x
)
86 for (auto y
= 0; y
< 5; ++y
)
88 xSheet0
->getCellByPosition(x
, y
)->setFormula("a");
91 for (auto x
= 0; x
< 10; ++x
)
93 for (auto y
= 5; y
< 10; ++y
)
95 xSheet0
->getCellByPosition(x
, y
)->setValue(x
+ y
);
98 uno::Reference
<container::XEnumerationAccess
> xEA(xSCR
, uno::UNO_QUERY_THROW
);
100 return xEA
->createEnumeration();
103 void ScIndexEnumeration_SheetCellRangesEnumeration::setUp()
105 CalcUnoApiTest::setUp();
106 m_xComponent
= loadFromDesktop("private:factory/scalc");
107 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
110 void ScIndexEnumeration_SheetCellRangesEnumeration::tearDown()
112 closeDocument(m_xComponent
);
113 CalcUnoApiTest::tearDown();
116 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_SheetCellRangesEnumeration
);
118 } // namespace sc_apitest
120 CPPUNIT_PLUGIN_IMPLEMENT();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */