LibreOffice Module test (master)  1
xformulaquery.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 
12 
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>
20 
21 #include <cppunit/TestAssert.h>
22 
23 using namespace com::sun::star;
24 using namespace com::sun::star::uno;
25 
26 namespace apitest
27 {
28 void XFormulaQuery::testQueryDependents()
29 {
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);
35 
36  uno::Reference<table::XCell> xCell = getXCell();
37  xCell->setFormula("=SUM(A1:D1)");
38 
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();
42 
43  CPPUNIT_ASSERT_EQUAL(aCellRangeAddress[m_nIdxDependents], m_aCellRangeAddressDependents);
44 }
45 
46 void XFormulaQuery::testQueryPrecedents()
47 {
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");
54 
55  uno::Reference<table::XCell> xCell = getXCell();
56  xCell->setFormula("=SUM(A1:D1)");
57 
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();
61 
62  CPPUNIT_ASSERT_EQUAL(aCellRangeAddress[m_nIdxPrecedents], m_aCellRangeAddressPrecedents);
63 }
64 } // namespace apitest
65 
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
FILE * init(int, char **)