LibreOffice Module test (master) 1
xcalculatable.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
11
12#include <com/sun/star/sheet/XCalculatable.hpp>
13#include <com/sun/star/table/XCell.hpp>
14
15#include <com/sun/star/uno/Reference.hxx>
16#include <com/sun/star/uno/Sequence.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace com::sun::star;
21using namespace com::sun::star::uno;
22
23namespace apitest
24{
26{
27 uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW);
28
29 bool bIsAutomaticCalculationEnabled = xCalculatable->isAutomaticCalculationEnabled();
30 xCalculatable->enableAutomaticCalculation(!bIsAutomaticCalculationEnabled);
31 bool bIsAutomaticCalculationEnabledNew = xCalculatable->isAutomaticCalculationEnabled();
32 CPPUNIT_ASSERT_MESSAGE("Unable to set enableAutomaticCalculation()",
33 bIsAutomaticCalculationEnabled != bIsAutomaticCalculationEnabledNew);
34}
35
37{
38 uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW);
39 xCalculatable->enableAutomaticCalculation(false);
40
41 uno::Sequence<uno::Reference<table::XCell>> xCells = getXCells();
42
43 double dProduct = xCells[2]->getValue();
44 double dFactor1 = xCells[0]->getValue();
45 xCells[0]->setValue(dFactor1 + 1.0);
46 double dProduct2 = xCells[2]->getValue();
47 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculated products are equal", dProduct, dProduct2, 0.5);
48
49 xCalculatable->calculate();
50 dProduct2 = xCells[2]->getValue();
51 CPPUNIT_ASSERT_MESSAGE("Calculated products are not equal", dProduct != dProduct2);
52}
53
55{
56 uno::Reference<sheet::XCalculatable> xCalculatable(init(), UNO_QUERY_THROW);
57 xCalculatable->enableAutomaticCalculation(false);
58
59 uno::Sequence<uno::Reference<table::XCell>> xCells = getXCells();
60
61 double dProduct = xCells[2]->getValue();
62 double dFactor1 = xCells[0]->getValue();
63 xCells[0]->setValue(dFactor1 + 1.0);
64 double dProduct2 = xCells[2]->getValue();
65 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Calculated products are equal", dProduct, dProduct2, 0.5);
66
67 xCalculatable->calculateAll();
68 dProduct2 = xCells[2]->getValue();
69 CPPUNIT_ASSERT_MESSAGE("Calculated products are not equal", dProduct != dProduct2);
70 xCalculatable->calculateAll();
71}
72} // namespace apitest
73
74/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0
virtual css::uno::Sequence< css::uno::Reference< css::table::XCell > > getXCells()=0