tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / form / _XSubmit.java
blob3b33469002937d7d6ebe83a177bffa48c9d282d7
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.form;
21 import lib.MultiMethodTest;
23 import com.sun.star.awt.MouseEvent;
24 import com.sun.star.awt.XControl;
25 import com.sun.star.beans.XPropertySet;
26 import com.sun.star.form.XSubmit;
27 import com.sun.star.form.XSubmitListener;
28 import com.sun.star.lang.EventObject;
29 import com.sun.star.uno.UnoRuntime;
31 /**
32 * Testing <code>com.sun.star.form.XSubmit</code>
33 * interface methods :
34 * <ul>
35 * <li><code> submit()</code></li>
36 * <li><code> addSubmitListener()</code></li>
37 * <li><code> removeSubmitListener()</code></li>
38 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
42 * <li> <code>'XSubmit.Control'</code> <b>optional</b>
43 * (of type <code>com.sun.star.awt.XControl</code>):
44 * is used to pass as parameters to <code>submit</code>
45 * method. <code>null</code> is passed if the relation
46 * is not found.</li>
47 * <ul> <p>
49 * Other <b> prerequicity </b> is the object must have
50 * <code>TargetURL</code> property. <p>
52 * Short description: test adds two listeners, call
53 * <code> submit </code> method and checks if both listeners
54 * were called. Then one listener is removed and after
55 * <code> submit </code> method call it must not be called. <p>
57 * Test is <b> NOT </b> multithread compliant. <p>
58 * @see com.sun.star.form.XSubmit
60 public class _XSubmit extends MultiMethodTest {
62 public static XSubmit oObj = null;
64 public static class MySubmitListener implements XSubmitListener {
65 public int called = 0 ;
66 public void disposing ( EventObject oEvent ) {
68 public boolean approveSubmit( EventObject oEvent ) {
69 called += 1;
70 System.out.println("Listener called");
71 return true;
76 MySubmitListener listener1 = new MySubmitListener();
77 MySubmitListener listener2 = new MySubmitListener();
79 /**
80 * Just adds two submit listeners. <p>
81 * Status of this method test is defined in <code>
82 * submit </code> method test.
84 public void _addSubmitListener() {
85 log.println("Testing addSubmitListener ...");
86 oObj.addSubmitListener( listener1 );
87 oObj.addSubmitListener( listener2 );
90 /**
91 * Before submission tries to set 'TargetURL' property
92 * of component to some value assuming that component
93 * supports <code>com.sun.star.form.HTMLForm</code>
94 * service.
95 * Then calls the <code> submit </code> method and checks
96 * if listener removed were not called, and other was
97 * called only once.<p>
99 * Has <b> OK </b> status for <code>submit</code> if
100 * listener was called at least ones, for
101 * <code>addSubmitListener</code> method if the remaining
102 * listener was called only once, for
103 * <code>removeSubmitListener</code> method if the removed
104 * listener was not called. <p>
106 * The following method tests are to be completed successfully before :
107 * <ul>
108 * <li> <code> removeSubmitListener </code> : to have one listener
109 * added and other removed.</li>
110 * </ul>
112 public void _submit() {
113 executeMethod("removeSubmitListener()");
114 log.println("Testing submit() ...");
115 XControl cntrl = (XControl) tEnv.getObjRelation("XSubmit.Control") ;
117 XPropertySet xPS = UnoRuntime.queryInterface
118 (XPropertySet.class, oObj) ;
120 if (xPS != null) {
121 try {
122 xPS.setPropertyValue("TargetURL", "someserver");
123 } catch (com.sun.star.lang.WrappedTargetException e) {
124 e.printStackTrace(log);
125 } catch (com.sun.star.lang.IllegalArgumentException e) {
126 e.printStackTrace(log);
127 } catch (com.sun.star.beans.PropertyVetoException e) {
128 e.printStackTrace(log);
129 } catch (com.sun.star.beans.UnknownPropertyException e) {
130 e.printStackTrace(log);
132 } else {
133 log.println("!!! The tested component doesn't support XPropertySet ");
136 oObj.submit(cntrl, new MouseEvent());
137 waitForEventIdle();
139 log.println("Listener1 called " + listener1.called + " times");
140 log.println("Listener2 called " + listener2.called + " times");
142 tRes.tested("addSubmitListener()", listener2.called == 1);
143 tRes.tested("removeSubmitListener()", listener1.called == 0);
144 tRes.tested("submit()", listener2.called > 0);
145 oObj.removeSubmitListener(listener2);
149 * Just removes one of submit listeners. <p>
150 * Status of this method test is defined in <code>
151 * submit </code> method test.
152 * The following method tests are to be completed successfully before :
153 * <ul>
154 * <li> <code> removeSubmitListener </code> : to have listeners added</li>
155 * </ul>
157 public void _removeSubmitListener() {
158 requiredMethod("addSubmitListener()");
159 oObj.removeSubmitListener(listener1);
163 * Forces environment recreation.
165 @Override
166 protected void after() {
167 disposeEnvironment();