Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / scindexenumeration_tablerowsenumeration.cxx
blob7a1068a335e48aae01c58df68efca18e9f0a6cf7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <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/XNameAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/XSpreadsheet.hpp>
17 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
18 #include <com/sun/star/sheet/XSpreadsheets.hpp>
19 #include <com/sun/star/table/XCellRange.hpp>
20 #include <com/sun/star/table/XColumnRowRange.hpp>
21 #include <com/sun/star/table/XTableRows.hpp>
22 #include <com/sun/star/uno/XInterface.hpp>
24 #include <com/sun/star/uno/Reference.hxx>
26 using namespace css;
27 using namespace css::uno;
29 namespace sc_apitest
31 class ScIndexEnumeration_TableRowsEnumeration : public CalcUnoApiTest, public apitest::XEnumeration
33 public:
34 ScIndexEnumeration_TableRowsEnumeration();
36 virtual uno::Reference<uno::XInterface> init() override;
37 virtual void setUp() override;
38 virtual void tearDown() override;
40 CPPUNIT_TEST_SUITE(ScIndexEnumeration_TableRowsEnumeration);
42 // XEnumeration
43 CPPUNIT_TEST(testHasMoreElements);
44 CPPUNIT_TEST(testNextElement);
46 CPPUNIT_TEST_SUITE_END();
48 private:
49 uno::Reference<lang::XComponent> m_xComponent;
52 ScIndexEnumeration_TableRowsEnumeration::ScIndexEnumeration_TableRowsEnumeration()
53 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
57 uno::Reference<uno::XInterface> ScIndexEnumeration_TableRowsEnumeration::init()
59 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
60 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
62 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
63 uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW);
64 uno::Reference<sheet::XSpreadsheet> xSheet0(xNA->getByName(xNA->getElementNames()[0]),
65 uno::UNO_QUERY_THROW);
67 // limit the range the XEnumeration has to walk over (see fdo#45337).
68 uno::Reference<table::XCellRange> xCR(xSheet0->getCellRangeByName("A1:A4"), uno::UNO_SET_THROW);
70 uno::Reference<table::XColumnRowRange> xColRowRange(xCR, uno::UNO_QUERY_THROW);
71 uno::Reference<table::XTableRows> xTableRows(xColRowRange->getRows(), uno::UNO_SET_THROW);
72 uno::Reference<container::XEnumerationAccess> xEA(xTableRows, uno::UNO_QUERY_THROW);
74 return xEA->createEnumeration();
77 void ScIndexEnumeration_TableRowsEnumeration::setUp()
79 CalcUnoApiTest::setUp();
80 m_xComponent = loadFromDesktop("private:factory/scalc");
81 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is());
84 void ScIndexEnumeration_TableRowsEnumeration::tearDown()
86 closeDocument(m_xComponent);
87 CalcUnoApiTest::tearDown();
90 CPPUNIT_TEST_SUITE_REGISTRATION(ScIndexEnumeration_TableRowsEnumeration);
92 } // namespace sc_apitest
94 CPPUNIT_PLUGIN_IMPLEMENT();
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */