Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / validation / _XValidatableFormComponent.java
blob78c107ecfa8c658c326b0a2c4406c8753ec95f19
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package ifc.form.validation;
29 import com.sun.star.beans.Property;
30 import com.sun.star.beans.PropertyAttribute;
31 import com.sun.star.beans.XMultiPropertySet;
32 import com.sun.star.beans.XPropertySetInfo;
33 import com.sun.star.form.validation.XFormComponentValidityListener;
34 import com.sun.star.form.validation.XValidatableFormComponent;
35 import com.sun.star.uno.UnoRuntime;
37 import lib.MultiMethodTest;
39 import util.ValueChanger;
41 import java.util.StringTokenizer;
44 public class _XValidatableFormComponent extends MultiMethodTest
46 public XValidatableFormComponent oObj;
47 protected XFormComponentValidityListener listener = null;
48 public boolean listenerCalled = false;
49 private String[] testPropsNames = null;
50 private int testPropsAmount = 0;
52 public void _addFormComponentValidityListener()
54 listener = new MyListener();
56 boolean res = true;
58 try
60 oObj.addFormComponentValidityListener(listener);
62 catch (com.sun.star.lang.NullPointerException e)
64 res = false;
65 e.printStackTrace();
68 changeAllProperties();
69 res &= listenerCalled;
70 tRes.tested("addFormComponentValidityListener()", res);
73 public void _getCurrentValue()
75 Object cValue = oObj.getCurrentValue();
76 tRes.tested("getCurrentValue()", true);
79 public void _isValid()
81 boolean res = oObj.isValid();
82 tRes.tested("isValid()", res);
85 public void _removeFormComponentValidityListener()
87 requiredMethod("isValid()");
89 boolean res = true;
91 try
93 oObj.removeFormComponentValidityListener(listener);
95 catch (com.sun.star.lang.NullPointerException e)
97 res = false;
98 e.printStackTrace();
101 listenerCalled = false;
102 changeAllProperties();
103 res &= !listenerCalled;
104 tRes.tested("removeFormComponentValidityListener()", true);
107 protected void changeAllProperties()
109 XMultiPropertySet mProps =
110 (XMultiPropertySet) UnoRuntime.queryInterface(
111 XMultiPropertySet.class, tEnv.getTestObject()
113 XPropertySetInfo propertySetInfo = mProps.getPropertySetInfo();
114 Property[] properties = propertySetInfo.getProperties();
115 getPropsToTest(properties);
116 log.println("Changing all properties");
118 Object[] gValues = mProps.getPropertyValues(testPropsNames);
120 for (int i = 0; i < testPropsAmount; i++)
122 Object oldValue = gValues[i];
124 if (
125 testPropsNames[i].equals("Value")
126 || testPropsNames[i].equals("Time")
127 || testPropsNames[i].equals("EffectiveValue")
130 oldValue = new Integer(10);
133 Object newValue = ValueChanger.changePValue(oldValue);
134 gValues[i] = newValue;
136 // System.out.println("#############################################");
137 // System.out.println("Name: "+testPropsNames[i]);
138 // System.out.println("OldValue: "+oldValue);
139 // System.out.println("NewValue: "+newValue);
140 // System.out.println("#############################################");
145 mProps.setPropertyValues(testPropsNames, gValues);
147 catch (com.sun.star.beans.PropertyVetoException e)
149 log.println("Exception occurred while setting properties");
150 e.printStackTrace(log);
152 catch (com.sun.star.lang.IllegalArgumentException e)
154 log.println("Exception occurred while setting properties");
155 e.printStackTrace(log);
157 catch (com.sun.star.lang.WrappedTargetException e)
159 log.println("Exception occurred while setting properties");
160 e.printStackTrace(log);
162 // end of try-catch
165 //Get the properties being tested
166 private void getPropsToTest(Property[] properties)
168 String bound = "";
170 for (int i = 0; i < properties.length; i++)
172 Property property = properties[i];
173 String name = property.Name;
174 boolean isWritable =
175 ((property.Attributes & PropertyAttribute.READONLY) == 0);
176 boolean isNotNull =
177 ((property.Attributes & PropertyAttribute.MAYBEVOID) == 0);
178 boolean isBound =
179 ((property.Attributes & PropertyAttribute.BOUND) != 0);
181 //these have values that are interfaces we can't change
182 if (
183 name.equals("TextUserDefinedAttributes")
184 || name.equals("ReferenceDevice")
185 || name.equals("ParaUserDefinedAttributes")
188 isWritable = false;
191 if (
192 name.equals("Value") || name.equals("Time")
193 || name.equals("Date")
196 bound = (name + ";");
199 if (
200 isWritable && isNotNull && (name.indexOf("Format") < 0)
201 && !name.equals("Enabled")
204 bound += (name + ";");
207 // endfor
209 //get a array of bound properties
210 if (bound.equals(""))
212 bound = "none";
215 if (tEnv.getTestCase().getObjectName().indexOf("Formatted") > 0)
217 bound = "EffectiveValue;";
220 StringTokenizer ST = new StringTokenizer(bound, ";");
221 int nr = ST.countTokens();
222 testPropsNames = new String[nr];
224 for (int i = 0; i < nr; i++)
225 testPropsNames[i] = ST.nextToken();
227 testPropsAmount = nr;
229 return;
232 protected class MyListener implements XFormComponentValidityListener
234 public void componentValidityChanged(
235 com.sun.star.lang.EventObject eventObject
238 System.out.println("componentValidityChanged called");
239 listenerCalled = true;
242 public void disposing(com.sun.star.lang.EventObject eventObject)
244 System.out.println("Listener Disposed");