bump product version to 7.2.5.1
[LibreOffice.git] / test / source / sheet / xnamedrange.cxx
blobea9fb778199abc8149db8294ce663fd5ba5b3bcc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
10 #include <test/sheet/xnamedrange.hxx>
12 #include <com/sun/star/sheet/XNamedRange.hpp>
13 #include <com/sun/star/table/CellAddress.hpp>
14 #include <com/sun/star/sheet/NamedRangeFlag.hpp>
16 #include <cppunit/TestAssert.h>
17 #include <rtl/ustring.hxx>
19 using namespace css;
20 using namespace css::uno;
22 namespace apitest {
24 void XNamedRange::testGetContent()
26 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
28 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 on GetContent", OUString("$Sheet1.$B$1"), xNamedRange->getContent());
31 void XNamedRange::testSetContent()
33 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
35 OUString aExpectedContent;
37 // test a cell
38 aExpectedContent = "D1";
39 xNamedRange->setContent(aExpectedContent);
40 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a cell", aExpectedContent, xNamedRange->getContent());
42 // test a cellrange
43 aExpectedContent = "D1:D10";
44 xNamedRange->setContent(aExpectedContent);
45 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", aExpectedContent, xNamedRange->getContent());
47 // test a formula
48 aExpectedContent = "=D10";
49 xNamedRange->setContent(aExpectedContent);
50 aExpectedContent = "D10";
51 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 after SetContent a formula", aExpectedContent, xNamedRange->getContent());
54 void XNamedRange::testGetType()
56 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type", sal_Int32(0), xNamedRange->getType());
60 void XNamedRange::testSetType()
62 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
64 sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER;
65 xNamedRange->setType(nType);
66 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type ROW_HEADER after setting it", nType, xNamedRange->getType());
68 nType = ::sheet::NamedRangeFlag::COLUMN_HEADER;
69 xNamedRange->setType(nType);
70 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", nType, xNamedRange->getType());
72 nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA;
73 xNamedRange->setType(nType);
74 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", nType, xNamedRange->getType());
76 nType = ::sheet::NamedRangeFlag::PRINT_AREA;
77 xNamedRange->setType(nType);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type PRINT_AREA after setting it", nType, xNamedRange->getType());
80 nType = 0;
81 xNamedRange->setType(nType);
82 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type 0 after setting it", nType, xNamedRange->getType());
85 void XNamedRange::testGetReferencePosition()
87 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial2");
89 table::CellAddress aCellAddress = xNamedRange->getReferencePosition();
90 // the expected address is on B1, as it was the active cell when initial2 was created
91 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SHEET reference position", sal_Int16(0), aCellAddress.Sheet);
92 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong COLUMN reference position", sal_Int32(1), aCellAddress.Column);
93 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong ROW reference position", sal_Int32(0), aCellAddress.Row);
96 void XNamedRange::testSetReferencePosition()
98 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
100 table::CellAddress aBaseAddress(1,2,3);
102 xNamedRange->setReferencePosition(aBaseAddress);
104 table::CellAddress aCellAddress = xNamedRange->getReferencePosition();
105 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong SHEET reference position after setting it", sal_Int16(1), aCellAddress.Sheet);
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong COLUMN reference position after setting it", sal_Int32(2), aCellAddress.Column);
107 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong ROW reference position after setting it", sal_Int32(3), aCellAddress.Row);
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */