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