1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/xenumerationaccess.hxx>
12 #include <test/sheet/sheetcellranges.hxx>
13 #include <test/sheet/xformulaquery.hxx>
14 #include <test/sheet/xsheetcellrangecontainer.hxx>
15 #include <test/sheet/xsheetcellranges.hxx>
16 #include <test/sheet/xsheetoperation.hxx>
17 #include <test/util/xindent.hxx>
19 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
20 #include <com/sun/star/container/XIndexAccess.hpp>
21 #include <com/sun/star/container/XNameContainer.hpp>
22 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
23 #include <com/sun/star/sheet/XSpreadsheet.hpp>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/uno/Reference.hxx>
29 using namespace css::uno
;
33 class ScCellRangesObj
: public CalcUnoApiTest
,
34 public apitest::SheetCellRanges
,
35 public apitest::XEnumerationAccess
,
36 public apitest::XFormulaQuery
,
37 public apitest::XIndent
,
38 public apitest::XSheetCellRangeContainer
,
39 public apitest::XSheetCellRanges
,
40 public apitest::XSheetOperation
45 virtual void setUp() override
;
46 virtual void tearDown() override
;
48 virtual uno::Reference
<uno::XInterface
> getXSpreadsheet() override
;
49 virtual uno::Reference
<uno::XInterface
> init() override
;
51 CPPUNIT_TEST_SUITE(ScCellRangesObj
);
54 CPPUNIT_TEST(testSheetCellRangesProperties
);
57 CPPUNIT_TEST(testCreateEnumeration
);
60 CPPUNIT_TEST(testQueryDependents
);
61 CPPUNIT_TEST(testQueryPrecedents
);
64 CPPUNIT_TEST(testIncrementIndent
);
65 CPPUNIT_TEST(testDecrementIndent
);
67 // XSheetCellRangeContainer
68 CPPUNIT_TEST(testAddRemoveRangeAddress
);
69 CPPUNIT_TEST(testAddRemoveRangeAddresses
);
72 CPPUNIT_TEST(testGetCells
);
73 CPPUNIT_TEST(testGetRangeAddresses
);
74 CPPUNIT_TEST(testGetRangeAddressesAsString
);
77 CPPUNIT_TEST(testComputeFunction
);
78 CPPUNIT_TEST(testClearContents
);
80 CPPUNIT_TEST_SUITE_END();
83 uno::Reference
<lang::XComponent
> mxComponent
;
86 ScCellRangesObj::ScCellRangesObj()
87 : CalcUnoApiTest("/sc/qa/extras/testdocuments")
88 , apitest::XFormulaQuery(table::CellRangeAddress(0, 4, 1, 5, 4),
89 table::CellRangeAddress(0, 4, 1, 5, 4))
93 uno::Reference
<uno::XInterface
> ScCellRangesObj::init()
95 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
97 uno::Reference
<container::XIndexAccess
> xIndexAccess(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
98 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
99 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xDoc
, uno::UNO_QUERY_THROW
);
100 uno::Reference
<container::XNameContainer
> xRanges(
101 xMSF
->createInstance("com.sun.star.sheet.SheetCellRanges"), uno::UNO_QUERY_THROW
);
104 xCellRange
<<= xSheet
->getCellRangeByName("C1:D4");
105 xRanges
->insertByName("Range1", xCellRange
);
106 xCellRange
<<= xSheet
->getCellRangeByName("E2:F5");
107 xRanges
->insertByName("Range2", xCellRange
);
108 xCellRange
<<= xSheet
->getCellRangeByName("G2:H3");
109 xRanges
->insertByName("Range3", xCellRange
);
110 xCellRange
<<= xSheet
->getCellRangeByName("I7:J8");
111 xRanges
->insertByName("Range4", xCellRange
);
113 for (int i
= 0; i
< 10; i
++)
115 for (int j
= 5; j
< 10; j
++)
117 xSheet
->getCellByPosition(i
, j
)->setValue(i
+ j
);
124 uno::Reference
<uno::XInterface
> ScCellRangesObj::getXSpreadsheet()
126 uno::Reference
<sheet::XSpreadsheetDocument
> xSheetDoc(mxComponent
, uno::UNO_QUERY_THROW
);
128 uno::Reference
<sheet::XSpreadsheets
> xSheets(xSheetDoc
->getSheets(), UNO_SET_THROW
);
129 uno::Reference
<container::XIndexAccess
> xIndex(xSheets
, UNO_QUERY_THROW
);
130 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), UNO_QUERY_THROW
);
132 setXCell(xSheet
->getCellByPosition(15, 15));
137 void ScCellRangesObj::setUp()
139 CalcUnoApiTest::setUp();
140 // create a calc document
141 mxComponent
= loadFromDesktop("private:factory/scalc");
144 void ScCellRangesObj::tearDown()
146 closeDocument(mxComponent
);
147 CalcUnoApiTest::tearDown();
150 CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangesObj
);
153 CPPUNIT_PLUGIN_IMPLEMENT();
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */