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 
23 using namespace com::sun::star;
24 using namespace com::sun::star::uno;
25 
26 namespace apitest {
27 
28 void XSubTotalCalculatable::testCreateSubTotalDescriptor()
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;
34  xCols.realloc(1);
35  xCols[0].Column = 5;
36  xCols[0].Function = sheet::GeneralFunction_SUM;
37 
38  CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSubTotalDescriptor", xSTD->addNew(xCols, 1));
39 }
40 
41 void XSubTotalCalculatable::testApplyRemoveSubTotals()
42 {
43  uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
44  uno::Reference< sheet::XSubTotalCalculatable > xSTC(xSheet, UNO_QUERY_THROW);
45 
46  uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true);
47  uno::Sequence< sheet::SubTotalColumn > xCols;
48  xCols.realloc(1);
49  xCols[0].Column = 0;
50  xCols[0].Function = sheet::GeneralFunction_SUM;
51  xSTD->addNew(xCols, 1);
52 
53  xSheet->getCellByPosition(0, 0)->setFormula("first");
54  xSheet->getCellByPosition(1, 0)->setFormula("second");
55  xSheet->getCellByPosition(0, 3)->setFormula("");
56  xSheet->getCellByPosition(0, 1)->setValue(5);
57  xSheet->getCellByPosition(0, 2)->setValue(5);
58  xSheet->getCellByPosition(1, 1)->setValue(17);
59  xSheet->getCellByPosition(1, 2)->setValue(17);
60 
61  xSTC->applySubTotals(xSTD, true);
62  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to apply SubTotals",
63  OUString("=SUBTOTAL(9;$A$2:$A$3)"),
64  xSheet->getCellByPosition(0, 3)->getFormula());
65 
66  xSTC->removeSubTotals();
67  CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove SubTotals",
68  OUString(""),
69  xSheet->getCellByPosition(0, 3)->getFormula());
70 }
71 
72 }
73 
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
FILE * init(int, char **)