nss: upgrade to release 3.73
[LibreOffice.git] / test / source / sheet / xsubtotalcalculatable.cxx
blob3a85c923bfaf0daac4aea5c360befd9987e11d2c
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.
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 */
10 #include <test/sheet/xsubtotalcalculatable.hxx>
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>
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;
26 namespace apitest {
28 void XSubTotalCalculatable::testCreateSubTotalDescriptor()
30 uno::Reference< sheet::XSubTotalCalculatable > xSTC(init(), uno::UNO_QUERY_THROW);
31 uno::Reference< sheet::XSubTotalDescriptor > xSTD = xSTC->createSubTotalDescriptor(true);
33 uno::Sequence< sheet::SubTotalColumn > xCols;
34 xCols.realloc(1);
35 xCols[0].Column = 5;
36 xCols[0].Function = sheet::GeneralFunction_SUM;
38 CPPUNIT_ASSERT_NO_THROW_MESSAGE("Unable to create XSubTotalDescriptor", xSTD->addNew(xCols, 1));
41 void XSubTotalCalculatable::testApplyRemoveSubTotals()
43 uno::Reference< sheet::XSpreadsheet > xSheet(getXSpreadsheet(), UNO_QUERY_THROW);
44 uno::Reference< sheet::XSubTotalCalculatable > xSTC(xSheet, UNO_QUERY_THROW);
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);
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);
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());
66 xSTC->removeSubTotals();
67 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to remove SubTotals",
68 OUString(""),
69 xSheet->getCellByPosition(0, 3)->getFormula());
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */