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 
26 using namespace css;
27 using namespace css::uno;
28 
29 namespace apitest
30 {
34 void XDatabaseRange::testDataArea()
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 
53 void XDatabaseRange::testGetSubtotalDescriptor()
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 
60 void XDatabaseRange::testGetSortDescriptor()
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 
119 void XDatabaseRange::testGetFilterDescriptor()
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 
125 void XDatabaseRange::testGetImportDescriptor()
126 {
127  uno::Reference<sheet::XDatabaseRange> xDBRange(init("ImportDescriptor"), UNO_QUERY_THROW);
128  uno::Sequence<beans::PropertyValue> xImportDescr = xDBRange->getImportDescriptor();
129  (void)xImportDescr;
130 }
131 
132 void XDatabaseRange::testRefresh()
133 {
134  uno::Reference<sheet::XDatabaseRange> xDBRange(init("Refresh"), UNO_QUERY_THROW);
135 
136  const sal_Int32 nCol = 0;
137  OUString aHidden("IsVisible");
138  uno::Reference<sheet::XCellRangeReferrer> xCellRangeReferrer(xDBRange, UNO_QUERY_THROW);
139  uno::Reference<table::XCellRange> xCellRange = xCellRangeReferrer->getReferredCells();
140 
141  for (sal_Int32 i = 1; i < 5; ++i)
142  {
143  uno::Reference<table::XCell> xCell = xCellRange->getCellByPosition(nCol, i);
144  xCell->setValue(0);
145  }
146 
147  for (sal_Int32 i = 2; i < 5; ++i)
148  {
149  uno::Reference<table::XColumnRowRange> xColRowRange(xCellRange, UNO_QUERY_THROW);
150  uno::Reference<table::XTableRows> xRows = xColRowRange->getRows();
151  uno::Reference<table::XCellRange> xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
152  uno::Reference<beans::XPropertySet> xPropRow(xRow, UNO_QUERY_THROW);
153  Any aAny = xPropRow->getPropertyValue(aHidden);
154 
155  CPPUNIT_ASSERT(aAny.get<bool>());
156  }
157 
158  xDBRange->refresh();
159  std::cout << "after refresh" << std::endl;
160 
161  for (sal_Int32 i = 1; i < 5; ++i)
162  {
163  uno::Reference<table::XColumnRowRange> xColRowRange(xCellRange, UNO_QUERY_THROW);
164  uno::Reference<table::XTableRows> xRows = xColRowRange->getRows();
165  uno::Reference<table::XCellRange> xRow(xRows->getByIndex(i), UNO_QUERY_THROW);
166  uno::Reference<beans::XPropertySet> xPropRow(xRow, UNO_QUERY_THROW);
167  Any aAny = xPropRow->getPropertyValue(aHidden);
168 
169  CPPUNIT_ASSERT(!aAny.get<bool>());
170  }
171 }
172 }
173 
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< sdbc::XRow > xRow
int i
FILE * init(int, char **)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo