LibreOffice Module test (master) 1
xnamedrange.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/XNamedRange.hpp>
13#include <com/sun/star/table/CellAddress.hpp>
14#include <com/sun/star/sheet/NamedRangeFlag.hpp>
15
16#include <cppunit/TestAssert.h>
17#include <rtl/ustring.hxx>
18
19using namespace css;
20using namespace css::uno;
21
22namespace apitest {
23
25{
26 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
27
28 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected content for initial1 on GetContent", OUString("$Sheet1.$B$1"), xNamedRange->getContent());
29}
30
32{
33 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
34
35 OUString aExpectedContent;
36
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());
41
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());
46
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());
52}
53
55{
56 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
57 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type", sal_Int32(0), xNamedRange->getType());
58}
59
61{
62 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
63
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());
67
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());
71
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());
75
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());
79
80 nType = 0;
81 xNamedRange->setType(nType);
82 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong expected Type 0 after setting it", nType, xNamedRange->getType());
83}
84
86{
87 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial2");
88
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);
94}
95
97{
98 uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange("initial1");
99
100 table::CellAddress aBaseAddress(1,2,3);
101
102 xNamedRange->setReferencePosition(aBaseAddress);
103
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);
108}
109
110}
111
112/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::sheet::XNamedRange > getNamedRange(const OUString &)=0
void testSetReferencePosition()
Definition: xnamedrange.cxx:96
void testGetReferencePosition()
Definition: xnamedrange.cxx:85
QPRO_FUNC_TYPE nType