LibreOffice Module test (master) 1
xsheetcellcursor.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
11
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>
21
22#include <com/sun/star/uno/Reference.hxx>
23
24#include <cppunit/TestAssert.h>
25
26using namespace com::sun::star;
27using namespace com::sun::star::uno;
28
29namespace apitest
30{
32{
33 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
34
35 uno::Reference<sheet::XCellRangeAddressable> xCellRangeAddressable(xSheetCellCursor,
36 UNO_QUERY_THROW);
37 table::CellRangeAddress aCellRangeAddr = xCellRangeAddressable->getRangeAddress();
38 const sal_Int32 nHeight = aCellRangeAddr.EndRow - aCellRangeAddr.StartRow + 1;
39
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));
44
45 xSheetCellCursor->collapseToSize(1, 1);
46 xSheetCellCursor->collapseToCurrentArray();
47
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("");
54}
55
57{
58 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
59
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);
64
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());
71}
72
74{
75 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
76 xSheetCellCursor->collapseToSize(1, 1);
77
78 const sal_Int32 nLeftCol = 0, nTopRow = 0, nWidth = 8, nHeight = 8;
79 uno::Reference<sheet::XSpreadsheet> xSheet = xSheetCellCursor->getSpreadsheet();
80
81 uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition(
82 nLeftCol + nWidth - 8, nTopRow + nHeight - 8, nLeftCol + nWidth, nTopRow + nHeight);
83
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);
89
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());
95}
96
98{
99 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
100
101 const sal_Int32 nWidth = 1, nHeight = 1;
102 xSheetCellCursor->collapseToSize(nWidth + 3, nHeight + 3);
103
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());
109}
110
112{
113 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
114
115 xSheetCellCursor->expandToEntireColumns();
116
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));
122}
123
125{
126 uno::Reference<sheet::XSheetCellCursor> xSheetCellCursor(init(), UNO_QUERY_THROW);
127
128 xSheetCellCursor->expandToEntireRows();
129
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());
135}
136}
137
138/* vim:set shiftnWidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0