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