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 .
18 package ifc
.form
.validation
;
20 import com
.sun
.star
.beans
.Property
;
21 import com
.sun
.star
.beans
.PropertyAttribute
;
22 import com
.sun
.star
.beans
.XMultiPropertySet
;
23 import com
.sun
.star
.beans
.XPropertySetInfo
;
24 import com
.sun
.star
.form
.validation
.XFormComponentValidityListener
;
25 import com
.sun
.star
.form
.validation
.XValidatableFormComponent
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
28 import lib
.MultiMethodTest
;
30 import util
.ValueChanger
;
32 import java
.util
.StringTokenizer
;
35 public class _XValidatableFormComponent
extends MultiMethodTest
37 public XValidatableFormComponent oObj
;
38 protected XFormComponentValidityListener listener
= null;
39 public boolean listenerCalled
= false;
40 private String
[] testPropsNames
= null;
41 private int testPropsAmount
= 0;
43 public void _addFormComponentValidityListener()
45 listener
= new MyListener();
51 oObj
.addFormComponentValidityListener(listener
);
53 catch (com
.sun
.star
.lang
.NullPointerException e
)
59 changeAllProperties();
60 res
&= listenerCalled
;
61 tRes
.tested("addFormComponentValidityListener()", res
);
64 public void _getCurrentValue()
66 oObj
.getCurrentValue();
67 tRes
.tested("getCurrentValue()", true);
70 public void _isValid()
72 boolean res
= oObj
.isValid();
73 tRes
.tested("isValid()", res
);
76 public void _removeFormComponentValidityListener()
78 requiredMethod("isValid()");
82 oObj
.removeFormComponentValidityListener(listener
);
84 catch (com
.sun
.star
.lang
.NullPointerException e
)
89 listenerCalled
= false;
90 changeAllProperties();
91 tRes
.tested("removeFormComponentValidityListener()", true);
94 protected void changeAllProperties()
96 XMultiPropertySet mProps
=
97 UnoRuntime
.queryInterface(
98 XMultiPropertySet
.class, tEnv
.getTestObject()
100 XPropertySetInfo propertySetInfo
= mProps
.getPropertySetInfo();
101 Property
[] properties
= propertySetInfo
.getProperties();
102 getPropsToTest(properties
);
103 log
.println("Changing all properties");
105 Object
[] gValues
= mProps
.getPropertyValues(testPropsNames
);
107 for (int i
= 0; i
< testPropsAmount
; i
++)
109 Object oldValue
= gValues
[i
];
112 testPropsNames
[i
].equals("Value")
113 || testPropsNames
[i
].equals("EffectiveValue")
116 oldValue
= Integer
.valueOf(10);
118 else if (testPropsNames
[i
].equals("Time"))
120 oldValue
= new com
.sun
.star
.util
.Time(
121 10, (short) 10, (short) 10, (short) 10, false);
124 Object newValue
= ValueChanger
.changePValue(oldValue
);
125 gValues
[i
] = newValue
;
130 mProps
.setPropertyValues(testPropsNames
, gValues
);
132 catch (com
.sun
.star
.beans
.PropertyVetoException e
)
134 log
.println("Exception occurred while setting properties");
135 e
.printStackTrace(log
);
137 catch (com
.sun
.star
.lang
.IllegalArgumentException e
)
139 log
.println("Exception occurred while setting properties");
140 e
.printStackTrace(log
);
142 catch (com
.sun
.star
.lang
.WrappedTargetException e
)
144 log
.println("Exception occurred while setting properties");
145 e
.printStackTrace(log
);
150 //Get the properties being tested
151 private void getPropsToTest(Property
[] properties
)
153 StringBuilder sb
= new StringBuilder();
155 for (int i
= 0; i
< properties
.length
; i
++)
157 Property property
= properties
[i
];
158 String name
= property
.Name
;
160 ((property
.Attributes
& PropertyAttribute
.READONLY
) == 0);
162 ((property
.Attributes
& PropertyAttribute
.MAYBEVOID
) == 0);
163 //these have values that are interfaces we can't change
165 name
.equals("TextUserDefinedAttributes")
166 || name
.equals("ReferenceDevice")
167 || name
.equals("ParaUserDefinedAttributes")
174 name
.equals("Value") || name
.equals("Time")
175 || name
.equals("Date")
178 sb
= new StringBuilder(name
+ ";");
182 isWritable
&& isNotNull
&& (name
.indexOf("Format") < 0)
183 && !name
.equals("Enabled")
186 sb
.append(name
+ ";");
190 String bound
= sb
.toString();
193 //get an array of bound properties
194 if (bound
.equals(""))
199 if (tEnv
.getTestCase().getObjectName().indexOf("Formatted") > 0)
201 bound
= "EffectiveValue;";
204 StringTokenizer ST
= new StringTokenizer(bound
, ";");
205 int nr
= ST
.countTokens();
206 testPropsNames
= new String
[nr
];
208 for (int i
= 0; i
< nr
; i
++)
209 testPropsNames
[i
] = ST
.nextToken();
211 testPropsAmount
= nr
;
214 protected class MyListener
implements XFormComponentValidityListener
216 public void componentValidityChanged(
217 com
.sun
.star
.lang
.EventObject eventObject
220 System
.out
.println("componentValidityChanged called");
221 listenerCalled
= true;
224 public void disposing(com
.sun
.star
.lang
.EventObject eventObject
)
226 System
.out
.println("Listener Disposed");