1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/sheet/xsheetfilterable.hxx>
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>
23 #include <cppunit/TestAssert.h>
26 using namespace css::uno
;
30 void XSheetFilterable::testCreateFilterDescriptor()
32 uno::Reference
< sheet::XSheetFilterable
> xFA(init(), UNO_QUERY_THROW
);
33 uno::Reference
< sheet::XSheetFilterDescriptor
> xSFD
= xFA
->createFilterDescriptor(true);
35 uno::Sequence
< sheet::TableFilterField
> xTFF
;
37 xTFF
[0].IsNumeric
= true;
39 xTFF
[0].NumericValue
= 2;
40 xTFF
[0].Operator
= sheet::FilterOperator_GREATER_EQUAL
;
41 xTFF
[1].IsNumeric
= false;
43 xTFF
[1].StringValue
= "C";
44 xTFF
[1].Operator
= sheet::FilterOperator_LESS
;
46 CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSheetFilterDescriptor", xSFD
->setFilterFields(xTFF
));
49 void XSheetFilterable::testFilter()
51 uno::Reference
< sheet::XSpreadsheet
> xSheet(getXSpreadsheet(), UNO_QUERY_THROW
);
53 uno::Reference
< sheet::XSheetFilterable
> xFA(xSheet
, UNO_QUERY_THROW
);
54 uno::Reference
< sheet::XSheetFilterDescriptor
> xSFD
= xFA
->createFilterDescriptor(true);
56 uno::Sequence
< sheet::TableFilterField
> xTFF
;
58 xTFF
[0].IsNumeric
= true;
60 xTFF
[0].NumericValue
= 2;
61 xTFF
[0].Operator
= sheet::FilterOperator_GREATER_EQUAL
;
62 xTFF
[1].IsNumeric
= false;
64 xTFF
[1].StringValue
= "C";
65 xTFF
[1].Operator
= sheet::FilterOperator_LESS
;
66 xSFD
->setFilterFields(xTFF
);
68 xSheet
->getCellByPosition(0, 0)->setValue(1);
69 xSheet
->getCellByPosition(0, 1)->setValue(2);
70 xSheet
->getCellByPosition(0, 2)->setValue(3);
71 xSheet
->getCellByPosition(1, 0)->setFormula("A");
72 xSheet
->getCellByPosition(1, 1)->setFormula("B");
73 xSheet
->getCellByPosition(1, 2)->setFormula("C");
76 uno::Reference
< table::XColumnRowRange
> xColRowRange(xSheet
, UNO_QUERY_THROW
);
77 uno::Reference
< table::XTableRows
> xTableRows
= xColRowRange
->getRows();
78 uno::Reference
< beans::XPropertySet
> xRowProps(xTableRows
->getByIndex(0), UNO_QUERY_THROW
);
79 bool bIsVisible
= true;
80 CPPUNIT_ASSERT(xRowProps
->getPropertyValue("IsVisible") >>= bIsVisible
);
82 CPPUNIT_ASSERT_MESSAGE("Row 1 should be invisible", !bIsVisible
);
87 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */