1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XValidatableFormComponent.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc
.form
.validation
;
32 import com
.sun
.star
.beans
.Property
;
33 import com
.sun
.star
.beans
.PropertyAttribute
;
34 import com
.sun
.star
.beans
.XMultiPropertySet
;
35 import com
.sun
.star
.beans
.XPropertySetInfo
;
36 import com
.sun
.star
.form
.validation
.XFormComponentValidityListener
;
37 import com
.sun
.star
.form
.validation
.XValidatableFormComponent
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
40 import lib
.MultiMethodTest
;
42 import util
.ValueChanger
;
44 import java
.util
.StringTokenizer
;
47 public class _XValidatableFormComponent
extends MultiMethodTest
49 public XValidatableFormComponent oObj
;
50 protected XFormComponentValidityListener listener
= null;
51 public boolean listenerCalled
= false;
52 private String
[] testPropsNames
= null;
53 private int testPropsAmount
= 0;
55 public void _addFormComponentValidityListener()
57 listener
= new MyListener();
63 oObj
.addFormComponentValidityListener(listener
);
65 catch (com
.sun
.star
.lang
.NullPointerException e
)
71 changeAllProperties();
72 res
&= listenerCalled
;
73 tRes
.tested("addFormComponentValidityListener()", res
);
76 public void _getCurrentValue()
78 Object cValue
= oObj
.getCurrentValue();
79 tRes
.tested("getCurrentValue()", true);
82 public void _isValid()
84 boolean res
= oObj
.isValid();
85 tRes
.tested("isValid()", res
);
88 public void _removeFormComponentValidityListener()
90 requiredMethod("isValid()");
96 oObj
.removeFormComponentValidityListener(listener
);
98 catch (com
.sun
.star
.lang
.NullPointerException e
)
104 listenerCalled
= false;
105 changeAllProperties();
106 res
&= !listenerCalled
;
107 tRes
.tested("removeFormComponentValidityListener()", true);
110 protected void changeAllProperties()
112 XMultiPropertySet mProps
=
113 (XMultiPropertySet
) UnoRuntime
.queryInterface(
114 XMultiPropertySet
.class, tEnv
.getTestObject()
116 XPropertySetInfo propertySetInfo
= mProps
.getPropertySetInfo();
117 Property
[] properties
= propertySetInfo
.getProperties();
118 getPropsToTest(properties
);
119 log
.println("Changing all properties");
121 Object
[] gValues
= mProps
.getPropertyValues(testPropsNames
);
123 for (int i
= 0; i
< testPropsAmount
; i
++)
125 Object oldValue
= gValues
[i
];
128 testPropsNames
[i
].equals("Value")
129 || testPropsNames
[i
].equals("Time")
130 || testPropsNames
[i
].equals("EffectiveValue")
133 oldValue
= new Integer(10);
136 Object newValue
= ValueChanger
.changePValue(oldValue
);
137 gValues
[i
] = newValue
;
139 // System.out.println("#############################################");
140 // System.out.println("Name: "+testPropsNames[i]);
141 // System.out.println("OldValue: "+oldValue);
142 // System.out.println("NewValue: "+newValue);
143 // System.out.println("#############################################");
148 mProps
.setPropertyValues(testPropsNames
, gValues
);
150 catch (com
.sun
.star
.beans
.PropertyVetoException e
)
152 log
.println("Exception occured while setting properties");
153 e
.printStackTrace(log
);
155 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
157 log
.println("Exception occured while setting properties");
158 e
.printStackTrace(log
);
160 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
162 log
.println("Exception occured while setting properties");
163 e
.printStackTrace(log
);
168 //Get the properties being tested
169 private void getPropsToTest(Property
[] properties
)
173 for (int i
= 0; i
< properties
.length
; i
++)
175 Property property
= properties
[i
];
176 String name
= property
.Name
;
178 ((property
.Attributes
& PropertyAttribute
.READONLY
) == 0);
180 ((property
.Attributes
& PropertyAttribute
.MAYBEVOID
) == 0);
182 ((property
.Attributes
& PropertyAttribute
.BOUND
) != 0);
184 //these have values that are interfaces we can't change
186 name
.equals("TextUserDefinedAttributes")
187 || name
.equals("ReferenceDevice")
188 || name
.equals("ParaUserDefinedAttributes")
195 name
.equals("Value") || name
.equals("Time")
196 || name
.equals("Date")
199 bound
= (name
+ ";");
203 isWritable
&& isNotNull
&& (name
.indexOf("Format") < 0)
204 && !name
.equals("Enabled")
207 bound
+= (name
+ ";");
212 //get a array of bound properties
213 if (bound
.equals(""))
218 if (tEnv
.getTestCase().getObjectName().indexOf("Formatted") > 0)
220 bound
= "EffectiveValue;";
223 StringTokenizer ST
= new StringTokenizer(bound
, ";");
224 int nr
= ST
.countTokens();
225 testPropsNames
= new String
[nr
];
227 for (int i
= 0; i
< nr
; i
++)
228 testPropsNames
[i
] = ST
.nextToken();
230 testPropsAmount
= nr
;
235 protected class MyListener
implements XFormComponentValidityListener
237 public void componentValidityChanged(
238 com
.sun
.star
.lang
.EventObject eventObject
241 System
.out
.println("componentValidityChanged called");
242 listenerCalled
= true;
245 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
)
247 System
.out
.println("Listener Disposed");