summaryrefslogtreecommitdiffstats
path: root/test/source/sheet/tablevalidation.cxx
blob: 4383019602e5d669e4c718a8370a5cae3d9f788a (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* -*- 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/tablevalidation.hxx>

#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
#include <com/sun/star/sheet/ValidationType.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 TableValidation::testTableValidationProperties()
{
    uno::Reference<beans::XPropertySet> xTableValidation(init(), UNO_QUERY_THROW);
    OUString propName;
    uno::Any aNewValue;

    propName = "Type";
    uno::Any aValue = xTableValidation->getPropertyValue(propName);
    sheet::ValidationType aValidationType;
    aValue >>= aValidationType;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value Type", sheet::ValidationType_ANY,
                                 aValidationType);

    aNewValue <<= sheet::ValidationType_WHOLE;
    xTableValidation->setPropertyValue(propName, aNewValue);
    aValue = xTableValidation->getPropertyValue(propName);
    aValue >>= aValidationType;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value Type", sheet::ValidationType_WHOLE,
                                 aValidationType);

    propName = "ShowInputMessage";
    bool aShowInputMessage = true;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage);
    CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowInputMessage", !aShowInputMessage);

    aNewValue <<= true;
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage);
    CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowInputMessage", aShowInputMessage);

    // only possible if ShowInputMessage is true
    propName = "InputMessage";
    OUString aInputMessage;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage", OUString(""),
                                 aInputMessage);

    aNewValue <<= OUString("UnitTest InputMessage");
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage",
                                 OUString("UnitTest InputMessage"), aInputMessage);

    // only possible if ShowInputMessage is true
    propName = "InputTitle";
    OUString aInputTitle;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle", OUString(""),
                                 aInputTitle);

    aNewValue <<= OUString("UnitTest InputTitle");
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle",
                                 OUString("UnitTest InputTitle"), aInputTitle);

    propName = "ShowErrorMessage";
    bool aShowErrorMessage = true;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage);
    CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowErrorMessage", !aShowErrorMessage);

    aNewValue <<= true;
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage);
    CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowErrorMessage", aShowErrorMessage);

    // only possible if ShowErrorMessage is true
    propName = "ErrorMessage";
    OUString aErrorMessage;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage", OUString(""),
                                 aErrorMessage);

    aNewValue <<= OUString("UnitTest ErrorMessage");
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage",
                                 OUString("UnitTest ErrorMessage"), aErrorMessage);

    // only possible if ShowErrorMessage is true
    propName = "ErrorTitle";
    OUString aErrorTitle;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle", OUString(""),
                                 aErrorTitle);

    aNewValue <<= OUString("UnitTest ErrorTitle");
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle",
                                 OUString("UnitTest ErrorTitle"), aErrorTitle);

    propName = "IgnoreBlankCells";
    bool aIgnoreBlankCells = false;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells);
    CPPUNIT_ASSERT_MESSAGE("Unable to get property value IgnoreBlankCells", aIgnoreBlankCells);

    aNewValue <<= false;
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells);
    CPPUNIT_ASSERT_MESSAGE("Unable to set property value IgnoreBlankCells", !aIgnoreBlankCells);

    propName = "ErrorAlertStyle";
    aValue = xTableValidation->getPropertyValue(propName);
    sheet::ValidationAlertStyle aValidationAlertStyle;
    aValue >>= aValidationAlertStyle;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ValidationAlertStyle",
                                 sheet::ValidationAlertStyle_STOP, aValidationAlertStyle);

    aNewValue <<= sheet::ValidationAlertStyle_WARNING;
    xTableValidation->setPropertyValue(propName, aNewValue);
    aValue = xTableValidation->getPropertyValue(propName);
    aValue >>= aValidationAlertStyle;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ValidationAlertStyle",
                                 sheet::ValidationAlertStyle_WARNING, aValidationAlertStyle);

    propName = "ShowList";
    sal_Int16 aShowList = 0;
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ShowList", sal_Int16(1), aShowList);

    aNewValue <<= sal_Int16(42);
    xTableValidation->setPropertyValue(propName, aNewValue);
    CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ShowList", sal_Int16(42), aShowList);
}
}

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