tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / beans / _XPropertyAccess.java
blob697290dc738696d704d6a2047622a012ae92aa15
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.beans;
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.beans.PropertyVetoException;
23 import com.sun.star.lang.WrappedTargetException;
24 import lib.MultiMethodTest;
25 import com.sun.star.beans.UnknownPropertyException;
26 import com.sun.star.beans.XPropertyAccess;
27 import lib.Status;
28 import lib.StatusException;
30 /**
31 * Testing <code>com.sun.star.beans.XPropertyAccess</code>
32 * interface methods :
33 * <ul>
34 * <li><code>getPropertyValues()</code></li>
35 * <li><code>setPropertyValues()</code></li>
36 * </ul>
37 * @see com.sun.star.beans.XPropertyAccess
39 public class _XPropertyAccess extends MultiMethodTest {
41 /**
42 * oObj filled by MultiMethodTest
44 public XPropertyAccess oObj = null;// oObj filled by MultiMethodTest
46 /**
47 * object relation X<CODE>PropertyAccess.propertyToChange</CODE><br>
48 * This relation must be filled from the module. It contains a property which must
49 * be kind of String property, available at <CODE>getPropertyValues()</CODE> and changeable by
50 * <CODE>setPropertyValues()</CODE>
52 public PropertyValue propertyToChange = null;
54 /**
55 * checks if the object relation <CODE>XPropertyAccess.propertyToChange</CODE>
56 * is available
58 @Override
59 public void before() {
60 propertyToChange = (PropertyValue) tEnv.getObjRelation("XPropertyAccess.propertyToChange");
61 if (propertyToChange == null) {
62 throw new StatusException(Status.failed("Object raltion 'XPropertyAccess.propertyToChange' is null"));
66 /**
67 * Test calls the method and checks if the returned sequence contains a property which is named
68 * in the object relation <code>XPropertyAccess.propertyToChange</code>.
70 public void _getPropertyValues() {
71 PropertyValue[] properties = oObj.getPropertyValues();
73 boolean ok = true;
75 if (properties != null){
77 boolean found = false;
78 for (int i=0; i < properties.length; i++){
79 if (properties[i].Name.equals(propertyToChange.Name)) found = true;
81 if (! found){
82 log.println("ERROR: could not find desired property '"+ propertyToChange.Name+"'");
83 ok=false;
86 } else {
87 log.println("ERROR: the method returned NULL");
88 ok =false;
91 tRes.tested("getPropertyValues()", ok );
94 /**
95 * Test calls the method and checks if:
96 * <ul>
97 * <li>the property given by the object relation
98 * <CODE>XPropertyAccess.propertyToChange</CODE> has changed</LI>
99 * <li><CODE>com.sun.star.lang.IllegalArgumentException</CODE> was thrown if a <CODE>Integer</CODE>
100 * value was set to a <CODE>String</CODE> property</LI>
101 * <li><CODE>com.sun.star.beans.UnknownPropertyException</CODE> was thrown if an invalid property
102 * was set</LI>
103 * </ul>
105 public void _setPropertyValues(){
107 boolean ok = true;
108 boolean test = true;
109 boolean exp = false;
111 try {
112 PropertyValue[] newProps = new PropertyValue[1];
113 newProps[0] = propertyToChange;
115 log.println("try to set property values given by object relation 'XPropertyAccess.propertyToChange'...");
116 oObj.setPropertyValues(newProps);
118 } catch (UnknownPropertyException ex) {
119 log.println("ERROR: Exception was thrown while trying to set property value: " +
120 ex.toString());
121 test = false;
122 } catch (PropertyVetoException ex) {
123 log.println("ERROR: Exception was thrown while trying to set property value: " +
124 ex.toString());
125 test = false;
126 } catch (WrappedTargetException ex) {
127 log.println("ERROR: Exception was thrown while trying to set property value: " +
128 ex.toString());
129 test = false;
130 } catch (com.sun.star.lang.IllegalArgumentException ex) {
131 log.println("ERROR: Exception was thrown while trying to set property value: " +
132 ex.toString());
133 test = false;
136 if ( test){
137 log.println("... OK");
140 ok &= test;
141 test = false;
142 exp = false;
143 try {
144 log.println("try to set integer value to string property, " +
145 "expect 'com.sun.star.lang.IllegalArgumentException'...");
146 PropertyValue[] newProps = new PropertyValue[1];
147 PropertyValue failedProp = new PropertyValue();
148 failedProp.Name = propertyToChange.Name;
149 failedProp.Value = Integer.valueOf(10);
150 newProps[0] = failedProp;
151 oObj.setPropertyValues(newProps);
152 } catch (PropertyVetoException ex) {
153 log.println("ERROR: unexpected exception was thrown while trying to set null value: " +
154 ex.toString());
155 exp = true;
156 } catch (WrappedTargetException ex) {
157 log.println("ERROR: unexpected exception was thrown while trying to set null value: " +
158 ex.toString());
159 exp = true;
160 } catch (com.sun.star.lang.IllegalArgumentException ex) {
161 log.println("OK: expected exception was thrown while trying to set null value: " +
162 ex.toString());
163 test = true;
164 exp = true;
165 } catch (UnknownPropertyException ex) {
166 log.println("ERROR: unexpected exception was thrown while trying to set null value: " +
167 ex.toString());
168 exp = true;
171 if (! exp){
172 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
173 } else {
174 if (test) log.println("... OK");
177 ok &= test;
178 test = false;
179 exp = false;
180 try {
182 log.println("try to set values with invalid property name. " +
183 "Expect 'com.sun.star.beans.UnknownPropertyException'...");
185 PropertyValue[] newProps = new PropertyValue[1];
186 PropertyValue newProp = new PropertyValue();
187 newProp.Name = "XPropertyAccess.InvalidPropertyName";
188 newProp.Value = "invalid property";
189 newProps[0] = newProp;
191 oObj.setPropertyValues(newProps);
193 } catch (WrappedTargetException ex) {
194 log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
195 ex.toString());
196 exp = true;
197 } catch (com.sun.star.lang.IllegalArgumentException ex) {
198 log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
199 ex.toString());
200 exp = true;
201 } catch (PropertyVetoException ex) {
202 log.println("ERROR: unexpected exception was thrown while trying to set invalid value: " +
203 ex.toString());
204 exp = true;
205 } catch (UnknownPropertyException ex) {
206 log.println("OK: Expected exception was thrown while trying to set invalid value: " +
207 ex.toString());
208 exp = true;
209 test = true;
212 ok &= test;
214 if (! exp){
215 log.println("FAILED: expected exception 'UnknownPropertyException' was not thrown");
216 } else {
217 if (test) log.println("... OK");
220 tRes.tested("setPropertyValues()", ok);
223 } /// finish class XPropertyAccess