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 
10 #include <test/sheet/xsubtotalfield.hxx>
11 
12 #include <com/sun/star/sheet/GeneralFunction.hpp>
13 #include <com/sun/star/sheet/SubTotalColumn.hpp>
14 #include <com/sun/star/sheet/XSubTotalField.hpp>
15 
16 #include <com/sun/star/uno/Reference.hxx>
17 #include <com/sun/star/uno/Sequence.hxx>
18 
19 #include <cppunit/extensions/HelperMacros.h>
20 
21 using namespace com::sun::star;
22 using namespace com::sun::star::uno;
23 
24 CPPUNIT_NS_BEGIN
25 
26 template<> struct assertion_traits<uno::Sequence< sheet::SubTotalColumn > >
27 {
equalassertion_traits28     static bool equal(const uno::Sequence< sheet::SubTotalColumn >& x,
29                       const uno::Sequence< sheet::SubTotalColumn >& y)
30     {
31         return x == y;
32     }
33 
toStringassertion_traits34     static std::string toString(const uno::Sequence< sheet::SubTotalColumn >& x)
35     {
36         OStringStream ost;
37         ost << "Sequence: Length: " << x.getLength() << "\n";
38         for (const auto& rElement : x)
39             ost << "Column: " << rElement.Column << " Function:\n";
40             // FIXME: Find a way to print Function
41             //ost << "Column: " << element->Column << " Function: " << element->Function << "\n";
42         return ost.str();
43     }
44 };
45 
46 CPPUNIT_NS_END
47 
48 namespace apitest {
49 
testGetSetGroupColumn()50 void XSubTotalField::testGetSetGroupColumn()
51 {
52     uno::Reference< sheet::XSubTotalField > xSTF(init(), uno::UNO_QUERY_THROW);
53 
54     CPPUNIT_ASSERT_MESSAGE("Unable to get GroupColumn", xSTF->getGroupColumn() != 0);
55 
56     xSTF->setGroupColumn(2);
57     CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set GroupColumn to new value",
58                                  sal_Int32(2), xSTF->getGroupColumn());
59 }
60 
testGetSetTotalColumns()61 void XSubTotalField::testGetSetTotalColumns()
62 {
63     uno::Reference< sheet::XSubTotalField > xSTF(init(), UNO_QUERY_THROW);
64 
65     uno::Sequence< sheet::SubTotalColumn > sDefaultCols = xSTF->getSubTotalColumns();
66     CPPUNIT_ASSERT_MESSAGE("Unable to get SubTotalColumns", sDefaultCols.hasElements());
67 
68     uno::Sequence< sheet::SubTotalColumn > sNewCols;
69     sNewCols.realloc(1);
70     sNewCols[0].Column = 5;
71     sNewCols[0].Function = sheet::GeneralFunction_AVERAGE;
72     xSTF->setSubTotalColumns(sNewCols);
73 
74     CPPUNIT_ASSERT_MESSAGE("Unable to set SubTotalColumns", sDefaultCols != xSTF->getSubTotalColumns());
75 }
76 
77 }
78 
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
80