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/sheet/xnamedrange.hxx>
12 #include <com/sun/star/beans/XPropertySet.hpp>
13 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
14 #include <com/sun/star/sheet/XSpreadsheet.hpp>
15 #include <com/sun/star/table/XCellRange.hpp>
16 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
17 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
18 #include <com/sun/star/sheet/XNamedRanges.hpp>
19 #include <com/sun/star/sheet/XNamedRange.hpp>
20 #include <com/sun/star/table/XCell.hpp>
21 #include <com/sun/star/text/XTextRange.hpp>
23 #include <com/sun/star/table/CellAddress.hpp>
24 #include <com/sun/star/table/CellRangeAddress.hpp>
25 #include <com/sun/star/sheet/Border.hpp>
26 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
28 #include "cppunit/extensions/HelperMacros.h"
29 #include <rtl/ustring.hxx>
32 using namespace css::uno
;
36 void XNamedRange::testGetContent()
38 OUString
aTestedNamedRangeString("initial1");
39 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
41 OUString
aExpectedContent("$Sheet1.$B$1");
42 CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 on GetContent", xNamedRange
->getContent().equals(aExpectedContent
));
45 void XNamedRange::testSetContent()
47 OUString
aTestedNamedRangeString("initial1");
48 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
50 OUString aExpectedContent
;
53 aExpectedContent
= "D1";
54 xNamedRange
->setContent(aExpectedContent
);
55 CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cell", xNamedRange
->getContent().equals(aExpectedContent
));
58 aExpectedContent
= "D1:D10";
59 xNamedRange
->setContent(aExpectedContent
);
60 CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", xNamedRange
->getContent().equals(aExpectedContent
));
63 aExpectedContent
= "=D10";
64 xNamedRange
->setContent(aExpectedContent
);
65 aExpectedContent
= "D10";
66 CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a formula", xNamedRange
->getContent().equals(aExpectedContent
));
70 void XNamedRange::testGetType()
72 OUString
aTestedNamedRangeString("initial1");
73 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
74 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type", xNamedRange
->getType() == 0);
77 void XNamedRange::testSetType()
79 OUString
aTestedNamedRangeString("initial1");
80 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
82 sal_Int32 nType
= ::sheet::NamedRangeFlag::ROW_HEADER
;;
83 xNamedRange
->setType(nType
);
84 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type ROW_HEADER after setting it", xNamedRange
->getType() == nType
);
86 nType
= ::sheet::NamedRangeFlag::COLUMN_HEADER
;
87 xNamedRange
->setType(nType
);
88 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", xNamedRange
->getType() == nType
);
90 nType
= ::sheet::NamedRangeFlag::FILTER_CRITERIA
;
91 xNamedRange
->setType(nType
);
92 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", xNamedRange
->getType() == nType
);
94 nType
= ::sheet::NamedRangeFlag::PRINT_AREA
;
95 xNamedRange
->setType(nType
);
96 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type PRINT_AREA after setting it", xNamedRange
->getType() == nType
);
99 xNamedRange
->setType(nType
);
100 CPPUNIT_ASSERT_MESSAGE("Wrong expected Type 0 after setting it", xNamedRange
->getType() == nType
);
103 void XNamedRange::testGetReferencePosition()
105 OUString
aTestedNamedRangeString("initial2");
106 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
108 table::CellAddress xCellAddress
= xNamedRange
->getReferencePosition();
109 // the expected address is on B1, as it was the active cell when intial2 created
110 CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position", xCellAddress
.Sheet
== 0);
111 CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position", xCellAddress
.Column
== 1);
112 CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position", xCellAddress
.Row
== 0);
115 void XNamedRange::testSetReferencePosition()
117 OUString
aTestedNamedRangeString("initial1");
118 uno::Reference
< sheet::XNamedRange
> xNamedRange
= getNamedRange(aTestedNamedRangeString
);
120 table::CellAddress aBaseAddress
= table::CellAddress(1,2,3);
122 xNamedRange
->setReferencePosition(aBaseAddress
);
124 table::CellAddress xCellAddress
= xNamedRange
->getReferencePosition();
125 CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position after setting it", xCellAddress
.Sheet
== 1);
126 CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position after setting it", xCellAddress
.Column
== 2);
127 CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position after setting it", xCellAddress
.Row
== 3);
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */