LibreOffice Module test (master) 1
xsubtotalcalculatable.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/GeneralFunction.hpp>
13#include <com/sun/star/sheet/SubTotalColumn.hpp>
14#include <com/sun/star/sheet/XSpreadsheet.hpp>
15#include <com/sun/star/sheet/XSubTotalCalculatable.hpp>
16#include <com/sun/star/sheet/XSubTotalDescriptor.hpp>
17
18#include <com/sun/star/uno/Reference.hxx>
19#include <com/sun/star/uno/Sequence.hxx>
20
21#include <cppunit/TestAssert.h>
22
23using namespace com::sun::star;
24using namespace com::sun::star::uno;
25
26namespace apitest {
27
29{
30 uno::Reference< sheet::XSubTotalCalculatable > xSTC(init(), uno::UNO_QUERY_THROW);
31 uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true);
32
33 uno::Sequence< sheet::SubTotalColumn > xCols{ { /* Column */ 5,
34 /* Function */ sheet::GeneralFunction_SUM } };
35
36 CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSubTotalDescriptor", xSTD->addNew(xCols, 1));
37}
38
40{
41 uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
42 uno::Reference< sheet::XSubTotalCalculatable > xSTC(xSheet, UNO_QUERY_THROW);
43
44 uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true);
45 uno::Sequence< sheet::SubTotalColumn > xCols{ { /* Column */ 0,
46 /* Function */ sheet::GeneralFunction_SUM } };
47 xSTD->addNew(xCols, 1);
48
49 xSheet->getCellByPosition(0, 0)->setFormula("first");
50 xSheet->getCellByPosition(1, 0)->setFormula("second");
51 xSheet->getCellByPosition(0, 3)->setFormula("");
52 xSheet->getCellByPosition(0, 1)->setValue(5);
53 xSheet->getCellByPosition(0, 2)->setValue(5);
54 xSheet->getCellByPosition(1, 1)->setValue(17);
55 xSheet->getCellByPosition(1, 2)->setValue(17);
56
57 xSTC->applySubTotals(xSTD, true);
58 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to apply SubTotals",
59 OUString("=SUBTOTAL(9;$A$2:$A$3)"),
60 xSheet->getCellByPosition(0, 3)->getFormula());
61
62 xSTC->removeSubTotals();
63 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove SubTotals",
64 OUString(""),
65 xSheet->getCellByPosition(0, 3)->getFormula());
66}
67
68}
69
70/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > getXSpreadsheet()=0
virtual css::uno::Reference< css::uno::XInterface > init()=0