1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/cppunitasserthelper.hxx>
11 #include <test/sheet/xformulaquery.hxx>
13 #include <com/sun/star/sheet/XFormulaQuery.hpp>
14 #include <com/sun/star/sheet/XSheetCellRanges.hpp>
15 #include <com/sun/star/sheet/XSpreadsheet.hpp>
16 #include <com/sun/star/table/CellRangeAddress.hpp>
17 #include <com/sun/star/table/XCell.hpp>
18 #include <com/sun/star/uno/Reference.hxx>
19 #include <com/sun/star/uno/Sequence.hxx>
21 #include <cppunit/TestAssert.h>
23 using namespace com::sun::star
;
24 using namespace com::sun::star::uno
;
28 void XFormulaQuery::testQueryDependents()
30 uno::Reference
<sheet::XSpreadsheet
> xSheet(getXSpreadsheet(), UNO_QUERY_THROW
);
31 xSheet
->getCellByPosition(0, 0)->setValue(1);
32 xSheet
->getCellByPosition(1, 0)->setValue(1);
33 xSheet
->getCellByPosition(2, 0)->setValue(1);
34 xSheet
->getCellByPosition(3, 0)->setValue(1);
36 uno::Reference
<table::XCell
> xCell
= getXCell();
37 xCell
->setFormula("=SUM(A1:D1)");
39 uno::Reference
<sheet::XFormulaQuery
> xFormulaQuery(init(), UNO_QUERY_THROW
);
40 uno::Reference
<sheet::XSheetCellRanges
> xSCR
= xFormulaQuery
->queryDependents(false);
41 uno::Sequence
<table::CellRangeAddress
> aCellRangeAddress
= xSCR
->getRangeAddresses();
43 CPPUNIT_ASSERT_EQUAL(aCellRangeAddress
[m_nIdxDependents
], m_aCellRangeAddressDependents
);
46 void XFormulaQuery::testQueryPrecedents()
48 uno::Reference
<sheet::XSpreadsheet
> xSheet(getXSpreadsheet(), UNO_QUERY_THROW
);
49 xSheet
->getCellByPosition(0, 0)->setValue(1);
50 xSheet
->getCellByPosition(1, 0)->setValue(1);
51 xSheet
->getCellByPosition(2, 0)->setValue(1);
52 xSheet
->getCellByPosition(3, 0)->setValue(1);
53 xSheet
->getCellByPosition(1, 2)->setFormula("=A16 * 2");
55 uno::Reference
<table::XCell
> xCell
= getXCell();
56 xCell
->setFormula("=SUM(A1:D1)");
58 uno::Reference
<sheet::XFormulaQuery
> xFormulaQuery(init(), UNO_QUERY_THROW
);
59 uno::Reference
<sheet::XSheetCellRanges
> xSCR
= xFormulaQuery
->queryPrecedents(false);
60 uno::Sequence
<table::CellRangeAddress
> aCellRangeAddress
= xSCR
->getRangeAddresses();
62 CPPUNIT_ASSERT_EQUAL(aCellRangeAddress
[m_nIdxPrecedents
], m_aCellRangeAddressPrecedents
);
64 } // namespace apitest
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */