LibreOffice Module test (master) 1
tablevalidation.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/beans/XPropertySet.hpp>
13#include <com/sun/star/sheet/ValidationAlertStyle.hpp>
14#include <com/sun/star/sheet/ValidationType.hpp>
15#include <com/sun/star/uno/Any.hxx>
16#include <com/sun/star/uno/Reference.hxx>
17
18#include <cppunit/TestAssert.h>
19
20using namespace com::sun::star;
21using namespace com::sun::star::uno;
22
23namespace apitest
24{
26{
27 uno::Reference<beans::XPropertySet> xTableValidation(init(), UNO_QUERY_THROW);
28 OUString propName;
29 uno::Any aNewValue;
30
31 propName = "Type";
32 uno::Any aValue = xTableValidation->getPropertyValue(propName);
33 sheet::ValidationType aValidationType;
34 aValue >>= aValidationType;
35 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value Type", sheet::ValidationType_ANY,
36 aValidationType);
37
38 aNewValue <<= sheet::ValidationType_WHOLE;
39 xTableValidation->setPropertyValue(propName, aNewValue);
40 aValue = xTableValidation->getPropertyValue(propName);
41 aValue >>= aValidationType;
42 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value Type", sheet::ValidationType_WHOLE,
43 aValidationType);
44
45 propName = "ShowInputMessage";
46 bool aShowInputMessage = true;
47 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage);
48 CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowInputMessage", !aShowInputMessage);
49
50 aNewValue <<= true;
51 xTableValidation->setPropertyValue(propName, aNewValue);
52 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowInputMessage);
53 CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowInputMessage", aShowInputMessage);
54
55 // only possible if ShowInputMessage is true
56 propName = "InputMessage";
57 OUString aInputMessage;
58 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage);
59 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage", OUString(""),
60 aInputMessage);
61
62 aNewValue <<= OUString("UnitTest InputMessage");
63 xTableValidation->setPropertyValue(propName, aNewValue);
64 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputMessage);
65 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputMessage",
66 OUString("UnitTest InputMessage"), aInputMessage);
67
68 // only possible if ShowInputMessage is true
69 propName = "InputTitle";
70 OUString aInputTitle;
71 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle);
72 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle", OUString(""),
73 aInputTitle);
74
75 aNewValue <<= OUString("UnitTest InputTitle");
76 xTableValidation->setPropertyValue(propName, aNewValue);
77 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aInputTitle);
78 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value InputTitle",
79 OUString("UnitTest InputTitle"), aInputTitle);
80
81 propName = "ShowErrorMessage";
82 bool aShowErrorMessage = true;
83 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage);
84 CPPUNIT_ASSERT_MESSAGE("Unable to get property value ShowErrorMessage", !aShowErrorMessage);
85
86 aNewValue <<= true;
87 xTableValidation->setPropertyValue(propName, aNewValue);
88 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowErrorMessage);
89 CPPUNIT_ASSERT_MESSAGE("Unable to set property value ShowErrorMessage", aShowErrorMessage);
90
91 // only possible if ShowErrorMessage is true
92 propName = "ErrorMessage";
93 OUString aErrorMessage;
94 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage);
95 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage", OUString(""),
96 aErrorMessage);
97
98 aNewValue <<= OUString("UnitTest ErrorMessage");
99 xTableValidation->setPropertyValue(propName, aNewValue);
100 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorMessage);
101 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorMessage",
102 OUString("UnitTest ErrorMessage"), aErrorMessage);
103
104 // only possible if ShowErrorMessage is true
105 propName = "ErrorTitle";
106 OUString aErrorTitle;
107 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle);
108 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle", OUString(""),
109 aErrorTitle);
110
111 aNewValue <<= OUString("UnitTest ErrorTitle");
112 xTableValidation->setPropertyValue(propName, aNewValue);
113 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aErrorTitle);
114 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ErrorTitle",
115 OUString("UnitTest ErrorTitle"), aErrorTitle);
116
117 propName = "IgnoreBlankCells";
118 bool aIgnoreBlankCells = false;
119 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells);
120 CPPUNIT_ASSERT_MESSAGE("Unable to get property value IgnoreBlankCells", aIgnoreBlankCells);
121
122 aNewValue <<= false;
123 xTableValidation->setPropertyValue(propName, aNewValue);
124 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aIgnoreBlankCells);
125 CPPUNIT_ASSERT_MESSAGE("Unable to set property value IgnoreBlankCells", !aIgnoreBlankCells);
126
127 propName = "ErrorAlertStyle";
128 aValue = xTableValidation->getPropertyValue(propName);
129 sheet::ValidationAlertStyle aValidationAlertStyle;
130 aValue >>= aValidationAlertStyle;
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ValidationAlertStyle",
132 sheet::ValidationAlertStyle_STOP, aValidationAlertStyle);
133
134 aNewValue <<= sheet::ValidationAlertStyle_WARNING;
135 xTableValidation->setPropertyValue(propName, aNewValue);
136 aValue = xTableValidation->getPropertyValue(propName);
137 aValue >>= aValidationAlertStyle;
138 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ValidationAlertStyle",
139 sheet::ValidationAlertStyle_WARNING, aValidationAlertStyle);
140
141 propName = "ShowList";
142 sal_Int16 aShowList = 0;
143 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList);
144 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to get property value ShowList", sal_Int16(1), aShowList);
145
146 aNewValue <<= sal_Int16(42);
147 xTableValidation->setPropertyValue(propName, aNewValue);
148 CPPUNIT_ASSERT(xTableValidation->getPropertyValue(propName) >>= aShowList);
149 CPPUNIT_ASSERT_EQUAL_MESSAGE("Unable to set property value ShowList", sal_Int16(42), aShowList);
150}
151}
152
153/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
virtual css::uno::Reference< css::uno::XInterface > init()=0