Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / qa / extras / sctablerowsobj.cxx
blobe92e500b172646002471b5674db9fe5e1ebe2533
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/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/container/xindexaccess.hxx>
14 #include <test/lang/xserviceinfo.hxx>
15 #include <test/table/xtablerows.hxx>
17 #include <com/sun/star/container/XNameAccess.hpp>
18 #include <com/sun/star/lang/XComponent.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/table/XCellRange.hpp>
23 #include <com/sun/star/table/XColumnRowRange.hpp>
24 #include <com/sun/star/table/XTableRows.hpp>
25 #include <com/sun/star/uno/XInterface.hpp>
27 #include <com/sun/star/uno/Reference.hxx>
29 #include <cppu/unotype.hxx>
31 using namespace css;
32 using namespace css::uno;
34 namespace sc_apitest
36 class ScTableRowsObj : public CalcUnoApiTest,
37 public apitest::XElementAccess,
38 public apitest::XEnumerationAccess,
39 public apitest::XIndexAccess,
40 public apitest::XServiceInfo,
41 public apitest::XTableRows
43 public:
44 ScTableRowsObj();
46 virtual uno::Reference<uno::XInterface> init() override;
47 virtual uno::Reference<uno::XInterface> getXCellRange() override;
48 virtual void setUp() override;
49 virtual void tearDown() override;
51 CPPUNIT_TEST_SUITE(ScTableRowsObj);
53 // XElementAccess
54 CPPUNIT_TEST(testGetElementType);
55 CPPUNIT_TEST(testHasElements);
57 // XEnumerationAccess
58 CPPUNIT_TEST(testCreateEnumeration);
60 // XIndexAccess
61 CPPUNIT_TEST(testGetByIndex);
62 CPPUNIT_TEST(testGetCount);
64 // XServiceInfo
65 CPPUNIT_TEST(testGetImplementationName);
66 CPPUNIT_TEST(testGetSupportedServiceNames);
67 CPPUNIT_TEST(testSupportsService);
69 // XTableRows
70 CPPUNIT_TEST(testInsertByIndex);
71 CPPUNIT_TEST(testRemoveByIndex);
73 CPPUNIT_TEST_SUITE_END();
75 private:
76 uno::Reference<lang::XComponent> m_xComponent;
79 ScTableRowsObj::ScTableRowsObj()
80 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
81 , XElementAccess(cppu::UnoType<table::XCellRange>::get())
82 , XIndexAccess(1048576)
83 , XServiceInfo("ScTableRowsObj", "com.sun.star.table.TableRows")
87 uno::Reference<uno::XInterface> ScTableRowsObj::init()
89 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
90 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
92 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
93 uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW);
94 uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]),
95 uno::UNO_QUERY_THROW);
97 uno::Reference<table::XColumnRowRange> xCRR(xSheet0, uno::UNO_QUERY_THROW);
98 uno::Reference<table::XTableRows> xTR(xCRR->getRows(), uno::UNO_SET_THROW);
100 return xTR;
103 uno::Reference<uno::XInterface> ScTableRowsObj::getXCellRange()
105 uno::Reference<sheet::XSpreadsheetDocument> xDoc(m_xComponent, uno::UNO_QUERY_THROW);
106 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc.is());
108 uno::Reference<sheet::XSpreadsheets> xSheets(xDoc->getSheets(), uno::UNO_SET_THROW);
109 uno::Reference<container::XNameAccess> xNA(xSheets, uno::UNO_QUERY_THROW);
110 uno::Reference<sheet::XSpreadsheet> xSheet0(xSheets->getByName(xNA->getElementNames()[0]),
111 uno::UNO_QUERY_THROW);
113 uno::Reference<table::XCellRange> xCR(xSheet0, uno::UNO_QUERY_THROW);
114 return xCR;
117 void ScTableRowsObj::setUp()
119 CalcUnoApiTest::setUp();
120 m_xComponent = loadFromDesktop("private:factory/scalc");
121 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent.is());
124 void ScTableRowsObj::tearDown()
126 closeDocument(m_xComponent);
127 CalcUnoApiTest::tearDown();
130 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableRowsObj);
131 } // namespace sc_apitest
133 CPPUNIT_PLUGIN_IMPLEMENT();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */