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/xelementaccess.hxx>
12 #include <test/container/xenumerationaccess.hxx>
13 #include <test/container/xindexaccess.hxx>
14 #include <test/container/xnameaccess.hxx>
15 #include <test/lang/xserviceinfo.hxx>
16 #include <test/table/xtablecolumns.hxx>
17 #include <cppu/unotype.hxx>
19 #include <com/sun/star/container/XIndexAccess.hpp>
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/sheet/XSpreadsheet.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/sheet/XSpreadsheets.hpp>
24 #include <com/sun/star/table/XCellRange.hpp>
25 #include <com/sun/star/table/XColumnRowRange.hpp>
26 #include <com/sun/star/table/XTableColumns.hpp>
27 #include <com/sun/star/text/XSimpleText.hpp>
28 #include <com/sun/star/uno/XInterface.hpp>
30 #include <com/sun/star/uno/Reference.hxx>
36 class ScTableColumnsObj
: public CalcUnoApiTest
,
37 public apitest::XElementAccess
,
38 public apitest::XEnumerationAccess
,
39 public apitest::XIndexAccess
,
40 public apitest::XNameAccess
,
41 public apitest::XServiceInfo
,
42 public apitest::XTableColumns
47 virtual uno::Reference
<uno::XInterface
> init() override
;
48 virtual void setUp() override
;
49 virtual void tearDown() override
;
51 CPPUNIT_TEST_SUITE(ScTableColumnsObj
);
54 CPPUNIT_TEST(testGetElementType
);
55 CPPUNIT_TEST(testHasElements
);
58 CPPUNIT_TEST(testCreateEnumeration
);
61 CPPUNIT_TEST(testGetByIndex
);
62 CPPUNIT_TEST(testGetCount
);
65 CPPUNIT_TEST(testGetByName
);
66 CPPUNIT_TEST(testGetElementNames
);
67 CPPUNIT_TEST(testHasByName
);
70 CPPUNIT_TEST(testGetImplementationName
);
71 CPPUNIT_TEST(testGetSupportedServiceNames
);
72 CPPUNIT_TEST(testSupportsService
);
75 CPPUNIT_TEST(testInsertByIndex
);
76 CPPUNIT_TEST(testInsertByIndexWithNegativeIndex
);
77 CPPUNIT_TEST(testInsertByIndexWithNoColumn
);
78 CPPUNIT_TEST(testInsertByIndexWithOutOfBoundIndex
);
79 CPPUNIT_TEST(testRemoveByIndex
);
80 CPPUNIT_TEST(testRemoveByIndexWithNegativeIndex
);
81 CPPUNIT_TEST(testRemoveByIndexWithNoColumn
);
82 CPPUNIT_TEST(testRemoveByIndexWithOutOfBoundIndex
);
84 CPPUNIT_TEST_SUITE_END();
87 uno::Reference
<lang::XComponent
> m_xComponent
;
90 ScTableColumnsObj::ScTableColumnsObj()
91 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
92 , XElementAccess(cppu::UnoType
<table::XCellRange
>::get())
95 , XServiceInfo("ScTableColumnsObj", "com.sun.star.table.TableColumns")
99 uno::Reference
<uno::XInterface
> ScTableColumnsObj::init()
101 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
102 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
103 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
104 uno::Reference
<sheet::XSpreadsheet
> xSheet0(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
106 uno::Reference
<table::XColumnRowRange
> xCRR(xSheet0
, uno::UNO_QUERY_THROW
);
107 uno::Reference
<table::XTableColumns
> xTC(xCRR
->getColumns(), uno::UNO_SET_THROW
);
108 setXSpreadsheet(xSheet0
);
110 uno::Reference
<table::XCellRange
> xCR(xSheet0
, uno::UNO_QUERY_THROW
);
111 for (auto i
= 0; i
< xTC
->getCount() - 1 && i
< 3; ++i
)
113 uno::Reference
<text::XSimpleText
> xST0(xCR
->getCellByPosition(i
, 0), uno::UNO_QUERY_THROW
);
114 xST0
->setString(OUString::number(i
) + "a");
115 uno::Reference
<text::XSimpleText
> xST1(xCR
->getCellByPosition(i
, 1), uno::UNO_QUERY_THROW
);
116 xST1
->setString(OUString::number(i
) + "b");
118 for (auto i
= 3; i
< xTC
->getCount() - 1 && i
< 10; ++i
)
120 uno::Reference
<text::XSimpleText
> xST0(xCR
->getCellByPosition(i
, 0), uno::UNO_QUERY_THROW
);
122 uno::Reference
<text::XSimpleText
> xST1(xCR
->getCellByPosition(i
, 1), uno::UNO_QUERY_THROW
);
128 void ScTableColumnsObj::setUp()
130 CalcUnoApiTest::setUp();
131 // create calc document
132 m_xComponent
= loadFromDesktop("private:factory/scalc");
135 void ScTableColumnsObj::tearDown()
137 closeDocument(m_xComponent
);
138 CalcUnoApiTest::tearDown();
141 CPPUNIT_TEST_SUITE_REGISTRATION(ScTableColumnsObj
);
143 } // namespace sc_apitest
145 CPPUNIT_PLUGIN_IMPLEMENT();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */