Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / test / source / sheet / xdatabaserange.cxx
blobf57e3d37fcdd8abd4712087443c2c77a988a6e8f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
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/
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.
15 * Major Contributor(s):
16 * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
18 * All Rights Reserved.
20 * For minor contributions see the git repository.
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.
29 #include <test/sheet/xdatabaserange.hxx>
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>
45 #include <rtl/ustring.hxx>
46 #include "cppunit/extensions/HelperMacros.h"
47 #include <iostream>
49 using namespace com::sun::star::uno;
51 namespace apitest {
53 /**
54 * tests setDataArea and getDataArea
56 void XDatabaseRange::testDataArea()
58 uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DataArea"))), UNO_QUERY_THROW);
60 table::CellRangeAddress aCellAddress;
61 aCellAddress.Sheet = 0;
62 aCellAddress.StartColumn = 1;
63 aCellAddress.EndColumn = 4;
64 aCellAddress.StartRow = 2;
65 aCellAddress.EndRow = 5;
66 xDBRange->setDataArea(aCellAddress);
67 table::CellRangeAddress aValue;
68 aValue = xDBRange->getDataArea();
69 CPPUNIT_ASSERT( aCellAddress.Sheet == aValue.Sheet );
70 CPPUNIT_ASSERT( aCellAddress.StartRow == aValue.StartRow );
71 CPPUNIT_ASSERT( aCellAddress.EndRow == aValue.EndRow );
72 CPPUNIT_ASSERT( aCellAddress.StartColumn == aValue.StartColumn );
73 CPPUNIT_ASSERT( aCellAddress.EndColumn == aValue.EndColumn );
76 void XDatabaseRange::testGetSubtotalDescriptor()
78 uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SubtotalDescriptor"))), UNO_QUERY_THROW);
79 uno::Reference< sheet::XSubTotalDescriptor> xSubtotalDescr = xDBRange->getSubTotalDescriptor();
80 CPPUNIT_ASSERT(xSubtotalDescr.is());
83 void XDatabaseRange::testGetSortDescriptor()
85 uno::Reference< sheet::XDatabaseRange > xDBRange(init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SortDescriptor"))), UNO_QUERY_THROW);
86 uno::Sequence< beans::PropertyValue > xSortDescr = xDBRange->getSortDescriptor();
87 for (sal_Int32 i = 0; i < xSortDescr.getLength(); ++i)
89 beans::PropertyValue xProp = xSortDescr[i];
90 //std::cout << "Prop " << i << " Name: " << rtl::OUString(xProp.Name) << std::endl;
92 if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSortColumns")))
94 sal_Bool bIsSortColumns = sal_True;
95 xProp.Value >>= bIsSortColumns;
96 CPPUNIT_ASSERT(bIsSortColumns == sal_True);
98 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContainsHeader")))
100 sal_Bool bContainsHeader = sal_True;
101 xProp.Value >>= bContainsHeader;
102 CPPUNIT_ASSERT(bContainsHeader == sal_True);
104 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MaxFieldCount")))
106 sal_Int32 nMaxFieldCount = 0;
107 xProp.Value >>= nMaxFieldCount;
108 std::cout << "Value: " << nMaxFieldCount << std::endl;
111 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SortFields")))
115 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BindFormatsToContent")))
117 sal_Bool bBindFormatsToContent = sal_False;
118 xProp.Value >>= bBindFormatsToContent;
119 CPPUNIT_ASSERT(bBindFormatsToContent == sal_True);
121 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CopyOutputData")))
123 sal_Bool bCopyOutputData = sal_True;
124 xProp.Value >>= bCopyOutputData;
125 CPPUNIT_ASSERT(bCopyOutputData == sal_False);
127 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutputPosition")))
131 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsUserListEnabled")))
133 sal_Bool bIsUserListEnabled = sal_True;
134 xProp.Value >>= bIsUserListEnabled;
135 CPPUNIT_ASSERT(bIsUserListEnabled == sal_False);
138 else if (xProp.Name == rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UserListIndex")))
140 sal_Int32 nUserListIndex = 1;
141 xProp.Value >>= nUserListIndex;
142 CPPUNIT_ASSERT(nUserListIndex == 0);
147 void XDatabaseRange::testGetFilterDescriptor()
149 uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FilterDescriptor"))), UNO_QUERY_THROW);
150 uno::Reference< uno::XInterface > xFilterDescr( xDBRange->getFilterDescriptor(), UNO_QUERY_THROW);
151 CPPUNIT_ASSERT(xFilterDescr.is());
154 void XDatabaseRange::testGetImportDescriptor()
156 uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImportDescriptor"))), UNO_QUERY_THROW);
157 uno::Sequence< beans::PropertyValue > xImportDescr = xDBRange->getImportDescriptor();
160 void XDatabaseRange::testRefresh()
162 uno::Reference< sheet::XDatabaseRange > xDBRange( init(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Refresh"))), UNO_QUERY_THROW);
164 const sal_Int32 nCol = 0;
165 rtl::OUString aHidden(RTL_CONSTASCII_USTRINGPARAM("IsVisible"));
166 uno::Reference< sheet::XCellRangeReferrer > xCellRangeReferrer(xDBRange, UNO_QUERY_THROW);
167 uno::Reference< table::XCellRange > xCellRange = xCellRangeReferrer->getReferredCells();
169 for (sal_Int32 i = 1; i < 5; ++i)
171 uno::Reference< table::XCell > xCell = xCellRange->getCellByPosition(nCol, i);
172 xCell->setValue(0);
175 for (sal_Int32 i = 2; i < 5; ++i)
177 uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
178 uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
179 uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
180 uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
181 Any aAny = xPropRow->getPropertyValue( aHidden );
183 CPPUNIT_ASSERT(aAny.get<sal_Bool>() == sal_True);
186 xDBRange->refresh();
187 std::cout << "after refresh" << std::endl;
189 for (sal_Int32 i = 1; i < 5; ++i)
191 uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
192 uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
193 uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
194 uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
195 Any aAny = xPropRow->getPropertyValue( aHidden );
197 CPPUNIT_ASSERT(aAny.get<sal_Bool>() == sal_False);
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */