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>
14 #include <com/sun/star/container/XIndexAccess.hpp>
15 #include <com/sun/star/lang/XComponent.hpp>
16 #include <com/sun/star/sheet/XCellRangesQuery.hpp>
17 #include <com/sun/star/sheet/XSheetCellRanges.hpp>
18 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
19 #include <com/sun/star/sheet/XSpreadsheets.hpp>
20 #include <com/sun/star/table/XCell.hpp>
21 #include <com/sun/star/table/XCellRange.hpp>
22 #include <com/sun/star/text/XTextRange.hpp>
23 #include <com/sun/star/uno/XInterface.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
27 #include <cppu/unotype.hxx>
30 using namespace css::uno
;
34 class ScCellsObj
: public CalcUnoApiTest
,
35 public apitest::XElementAccess
,
36 public apitest::XEnumerationAccess
41 virtual uno::Reference
<uno::XInterface
> init() override
;
42 virtual void setUp() override
;
43 virtual void tearDown() override
;
45 CPPUNIT_TEST_SUITE(ScCellsObj
);
48 CPPUNIT_TEST(testHasElements
);
49 CPPUNIT_TEST(testGetElementType
);
52 CPPUNIT_TEST(testCreateEnumeration
);
54 CPPUNIT_TEST_SUITE_END();
57 uno::Reference
<lang::XComponent
> m_xComponent
;
60 ScCellsObj::ScCellsObj()
61 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
62 , XElementAccess(cppu::UnoType
<table::XCell
>::get())
66 uno::Reference
<uno::XInterface
> ScCellsObj::init()
68 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(m_xComponent
, uno::UNO_QUERY_THROW
);
69 CPPUNIT_ASSERT_MESSAGE("no calc document", xDoc
.is());
71 uno::Reference
<sheet::XSpreadsheets
> xSheets(xDoc
->getSheets(), uno::UNO_SET_THROW
);
72 uno::Reference
<container::XIndexAccess
> xIA(xSheets
, uno::UNO_QUERY_THROW
);
73 uno::Reference
<table::XCellRange
> xCellRange(xIA
->getByIndex(0), uno::UNO_QUERY_THROW
);
75 uno::Reference
<table::XCell
> xCell0(xCellRange
->getCellByPosition(0, 0), uno::UNO_SET_THROW
);
76 uno::Reference
<text::XTextRange
> xTextRange0(xCell0
, uno::UNO_QUERY_THROW
);
77 xTextRange0
->setString("ScCellsObj test 1");
79 uno::Reference
<table::XCell
> xCell1(xCellRange
->getCellByPosition(5, 1), uno::UNO_SET_THROW
);
82 uno::Reference
<table::XCell
> xCell2(xCellRange
->getCellByPosition(3, 9), uno::UNO_SET_THROW
);
83 uno::Reference
<text::XTextRange
> xTextRange2(xCell2
, uno::UNO_QUERY_THROW
);
84 xTextRange2
->setString("ScCellsObj test 2");
86 uno::Reference
<sheet::XCellRangesQuery
> xCRQ(xCellRange
, uno::UNO_QUERY_THROW
);
87 uno::Reference
<sheet::XSheetCellRanges
> xSCR(xCRQ
->queryVisibleCells(), uno::UNO_SET_THROW
);
89 return xSCR
->getCells();
92 void ScCellsObj::setUp()
94 CalcUnoApiTest::setUp();
95 m_xComponent
= loadFromDesktop("private:factory/scalc");
96 CPPUNIT_ASSERT_MESSAGE("no component", m_xComponent
.is());
99 void ScCellsObj::tearDown()
101 closeDocument(m_xComponent
);
102 CalcUnoApiTest::tearDown();
105 CPPUNIT_TEST_SUITE_REGISTRATION(ScCellsObj
);
107 } // namespace sc_apitest
109 CPPUNIT_PLUGIN_IMPLEMENT();
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */