merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / form / _XSubmit.java
blob47a3ce87aa0932e232d0af3fbdf2ff724b4dd304
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSubmit.java,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
31 package ifc.form;
33 import lib.MultiMethodTest;
35 import com.sun.star.awt.MouseEvent;
36 import com.sun.star.awt.XControl;
37 import com.sun.star.beans.XPropertySet;
38 import com.sun.star.form.XSubmit;
39 import com.sun.star.form.XSubmitListener;
40 import com.sun.star.lang.EventObject;
41 import com.sun.star.uno.UnoRuntime;
43 /**
44 * Testing <code>com.sun.star.form.XSubmit</code>
45 * interface methods :
46 * <ul>
47 * <li><code> submit()</code></li>
48 * <li><code> addSubmitListener()</code></li>
49 * <li><code> removeSubmitListener()</code></li>
50 * </ul> <p>
52 * This test needs the following object relations :
53 * <ul>
54 * <li> <code>'XSubmit.Control'</code> <b>optional</b>
55 * (of type <code>com.sun.star.awt.XControl</code>):
56 * is used to pass as parameters to <code>submit</code>
57 * method. <code>null</code> is passed if the relation
58 * is not found.</li>
59 * <ul> <p>
61 * Other <b> prerequicity </b> is the object must have
62 * <code>TargetURL</code> property. <p>
64 * Short description : test adds two listeners, call
65 * <code> submit </code> method and cecks if both listeners
66 * were called. Then one listener is removed and after
67 * <code> submit </code> method call it must not be called. <p>
69 * Test is <b> NOT </b> multithread compilant. <p>
70 * @see com.sun.star.form.XSubmit
72 public class _XSubmit extends MultiMethodTest {
74 public static XSubmit oObj = null;
76 public class MySubmitListener implements XSubmitListener {
77 public int called = 0 ;
78 public void disposing ( EventObject oEvent ) {
80 public boolean approveSubmit( EventObject oEvent ) {
81 called += 1;
82 System.out.println("Listener called");
83 return true;
88 MySubmitListener listener1 = new MySubmitListener();
89 MySubmitListener listener2 = new MySubmitListener();
91 /**
92 * Just adds two submit listeners. <p>
93 * Status of this method test is defined in <code>
94 * submit </code> method test.
96 public void _addSubmitListener() {
97 log.println("Testing addSubmitListener ...");
98 oObj.addSubmitListener( listener1 );
99 oObj.addSubmitListener( listener2 );
103 * Before submision tries to set 'TargetURL' property
104 * of component to some value assuming that component
105 * supports <code>com.sun.star.form.HTMLForm</code>
106 * service.
107 * Then calls the <code> submit </code> method and checks
108 * if listener removed were not called, and other was
109 * called only once.<p>
111 * Has <b> OK </b> status for <code>submit</code> if
112 * listener was called at least ones, for
113 * <code>addSubmitListener</code> method if the remaining
114 * listener was called only once, for
115 * <code>removeSubmitListener</code> method if the removed
116 * listener was not called. <p>
118 * The following method tests are to be completed successfully before :
119 * <ul>
120 * <li> <code> removeSubmitListener </code> : to have one listener
121 * added and other removed.</li>
122 * </ul>
124 public void _submit() {
125 executeMethod("removeSubmitListener()");
126 log.println("Testing submit() ...");
127 XControl cntrl = (XControl) tEnv.getObjRelation("XSubmit.Control") ;
129 XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface
130 (XPropertySet.class, oObj) ;
132 if (xPS != null) {
133 try {
134 xPS.setPropertyValue("TargetURL", "someserver");
135 } catch (com.sun.star.lang.WrappedTargetException e) {
136 e.printStackTrace(log);
137 } catch (com.sun.star.lang.IllegalArgumentException e) {
138 e.printStackTrace(log);
139 } catch (com.sun.star.beans.PropertyVetoException e) {
140 e.printStackTrace(log);
141 } catch (com.sun.star.beans.UnknownPropertyException e) {
142 e.printStackTrace(log);
144 } else {
145 log.println("!!! The tested compoennt doesn't support XPropertySet ");
148 oObj.submit(cntrl, new MouseEvent());
149 shortWait();
151 log.println("Listener1 called " + listener1.called + " times");
152 log.println("Listener2 called " + listener2.called + " times");
154 tRes.tested("addSubmitListener()", listener2.called == 1);
155 tRes.tested("removeSubmitListener()", listener1.called == 0);
156 tRes.tested("submit()", listener2.called > 0);
157 oObj.removeSubmitListener(listener2);
161 * Just removes one of submit listeners. <p>
162 * Status of this method test is defined in <code>
163 * submit </code> method test.
164 * The following method tests are to be completed successfully before :
165 * <ul>
166 * <li> <code> removeSubmitListener </code> : to have listeners added</li>
167 * </ul>
169 public void _removeSubmitListener() {
170 requiredMethod("addSubmitListener()");
171 oObj.removeSubmitListener(listener1);
175 * Sleeps for 0.2 sec. to allow StarOffice to react on <code>
176 * reset</code> call.
178 private void shortWait() {
179 try {
180 Thread.sleep(200) ;
181 } catch (InterruptedException e) {
182 log.println("While waiting :" + e) ;
187 * Forces environment recreation.
189 protected void after() {
190 disposeEnvironment();