Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2011 Laurent Godard lgodard.libre@laposte.net (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <test/sheet/xnamedrange.hxx>
30 :
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
33 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
34 : #include <com/sun/star/table/XCellRange.hpp>
35 : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
36 : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
37 : #include <com/sun/star/sheet/XNamedRanges.hpp>
38 : #include <com/sun/star/sheet/XNamedRange.hpp>
39 : #include <com/sun/star/table/XCell.hpp>
40 : #include <com/sun/star/text/XTextRange.hpp>
41 :
42 : #include <com/sun/star/table/CellAddress.hpp>
43 : #include <com/sun/star/table/CellRangeAddress.hpp>
44 : #include <com/sun/star/sheet/Border.hpp>
45 : #include <com/sun/star/sheet/NamedRangeFlag.hpp>
46 :
47 : #include "cppunit/extensions/HelperMacros.h"
48 : #include <rtl/ustring.hxx>
49 :
50 : using namespace com::sun::star::uno;
51 :
52 : namespace apitest {
53 :
54 0 : void XNamedRange::testGetContent()
55 : {
56 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
57 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
58 :
59 0 : rtl::OUString aExpectedContent(RTL_CONSTASCII_USTRINGPARAM("$Sheet1.$B$1"));
60 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 on GetContent", xNamedRange->getContent().equals(aExpectedContent));
61 0 : }
62 :
63 0 : void XNamedRange::testSetContent()
64 : {
65 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
66 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
67 :
68 0 : rtl::OUString aExpectedContent;
69 :
70 : // test a cell
71 0 : aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D1"));
72 0 : xNamedRange->setContent(aExpectedContent);
73 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cell", xNamedRange->getContent().equals(aExpectedContent));
74 :
75 : // test a cellrange
76 0 : aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D1:D10"));
77 0 : xNamedRange->setContent(aExpectedContent);
78 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a cellrange", xNamedRange->getContent().equals(aExpectedContent));
79 :
80 : // test a formula
81 0 : aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("=D10"));
82 0 : xNamedRange->setContent(aExpectedContent);
83 0 : aExpectedContent = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("D10"));
84 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected content for initial1 after SetContent a formula", xNamedRange->getContent().equals(aExpectedContent));
85 :
86 0 : }
87 :
88 0 : void XNamedRange::testGetType()
89 : {
90 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
91 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
92 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type", xNamedRange->getType() == 0);
93 0 : }
94 :
95 0 : void XNamedRange::testSetType()
96 : {
97 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
98 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
99 :
100 0 : sal_Int32 nType = ::sheet::NamedRangeFlag::ROW_HEADER;;
101 0 : xNamedRange->setType(nType);
102 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type ROW_HEADER after setting it", xNamedRange->getType() == nType);
103 :
104 0 : nType = ::sheet::NamedRangeFlag::COLUMN_HEADER;
105 0 : xNamedRange->setType(nType);
106 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type COLUMN_HEADER after setting it", xNamedRange->getType() == nType);
107 :
108 0 : nType = ::sheet::NamedRangeFlag::FILTER_CRITERIA;
109 0 : xNamedRange->setType(nType);
110 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type FILTER_CRITERIA after setting it", xNamedRange->getType() == nType);
111 :
112 0 : nType = ::sheet::NamedRangeFlag::PRINT_AREA;
113 0 : xNamedRange->setType(nType);
114 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type PRINT_AREA after setting it", xNamedRange->getType() == nType);
115 :
116 0 : nType = 0;
117 0 : xNamedRange->setType(nType);
118 0 : CPPUNIT_ASSERT_MESSAGE("Wrong expected Type 0 after setting it", xNamedRange->getType() == nType);
119 0 : }
120 :
121 0 : void XNamedRange::testGetReferencePosition()
122 : {
123 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial2"));
124 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
125 :
126 0 : table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
127 : // the expeted address is on B1, as it was the active cell when intial2 created
128 0 : CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position", xCellAddress.Sheet == 0);
129 0 : CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position", xCellAddress.Column == 1);
130 0 : CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position", xCellAddress.Row == 0);
131 0 : }
132 :
133 0 : void XNamedRange::testSetReferencePosition()
134 : {
135 0 : rtl::OUString aTestedNamedRangeString(RTL_CONSTASCII_USTRINGPARAM("initial1"));
136 0 : uno::Reference< sheet::XNamedRange > xNamedRange = getNamedRange(aTestedNamedRangeString);
137 :
138 0 : table::CellAddress aBaseAddress = table::CellAddress(1,2,3);
139 :
140 0 : xNamedRange->setReferencePosition(aBaseAddress);
141 :
142 0 : table::CellAddress xCellAddress = xNamedRange->getReferencePosition();
143 0 : CPPUNIT_ASSERT_MESSAGE("Wrong SHEET reference position after setting it", xCellAddress.Sheet == 1);
144 0 : CPPUNIT_ASSERT_MESSAGE("Wrong COLUMN reference position after setting it", xCellAddress.Column == 2);
145 0 : CPPUNIT_ASSERT_MESSAGE("Wrong ROW reference position after setting it", xCellAddress.Row == 3);
146 0 : }
147 :
148 :
149 :
150 0 : }
151 :
152 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|