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/table/xcellcursor.hxx>
12 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
13 #include <com/sun/star/sheet/XSheetCellCursor.hpp>
14 #include <com/sun/star/sheet/XSheetCellRange.hpp>
15 #include <com/sun/star/sheet/XSpreadsheet.hpp>
16 #include <com/sun/star/table/CellRangeAddress.hpp>
17 #include <com/sun/star/table/XCellCursor.hpp>
18 #include <com/sun/star/table/XCellRange.hpp>
20 #include <com/sun/star/uno/Reference.hxx>
22 #include <cppunit/TestAssert.h>
24 using namespace com::sun::star
;
25 using namespace com::sun::star::uno
;
29 void XCellCursor::testGoToNext()
31 uno::Reference
<table::XCellCursor
> xCellCursor(init(), UNO_QUERY_THROW
);
33 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xCellCursor
,
35 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
36 const sal_Int32 startCol
= aCellRangeAddr
.StartColumn
;
38 xCellCursor
->gotoNext();
40 aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
41 const sal_Int32 startCol2
= aCellRangeAddr
.StartColumn
;
43 CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Next", startCol
!= startCol2
);
46 void XCellCursor::testGoToOffset()
48 uno::Reference
<table::XCellCursor
> xCellCursor(init(), UNO_QUERY_THROW
);
50 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xCellCursor
,
52 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
53 const sal_Int32 startRow
= aCellRangeAddr
.StartRow
;
54 const sal_Int32 startCol
= aCellRangeAddr
.StartColumn
;
56 xCellCursor
->gotoOffset(4, 4);
58 aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
59 const sal_Int32 startRow2
= aCellRangeAddr
.StartRow
;
60 const sal_Int32 startCol2
= aCellRangeAddr
.StartColumn
;
62 CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Offset",
63 (startCol
!= startCol2
) || (startRow
== startRow2
));
66 void XCellCursor::testGoToPrevious()
68 uno::Reference
<table::XCellCursor
> xCellCursor(init(), UNO_QUERY_THROW
);
70 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xCellCursor
,
72 xCellCursor
->gotoOffset(4, 4);
74 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
75 const sal_Int32 startCol
= aCellRangeAddr
.StartColumn
;
77 xCellCursor
->gotoPrevious();
79 aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
80 const sal_Int32 startCol2
= aCellRangeAddr
.StartColumn
;
81 CPPUNIT_ASSERT_MESSAGE("Successfully able to go to Previous", startCol
!= startCol2
);
84 void XCellCursor::testGoToStart()
86 uno::Reference
<table::XCellCursor
> xCellCursor(init(), UNO_QUERY_THROW
);
88 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xCellCursor
,
90 xCellCursor
->gotoStart();
92 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
94 const sal_Int32 startRow
= aCellRangeAddr
.StartRow
;
95 const sal_Int32 startCol
= aCellRangeAddr
.StartColumn
;
96 const sal_Int32 endRow
= aCellRangeAddr
.EndRow
;
97 const sal_Int32 endCol
= aCellRangeAddr
.EndColumn
;
98 CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to Start", startCol
, endCol
);
99 CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to Start", endRow
, startRow
);
102 void XCellCursor::testGoToEnd()
104 uno::Reference
<table::XCellCursor
> xCellCursor(init(), UNO_QUERY_THROW
);
105 uno::Reference
<sheet::XSpreadsheet
> xSpreadsheet(getXSpreadsheet(), UNO_QUERY_THROW
);
106 uno::Reference
<table::XCellRange
> xCellRange(xCellCursor
, UNO_QUERY_THROW
);
107 xCellRange
= xSpreadsheet
->getCellRangeByName("$A$1:$g$7");
108 uno::Reference
<sheet::XSheetCellRange
> xSheetCellRange(xCellCursor
, UNO_QUERY_THROW
);
109 uno::Reference
<sheet::XSheetCellCursor
> xSheetCellCursor(xCellCursor
, UNO_QUERY_THROW
);
110 xSheetCellCursor
= xSpreadsheet
->createCursorByRange(xSheetCellRange
);
111 uno::Reference
<sheet::XCellRangeAddressable
> xCellRangeAddressable(xCellCursor
,
114 xCellCursor
->gotoEnd();
116 table::CellRangeAddress aCellRangeAddr
= xCellRangeAddressable
->getRangeAddress();
117 const sal_Int32 startRow
= aCellRangeAddr
.StartRow
;
118 const sal_Int32 startCol
= aCellRangeAddr
.StartColumn
;
119 const sal_Int32 endRow
= aCellRangeAddr
.EndRow
;
120 const sal_Int32 endCol
= aCellRangeAddr
.EndColumn
;
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to End", startCol
, endCol
);
122 CPPUNIT_ASSERT_EQUAL_MESSAGE("Successfully able to go to End", endRow
, startRow
);
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */