Branch data 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) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (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/xdatabaserange.hxx>
30 : :
31 : : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
32 : : #include <com/sun/star/sheet/XSpreadsheet.hpp>
33 : : #include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
34 : : #include <com/sun/star/beans/PropertyValue.hpp>
35 : : #include <com/sun/star/sheet/XDatabaseRange.hpp>
36 : : #include <com/sun/star/sheet/XDatabaseRanges.hpp>
37 : : #include <com/sun/star/table/CellRangeAddress.hpp>
38 : : #include <com/sun/star/util/XCloseable.hpp>
39 : : #include <com/sun/star/beans/XPropertySet.hpp>
40 : : #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
41 : : #include <com/sun/star/table/XCell.hpp>
42 : : #include <com/sun/star/table/XTableRows.hpp>
43 : : #include <com/sun/star/table/XColumnRowRange.hpp>
44 : :
45 : : #include <rtl/oustringostreaminserter.hxx>
46 : : #include "cppunit/extensions/HelperMacros.h"
47 : : #include <iostream>
48 : :
49 : : using namespace com::sun::star::uno;
50 : :
51 : : namespace apitest {
52 : :
53 : : /**
54 : : * tests setDataArea and getDataArea
55 : : */
56 : 2 : void XDatabaseRange::testDataArea()
57 : : {
58 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataArea"))), UNO_QUERY_THROW);
[ + - ]
59 : :
60 : 2 : table::CellRangeAddress aCellAddress;
61 : 2 : aCellAddress.Sheet = 0;
62 : 2 : aCellAddress.StartColumn = 1;
63 : 2 : aCellAddress.EndColumn = 4;
64 : 2 : aCellAddress.StartRow = 2;
65 : 2 : aCellAddress.EndRow = 5;
66 [ + - ][ + - ]: 2 : xDBRange->setDataArea(aCellAddress);
67 : 2 : table::CellRangeAddress aValue;
68 [ + - ][ + - ]: 2 : aValue = xDBRange->getDataArea();
69 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aCellAddress.Sheet == aValue.Sheet );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
70 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aCellAddress.StartRow == aValue.StartRow );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
71 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aCellAddress.EndRow == aValue.EndRow );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
72 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aCellAddress.StartColumn == aValue.StartColumn );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
73 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT( aCellAddress.EndColumn == aValue.EndColumn );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
74 : 2 : }
75 : :
76 : 2 : void XDatabaseRange::testGetSubtotalDescriptor()
77 : : {
78 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubtotalDescriptor"))), UNO_QUERY_THROW);
[ + - ]
79 [ + - ][ + - ]: 2 : uno::Reference< sheet::XSubTotalDescriptor> xSubtotalDescr = xDBRange->getSubTotalDescriptor();
80 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(xSubtotalDescr.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
81 : 2 : }
82 : :
83 : 2 : void XDatabaseRange::testGetSortDescriptor()
84 : : {
85 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SortDescriptor"))), UNO_QUERY_THROW);
[ + - ]
86 [ + - ][ + - ]: 2 : uno::Sequence< beans::PropertyValue > xSortDescr = xDBRange->getSortDescriptor();
87 [ + + ]: 20 : for (sal_Int32 i = 0; i < xSortDescr.getLength(); ++i)
88 : : {
89 [ + - ]: 18 : beans::PropertyValue xProp = xSortDescr[i];
90 : : //std::cout << "Prop " << i << " Name: " << rtl::OUString(xProp.Name) << std::endl;
91 : :
92 [ + + ][ + - ]: 18 : if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")))
93 : : {
94 : 2 : sal_Bool bIsSortColumns = sal_True;
95 : 2 : xProp.Value >>= bIsSortColumns;
96 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(bIsSortColumns == sal_True);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
97 : : }
98 [ + - ][ + + ]: 16 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContainsHeader")))
99 : : {
100 : 2 : sal_Bool bContainsHeader = sal_True;
101 : 2 : xProp.Value >>= bContainsHeader;
102 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(bContainsHeader == sal_True);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
103 : : }
104 [ + - ][ + + ]: 14 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxFieldCount")))
105 : : {
106 : 2 : sal_Int32 nMaxFieldCount = 0;
107 : 2 : xProp.Value >>= nMaxFieldCount;
108 [ + - ][ + - ]: 2 : std::cout << "Value: " << nMaxFieldCount << std::endl;
[ + - ]
109 : :
110 : : }
111 [ + - ][ + + ]: 12 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SortFields")))
112 : : {
113 : :
114 : : }
115 [ + - ][ + + ]: 10 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BindFormatsToContent")))
116 : : {
117 : 2 : sal_Bool bBindFormatsToContent = sal_False;
118 : 2 : xProp.Value >>= bBindFormatsToContent;
119 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(bBindFormatsToContent == sal_True);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
120 : : }
121 [ + - ][ + + ]: 8 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyOutputData")))
122 : : {
123 : 2 : sal_Bool bCopyOutputData = sal_True;
124 : 2 : xProp.Value >>= bCopyOutputData;
125 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(bCopyOutputData == sal_False);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
126 : : }
127 [ + - ][ + + ]: 6 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutputPosition")))
128 : : {
129 : :
130 : : }
131 [ + - ][ + + ]: 4 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsUserListEnabled")))
132 : : {
133 : 2 : sal_Bool bIsUserListEnabled = sal_True;
134 : 2 : xProp.Value >>= bIsUserListEnabled;
135 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(bIsUserListEnabled == sal_False);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
136 : :
137 : : }
138 [ + - ][ + - ]: 2 : else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UserListIndex")))
139 : : {
140 : 2 : sal_Int32 nUserListIndex = 1;
141 : 2 : xProp.Value >>= nUserListIndex;
142 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(nUserListIndex == 0);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
143 : : }
144 [ + - ]: 20 : }
145 : 2 : }
146 : :
147 : 2 : void XDatabaseRange::testGetFilterDescriptor()
148 : : {
149 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FilterDescriptor"))), UNO_QUERY_THROW);
[ + - ]
150 [ + - ][ + - ]: 2 : uno::Reference< uno::XInterface > xFilterDescr( xDBRange->getFilterDescriptor(), UNO_QUERY_THROW);
[ + - ]
151 [ + - ][ + - ]: 2 : CPPUNIT_ASSERT(xFilterDescr.is());
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
152 : 2 : }
153 : :
154 : 2 : void XDatabaseRange::testGetImportDescriptor()
155 : : {
156 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImportDescriptor"))), UNO_QUERY_THROW);
[ + - ]
157 [ + - ][ + - ]: 2 : uno::Sequence< beans::PropertyValue > xImportDescr = xDBRange->getImportDescriptor();
[ + - ]
158 : 2 : }
159 : :
160 : 2 : void XDatabaseRange::testRefresh()
161 : : {
162 [ + - ][ + - ]: 2 : uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Refresh"))), UNO_QUERY_THROW);
[ + - ]
163 : :
164 : 2 : const sal_Int32 nCol = 0;
165 [ + - ]: 2 : rtl::OUString aHidden(RTL_CONSTASCII_USTRINGPARAM("IsVisible"));
166 [ + - ]: 2 : uno::Reference< sheet::XCellRangeReferrer > xCellRangeReferrer(xDBRange, UNO_QUERY_THROW);
167 [ + - ][ + - ]: 2 : uno::Reference< table::XCellRange > xCellRange = xCellRangeReferrer->getReferredCells();
168 : :
169 [ + + ]: 10 : for (sal_Int32 i = 1; i < 5; ++i)
170 : : {
171 [ + - ][ + - ]: 8 : uno::Reference< table::XCell > xCell = xCellRange->getCellByPosition(nCol, i);
172 [ + - ][ + - ]: 8 : xCell->setValue(0);
173 : 8 : }
174 : :
175 [ + + ]: 8 : for (sal_Int32 i = 2; i < 5; ++i)
176 : : {
177 [ + - ]: 6 : uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
178 [ + - ][ + - ]: 6 : uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
179 [ + - ][ + - ]: 6 : uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
[ + - ]
180 [ + - ]: 6 : uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
181 [ + - ][ + - ]: 6 : Any aAny = xPropRow->getPropertyValue( aHidden );
182 : :
183 [ + - ][ + - ]: 6 : CPPUNIT_ASSERT(aAny.get<sal_Bool>() == sal_True);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
184 : 6 : }
185 : :
186 [ + - ][ + - ]: 2 : xDBRange->refresh();
187 [ + - ][ + - ]: 2 : std::cout << "after refresh" << std::endl;
188 : :
189 [ + + ]: 10 : for (sal_Int32 i = 1; i < 5; ++i)
190 : : {
191 [ + - ]: 8 : uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
192 [ + - ][ + - ]: 8 : uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
193 [ + - ][ + - ]: 8 : uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
[ + - ]
194 [ + - ]: 8 : uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
195 [ + - ][ + - ]: 8 : Any aAny = xPropRow->getPropertyValue( aHidden );
196 : :
197 [ + - ][ + - ]: 8 : CPPUNIT_ASSERT(aAny.get<sal_Bool>() == sal_False);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
198 : 10 : }
199 : :
200 : :
201 : 2 : }
202 : :
203 [ + - ][ + - ]: 66 : }
204 : :
205 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|