bump product version to 6.3.0.0.beta1
[LibreOffice.git] / test / source / sheet / xdatabaserange.cxx
blob36ce1d5362fb0f8fd6896b6d4699ab6e0e64781b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <test/sheet/xdatabaserange.hxx>
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>
26 #include <rtl/ustring.hxx>
27 #include <cppunit/extensions/HelperMacros.h>
28 #include <iostream>
30 using namespace css;
31 using namespace css::uno;
33 namespace apitest {
35 /**
36 * tests setDataArea and getDataArea
38 void XDatabaseRange::testDataArea()
40 uno::Reference< sheet::XDatabaseRange > xDBRange(init("DataArea"), UNO_QUERY_THROW);
42 table::CellRangeAddress aCellAddress;
43 aCellAddress.Sheet = 0;
44 aCellAddress.StartColumn = 1;
45 aCellAddress.EndColumn = 4;
46 aCellAddress.StartRow = 2;
47 aCellAddress.EndRow = 5;
48 xDBRange->setDataArea(aCellAddress);
49 table::CellRangeAddress aValue = xDBRange->getDataArea();
50 CPPUNIT_ASSERT_EQUAL( aCellAddress.Sheet, aValue.Sheet );
51 CPPUNIT_ASSERT_EQUAL( aCellAddress.StartRow, aValue.StartRow );
52 CPPUNIT_ASSERT_EQUAL( aCellAddress.EndRow, aValue.EndRow );
53 CPPUNIT_ASSERT_EQUAL( aCellAddress.StartColumn, aValue.StartColumn );
54 CPPUNIT_ASSERT_EQUAL( aCellAddress.EndColumn, aValue.EndColumn );
57 void XDatabaseRange::testGetSubtotalDescriptor()
59 uno::Reference< sheet::XDatabaseRange > xDBRange(init("SubtotalDescriptor"), UNO_QUERY_THROW);
60 uno::Reference< sheet::XSubTotalDescriptor> xSubtotalDescr = xDBRange->getSubTotalDescriptor();
61 CPPUNIT_ASSERT(xSubtotalDescr.is());
64 void XDatabaseRange::testGetSortDescriptor()
66 uno::Reference< sheet::XDatabaseRange > xDBRange(init("SortDescriptor"), UNO_QUERY_THROW);
67 uno::Sequence< beans::PropertyValue > xSortDescr = xDBRange->getSortDescriptor();
68 for (sal_Int32 i = 0; i < xSortDescr.getLength(); ++i)
70 beans::PropertyValue aProp = xSortDescr[i];
71 //std::cout << "Prop " << i << " Name: " << OUString(aProp.Name) << std::endl;
73 if (aProp.Name == "IsSortColumns")
75 bool bIsSortColumns = true;
76 aProp.Value >>= bIsSortColumns;
77 CPPUNIT_ASSERT(bIsSortColumns);
79 else if (aProp.Name == "ContainsHeader")
81 bool bContainsHeader = true;
82 aProp.Value >>= bContainsHeader;
83 CPPUNIT_ASSERT(bContainsHeader);
85 else if (aProp.Name == "MaxFieldCount")
87 sal_Int32 nMaxFieldCount = 0;
88 aProp.Value >>= nMaxFieldCount;
89 std::cout << "Value: " << nMaxFieldCount << std::endl;
92 else if (aProp.Name == "SortFields")
96 else if (aProp.Name == "BindFormatsToContent")
98 bool bBindFormatsToContent = false;
99 aProp.Value >>= bBindFormatsToContent;
100 CPPUNIT_ASSERT(bBindFormatsToContent);
102 else if (aProp.Name == "CopyOutputData")
104 bool bCopyOutputData = true;
105 aProp.Value >>= bCopyOutputData;
106 CPPUNIT_ASSERT(!bCopyOutputData);
108 else if (aProp.Name == "OutputPosition")
112 else if (aProp.Name == "IsUserListEnabled")
114 bool bIsUserListEnabled = true;
115 aProp.Value >>= bIsUserListEnabled;
116 CPPUNIT_ASSERT(!bIsUserListEnabled);
119 else if (aProp.Name == "UserListIndex")
121 sal_Int32 nUserListIndex = 1;
122 aProp.Value >>= nUserListIndex;
123 CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nUserListIndex);
128 void XDatabaseRange::testGetFilterDescriptor()
130 uno::Reference< sheet::XDatabaseRange > xDBRange( init("FilterDescriptor"), UNO_QUERY_THROW);
131 uno::Reference< uno::XInterface > xFilterDescr( xDBRange->getFilterDescriptor(), UNO_QUERY_THROW);
134 void XDatabaseRange::testGetImportDescriptor()
136 uno::Reference< sheet::XDatabaseRange > xDBRange( init("ImportDescriptor"), UNO_QUERY_THROW);
137 uno::Sequence< beans::PropertyValue > xImportDescr = xDBRange->getImportDescriptor();
138 (void) xImportDescr;
141 void XDatabaseRange::testRefresh()
143 uno::Reference< sheet::XDatabaseRange > xDBRange( init("Refresh"), UNO_QUERY_THROW);
145 const sal_Int32 nCol = 0;
146 OUString aHidden("IsVisible");
147 uno::Reference< sheet::XCellRangeReferrer > xCellRangeReferrer(xDBRange, UNO_QUERY_THROW);
148 uno::Reference< table::XCellRange > xCellRange = xCellRangeReferrer->getReferredCells();
150 for (sal_Int32 i = 1; i < 5; ++i)
152 uno::Reference< table::XCell > xCell = xCellRange->getCellByPosition(nCol, i);
153 xCell->setValue(0);
156 for (sal_Int32 i = 2; i < 5; ++i)
158 uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
159 uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
160 uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
161 uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
162 Any aAny = xPropRow->getPropertyValue( aHidden );
164 CPPUNIT_ASSERT(aAny.get<bool>());
167 xDBRange->refresh();
168 std::cout << "after refresh" << std::endl;
170 for (sal_Int32 i = 1; i < 5; ++i)
172 uno::Reference< table::XColumnRowRange > xColRowRange(xCellRange, UNO_QUERY_THROW);
173 uno::Reference< table::XTableRows > xRows = xColRowRange->getRows();
174 uno::Reference< table::XCellRange > xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
175 uno::Reference< beans::XPropertySet > xPropRow(xRow, UNO_QUERY_THROW);
176 Any aAny = xPropRow->getPropertyValue( aHidden );
178 CPPUNIT_ASSERT(!aAny.get<bool>());
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */