summaryrefslogtreecommitdiffstats
path: root/test/source/sheet/subtotaldescriptor.cxx
blob: e9dffdb7523665ee28b53edad3c28fad8940e6f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <test/sheet/subtotaldescriptor.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>

#include <cppunit/TestAssert.h>

using namespace com::sun::star;
using namespace com::sun::star::uno;

namespace apitest
{
void SubTotalDescriptor::testSubTotalDescriptorProperties()
{
    uno::Reference<beans::XPropertySet> xSubTotalDescriptor(init(), UNO_QUERY_THROW);
    OUString propName;
    uno::Any aNewValue;

    propName = "InsertPageBreaks";
    bool aInsertPageBreaks = true;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aInsertPageBreaks);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue InsertPageBreaks", !aInsertPageBreaks);

    aNewValue <<= true;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aInsertPageBreaks);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue InsertPageBreaks", aInsertPageBreaks);

    propName = "IsCaseSensitive";
    bool aIsCaseSensitive = true;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aIsCaseSensitive);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue IsCaseSensitive", !aIsCaseSensitive);

    aNewValue <<= true;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aIsCaseSensitive);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue IsCaseSensitive", aIsCaseSensitive);

    propName = "EnableUserSortList";
    bool aEnableUserSortList = true;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableUserSortList);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnableUserSortList", !aEnableUserSortList);

    aNewValue <<= true;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableUserSortList);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnableUserSortList", aEnableUserSortList);

    propName = "UserSortListIndex";
    sal_Int32 aUserSortListIndex = 42;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aUserSortListIndex);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue UserSortListIndex", sal_Int32(0),
                                 aUserSortListIndex);

    aNewValue <<= sal_Int32(42);
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aUserSortListIndex);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set PropertyValue UserSortListIndex", sal_Int32(42),
                                 aUserSortListIndex);

    propName = "BindFormatsToContent";
    bool aBindFormatsToContent = true;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aBindFormatsToContent);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue BindFormatsToContent",
                           !aBindFormatsToContent);

    aNewValue <<= true;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aBindFormatsToContent);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue BindFormatsToContent",
                           aBindFormatsToContent);

    propName = "EnableSort";
    bool aEnableSort = false;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableSort);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue EnableSort", aEnableSort);

    aNewValue <<= false;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aEnableSort);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue EnableSort", !aEnableSort);

    propName = "SortAscending";
    bool aSortAscending = false;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aSortAscending);
    CPPUNIT_ASSERT_MESSAGE("Unable to get PropertyValue SortAscending", aSortAscending);

    aNewValue <<= false;
    xSubTotalDescriptor->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aSortAscending);
    CPPUNIT_ASSERT_MESSAGE("Unable to set PropertyValue SortAscending", !aSortAscending);

    propName = "MaxFieldCount";
    sal_Int32 aMaxFieldCount = 42;
    CPPUNIT_ASSERT(xSubTotalDescriptor->getPropertyValue(propName) >>= aMaxFieldCount);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get PropertyValue MaxFieldCount", sal_Int32(3),
                                 aMaxFieldCount);

    aNewValue <<= sal_Int32(42);
    CPPUNIT_ASSERT_THROW_MESSAGE("Able to change PropertyValue MaxFieldCount",
                                 xSubTotalDescriptor->setPropertyValue(propName, aNewValue),
                                 lang::IllegalArgumentException);
}
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */