LibreOffice Module test (master) 1
xsheetfilterable.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/beans/XPropertySet.hpp>
13#include <com/sun/star/sheet/FilterOperator.hpp>
14#include <com/sun/star/sheet/TableFilterField.hpp>
15#include <com/sun/star/sheet/XSheetFilterable.hpp>
16#include <com/sun/star/sheet/XSheetFilterDescriptor.hpp>
17#include <com/sun/star/sheet/XSpreadsheet.hpp>
18#include <com/sun/star/table/XColumnRowRange.hpp>
19#include <com/sun/star/table/XTableRows.hpp>
20#include <com/sun/star/uno/Reference.hxx>
21#include <com/sun/star/uno/Sequence.hxx>
22
23#include <cppunit/TestAssert.h>
24
25using namespace css;
26using namespace css::uno;
27
28namespace apitest {
29
31{
32 uno::Reference< sheet::XSheetFilterable > xFA(init(), UNO_QUERY_THROW);
33 uno::Reference< sheet::XSheetFilterDescriptor > xSFD = xFA->createFilterDescriptor(true);
34
35 uno::Sequence< sheet::TableFilterField > xTFF{
36 { /* Connection */ {},
37 /* Field */ 0,
38 /* Operator */ sheet::FilterOperator_GREATER_EQUAL,
39 /* IsNumeric */ true,
40 /* NumericValue */ 2,
41 /* StringValue */ {}},
42 { /* Connection */ {},
43 /* Field */ 1,
44 /* Operator */ sheet::FilterOperator_LESS,
45 /* IsNumeric */ false,
46 /* NumericValue */ {},
47 /* StringValue */ "C" }
48 };
49
50 CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSheetFilterDescriptor", xSFD->setFilterFields(xTFF));
51}
52
54{
55 uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
56
57 uno::Reference< sheet::XSheetFilterable > xFA(xSheet, UNO_QUERY_THROW);
58 uno::Reference< sheet::XSheetFilterDescriptor > xSFD = xFA->createFilterDescriptor(true);
59
60 uno::Sequence< sheet::TableFilterField > xTFF{
61 { /* Connection */ {},
62 /* Field */ 0,
63 /* Operator */ sheet::FilterOperator_GREATER_EQUAL,
64 /* IsNumeric */ true,
65 /* NumericValue */ 2,
66 /* StringValue */ {}},
67 { /* Connection */ {},
68 /* Field */ 1,
69 /* Operator */ sheet::FilterOperator_LESS,
70 /* IsNumeric */ false,
71 /* NumericValue */ {},
72 /* StringValue */ "C" }
73 };
74 xSFD->setFilterFields(xTFF);
75
76 xSheet->getCellByPosition(0, 0)->setValue(1);
77 xSheet->getCellByPosition(0, 1)->setValue(2);
78 xSheet->getCellByPosition(0, 2)->setValue(3);
79 xSheet->getCellByPosition(1, 0)->setFormula("A");
80 xSheet->getCellByPosition(1, 1)->setFormula("B");
81 xSheet->getCellByPosition(1, 2)->setFormula("C");
82 xFA->filter(xSFD);
83
84 uno::Reference< table::XColumnRowRange > xColRowRange(xSheet, UNO_QUERY_THROW);
85 uno::Reference< table::XTableRows > xTableRows = xColRowRange->getRows();
86 uno::Reference< beans::XPropertySet > xRowProps(xTableRows->getByIndex(0), UNO_QUERY_THROW);
87 bool bIsVisible = true;
88 CPPUNIT_ASSERT(xRowProps->getPropertyValue("IsVisible") >>= bIsVisible);
89
90 CPPUNIT_ASSERT_MESSAGE("Row 1 should be invisible", !bIsVisible);
91}
92
93}
94
95/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > getXSpreadsheet()=0
virtual css::uno::Reference< css::uno::XInterface > init()=0