bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XDispatch.java
blob7265a4ce2aa1f7bad309c92622171d5d13bcadd4
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.frame;
22 import com.sun.star.beans.PropertyValue;
23 import com.sun.star.frame.XDispatch;
24 import com.sun.star.util.URL;
25 import lib.MultiMethodTest;
26 import lib.Status;
27 import lib.StatusException;
28 import com.sun.star.frame.XNotifyingDispatch;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.frame.DispatchResultEvent;
32 /**
33 * Testing <code>com.sun.star.frame.XDispatch</code>
34 * interface methods :
35 * <ul>
36 * <li><code> dispatch()</code></li>
37 * <li><code> addStatusListener()</code></li>
38 * <li><code> removeStatusListener()</code></li>
39 * </ul> <p>
40 * This test needs the following object relations :
41 * <ul>
42 * <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL
43 * </code>): URL for passing to <code>dispatch()</code> method. </li>
44 * <ul> <p>
45 * @see com.sun.star.frame.XDispatch
46 * @see com.sun.star.frame.XNotifyingDispatch
47 * @see ifc.frame._XDispatch
48 * @see ifc.frame._XNotifyingDispatch
51 public class _XDispatch extends MultiMethodTest {
53 public XDispatch oObj = null;
55 /**
56 * Listener implementation which sets flags on appropriate method calls
58 protected class TestStatusListener implements
59 com.sun.star.frame.XStatusListener {
60 public boolean disposingCalled = false ;
61 public boolean statusChangedCalled = false ;
62 private java.io.PrintWriter log = null ;
64 public TestStatusListener(java.io.PrintWriter log) {
65 this.log = log ;
68 public void disposing(com.sun.star.lang.EventObject e) {
69 disposingCalled = true ;
70 log.println(" disposing was called.") ;
73 public void statusChanged(com.sun.star.frame.FeatureStateEvent e) {
74 statusChangedCalled = true ;
75 log.println(" statusChanged was called.") ;
76 log.println(" FeatureURL = '" + e.FeatureURL + "'");
77 log.println(" FeatureDescriptor = '" + e.FeatureDescriptor + "'");
78 log.println(" IsEnabled = " + e.IsEnabled);
79 log.println(" Requery = " + e.Requery);
80 log.println(" State = '" + e.State.toString() + "'");
85 /**
86 * Listener implementation which sets flags on appropriate method calls
88 protected class TestNotificationListener implements
89 com.sun.star.frame.XDispatchResultListener {
90 public boolean disposingCalled = false ;
91 public boolean finishedDispatch = false ;
92 private java.io.PrintWriter log = null ;
94 public TestNotificationListener(java.io.PrintWriter log) {
95 this.log = log ;
98 public void disposing(com.sun.star.lang.EventObject e) {
99 disposingCalled = true ;
100 log.println(" disposing was called.") ;
103 public void dispatchFinished( DispatchResultEvent e) {
104 finishedDispatch = true ;
105 log.println(" dispatchFinished was called.") ;
110 TestStatusListener listener = null ;
111 TestNotificationListener notificationListener = null;
112 URL url = null ;
115 * Not all implementations could call the
116 * <code>com.sun.star.frame.XStatusListener</code>. For this purposes the
117 * <code>com.sun.star.frame.XDispatchWithNotification</code> was designed.
118 * If <code>com.sun.star.frame.XStatusListener</code> was not called and
119 * <code>com.sun.star.frame.XStatusListener</code> is present, it was used
120 * to check listeners.
122 private boolean checkXDispatchWithNotification()
124 XNotifyingDispatch xND = UnoRuntime.queryInterface(XNotifyingDispatch.class, oObj);
125 if ( xND != null) {
126 log.println(" XNotifyingDispatch found:");
127 PropertyValue[] arguments = (PropertyValue[])
128 tEnv.getObjRelation("XNotifyingDispatchArgument");
130 notificationListener = new TestNotificationListener(log) ;
131 xND.dispatchWithNotification(url, arguments, notificationListener);
133 try {
134 Thread.sleep(200);
136 catch(java.lang.InterruptedException e) {}
138 log.println(" Listener called: "+ notificationListener.finishedDispatch);
140 return notificationListener.finishedDispatch;
141 } else {
142 return false;
147 * Retrieves object relations and creates new listeners.
148 * @throws StatusException If one of relations not found.
150 public void before() {
151 listener = new TestStatusListener(log) ;
152 url = (URL) tEnv.getObjRelation("XDispatch.URL") ;
154 if (url == null) throw new StatusException
155 (Status.failed("Relation not found.")) ;
159 * Calls the method using URL from relation. <p>
160 * Has <b> OK </b> status if one listener (not removed) is called, and
161 * another (removed) is not.
162 * The following method tests are to be completed successfully before :
163 * <ul>
164 * <li> <code>addStatusListener</code> :
165 * to check that the listener is called
166 * </li>
167 * </ul>
169 public void _dispatch() {
170 requiredMethod("addStatusListener()") ;
172 boolean result = true ;
174 oObj.dispatch(url, new PropertyValue[0]) ;
176 try {
177 Thread.sleep(200);
179 catch(java.lang.InterruptedException e) {}
181 log.println("Listener called: "+ listener.statusChangedCalled);
183 result = listener.statusChangedCalled;
185 if (result == false) {
186 result = checkXDispatchWithNotification();
189 tRes.tested("dispatch()", result) ;
193 * Adds two listeners. <p>
194 * Has <b> OK </b> status if no runtime exceptions occurred.
196 public void _addStatusListener() {
198 boolean result = true ;
199 oObj.addStatusListener(listener, url) ;
201 tRes.tested("addStatusListener()", result) ;
205 * Removes the listener added before. <p>
206 * Has <b> OK </b> status if the dispatch call doesn't call the listener.
207 * The following method tests are to be completed successfully before :
208 * <ul>
209 * <li> <code> dispatch() </code> : to have a listener to remove
210 * </li>
211 * </ul>
213 public void _removeStatusListener() {
214 requiredMethod("dispatch()") ;
215 listener.statusChangedCalled = false;
216 boolean result = true ;
217 oObj.removeStatusListener(listener, url) ;
219 oObj.dispatch(url, new PropertyValue[0]) ;
221 try {
222 Thread.sleep(200);
224 catch(java.lang.InterruptedException e) {}
226 System.out.println("Listener called: "+ listener.statusChangedCalled);
228 result = ! listener.statusChangedCalled;
230 tRes.tested("removeStatusListener()", result) ;