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/sheet/xsheetcellcursor.hxx>
12 #include <com/sun/star/sheet/XArrayFormulaRange.hpp>
13 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
14 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
15 #include <com/sun/star/sheet/XSheetOperation.hpp>
16 #include <com/sun/star/sheet/XSpreadsheet.hpp>
17 #include <com/sun/star/table/CellRangeAddress.hpp>
18 #include <com/sun/star/table/XCellRange.hpp>
19 #include <com/sun/star/table/XColumnRowRange.hpp>
20 #include <com/sun/star/util/XMergeable.hpp>
22 #include <com/sun/star/uno/Reference.hxx>
24 #include <cppunit/TestAssert.h>
26 using namespace com::sun::star
;
27 using namespace com::sun::star::uno
;
31 void XSheetCellCursor::testCollapseToCurrentArray()
33 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
35 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xSheetCellCursor
,
37 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
38 const sal_Int32 nHeight
= aCellRangeAddr
.EndRow
- aCellRangeAddr
.StartRow
+ 1;
40 uno::Reference
<table::XCellRange
> xCellRange
41 = xSheetCellCursor
->getCellRangeByPosition(0, 0, 0, nHeight
- 1);
42 uno::Reference
<sheet::XArrayFormulaRange
> xArrayFormulaRange(xCellRange
, UNO_QUERY_THROW
);
43 xArrayFormulaRange
->setArrayFormula("A1:A" + OUString::number(nHeight
));
45 xSheetCellCursor
->collapseToSize(1, 1);
46 xSheetCellCursor
->collapseToCurrentArray();
48 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
49 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentArray (cols)", sal_Int32(1),
50 xColRowRange
->getColumns()->getCount());
51 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentArray (rows)", nHeight
,
52 xColRowRange
->getRows()->getCount());
53 xArrayFormulaRange
->setArrayFormula("");
56 void XSheetCellCursor::testCollapseToCurrentRegion()
58 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
60 const sal_Int32 nWidth
= 4, nHeight
= 4;
61 uno::Reference
<sheet::XSpreadsheet
> xSheet
= xSheetCellCursor
->getSpreadsheet();
62 uno::Reference
<sheet::XSheetOperation
> xSheetOp(xSheet
, UNO_QUERY_THROW
);
63 xSheetOp
->clearContents(65535);
65 xSheetCellCursor
->collapseToCurrentRegion();
66 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentRegion (cols)", nWidth
,
68 xColRowRange
->getColumns()->getCount());
69 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToCurrentRegion (rows)", nHeight
,
70 xColRowRange
->getRows()->getCount());
73 void XSheetCellCursor::testCollapseToMergedArea()
75 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
76 xSheetCellCursor
->collapseToSize(1, 1);
78 const sal_Int32 nLeftCol
= 0, nTopRow
= 0, nWidth
= 8, nHeight
= 8;
79 uno::Reference
<sheet::XSpreadsheet
> xSheet
= xSheetCellCursor
->getSpreadsheet();
81 uno::Reference
<table::XCellRange
> xCellRange
= xSheet
->getCellRangeByPosition(
82 nLeftCol
+ nWidth
- 8, nTopRow
+ nHeight
- 8, nLeftCol
+ nWidth
, nTopRow
+ nHeight
);
84 uno::Reference
<util::XMergeable
> xMergeable(xCellRange
, UNO_QUERY_THROW
);
85 xMergeable
->merge(true);
86 CPPUNIT_ASSERT_MESSAGE("Unable to merge area", xMergeable
->getIsMerged());
87 xSheetCellCursor
->collapseToMergedArea();
88 xMergeable
->merge(false);
90 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
91 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToMergedArea (cols)", nWidth
+ 1,
92 xColRowRange
->getColumns()->getCount());
93 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToMergedArea (rows)", nHeight
+ 1,
94 xColRowRange
->getRows()->getCount());
97 void XSheetCellCursor::testCollapseToSize()
99 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
101 const sal_Int32 nWidth
= 1, nHeight
= 1;
102 xSheetCellCursor
->collapseToSize(nWidth
+ 3, nHeight
+ 3);
104 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToSize (cols)", nWidth
+ 3,
106 xColRowRange
->getColumns()->getCount());
107 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to collapseToSize (rows)", nHeight
+ 3,
108 xColRowRange
->getRows()->getCount());
111 void XSheetCellCursor::testExpandToEntireColumns()
113 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
115 xSheetCellCursor
->expandToEntireColumns();
117 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
118 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to expandToEntireColumns (cols)", sal_Int32(4),
119 xColRowRange
->getColumns()->getCount());
120 CPPUNIT_ASSERT_MESSAGE("Unable to expandToEntireColumns (rows)",
121 xColRowRange
->getRows()->getCount() >= sal_Int32(32000));
124 void XSheetCellCursor::testExpandToEntireRows()
126 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(init(), UNO_QUERY_THROW
);
128 xSheetCellCursor
->expandToEntireRows();
130 uno::Reference
<table::XColumnRowRange
> xColRowRange(xSheetCellCursor
, UNO_QUERY_THROW
);
131 CPPUNIT_ASSERT_MESSAGE("Unable to expandToEntireRows (cols)",
132 xColRowRange
->getColumns()->getCount() >= sal_Int32(256));
133 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to expandToEntireRows (rows)", sal_Int32(4),
134 xColRowRange
->getRows()->getCount());
138 /* vim:set shiftnWidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */