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/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 UnoApiTest
,
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
;
47 virtual uno::Reference
<uno::XInterface
> getXSpreadsheet() override
;
48 virtual uno::Reference
<uno::XInterface
> init() override
;
50 CPPUNIT_TEST_SUITE(ScCellRangesObj
);
53 CPPUNIT_TEST(testSheetCellRangesProperties
);
56 CPPUNIT_TEST(testCreateEnumeration
);
59 CPPUNIT_TEST(testQueryDependents
);
60 CPPUNIT_TEST(testQueryPrecedents
);
63 CPPUNIT_TEST(testIncrementIndent
);
64 CPPUNIT_TEST(testDecrementIndent
);
66 // XSheetCellRangeContainer
67 CPPUNIT_TEST(testAddRemoveRangeAddress
);
68 CPPUNIT_TEST(testAddRemoveRangeAddresses
);
71 CPPUNIT_TEST(testGetCells
);
72 CPPUNIT_TEST(testGetRangeAddresses
);
73 CPPUNIT_TEST(testGetRangeAddressesAsString
);
76 CPPUNIT_TEST(testComputeFunction
);
77 CPPUNIT_TEST(testClearContents
);
79 CPPUNIT_TEST_SUITE_END();
82 ScCellRangesObj::ScCellRangesObj()
83 : UnoApiTest(u
"/sc/qa/extras/testdocuments"_ustr
)
84 , apitest::XFormulaQuery(table::CellRangeAddress(0, 4, 1, 5, 4),
85 table::CellRangeAddress(0, 4, 1, 5, 4))
89 uno::Reference
<uno::XInterface
> ScCellRangesObj::init()
91 uno::Reference
<sheet::XSpreadsheetDocument
> xDoc(mxComponent
, uno::UNO_QUERY_THROW
);
93 uno::Reference
<container::XIndexAccess
> xIndexAccess(xDoc
->getSheets(), uno::UNO_QUERY_THROW
);
94 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndexAccess
->getByIndex(0), uno::UNO_QUERY_THROW
);
95 uno::Reference
<lang::XMultiServiceFactory
> xMSF(xDoc
, uno::UNO_QUERY_THROW
);
96 uno::Reference
<container::XNameContainer
> xRanges(
97 xMSF
->createInstance(u
"com.sun.star.sheet.SheetCellRanges"_ustr
), uno::UNO_QUERY_THROW
);
100 xCellRange
<<= xSheet
->getCellRangeByName(u
"C1:D4"_ustr
);
101 xRanges
->insertByName(u
"Range1"_ustr
, xCellRange
);
102 xCellRange
<<= xSheet
->getCellRangeByName(u
"E2:F5"_ustr
);
103 xRanges
->insertByName(u
"Range2"_ustr
, xCellRange
);
104 xCellRange
<<= xSheet
->getCellRangeByName(u
"G2:H3"_ustr
);
105 xRanges
->insertByName(u
"Range3"_ustr
, xCellRange
);
106 xCellRange
<<= xSheet
->getCellRangeByName(u
"I7:J8"_ustr
);
107 xRanges
->insertByName(u
"Range4"_ustr
, xCellRange
);
109 for (int i
= 0; i
< 10; i
++)
111 for (int j
= 5; j
< 10; j
++)
113 xSheet
->getCellByPosition(i
, j
)->setValue(i
+ j
);
120 uno::Reference
<uno::XInterface
> ScCellRangesObj::getXSpreadsheet()
122 uno::Reference
<sheet::XSpreadsheetDocument
> xSheetDoc(mxComponent
, uno::UNO_QUERY_THROW
);
124 uno::Reference
<sheet::XSpreadsheets
> xSheets(xSheetDoc
->getSheets(), UNO_SET_THROW
);
125 uno::Reference
<container::XIndexAccess
> xIndex(xSheets
, UNO_QUERY_THROW
);
126 uno::Reference
<sheet::XSpreadsheet
> xSheet(xIndex
->getByIndex(0), UNO_QUERY_THROW
);
128 setXCell(xSheet
->getCellByPosition(15, 15));
133 void ScCellRangesObj::setUp()
136 // create a calc document
137 loadFromURL(u
"private:factory/scalc"_ustr
);
140 CPPUNIT_TEST_SUITE_REGISTRATION(ScCellRangesObj
);
143 CPPUNIT_PLUGIN_IMPLEMENT();
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */