Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XDispatch.java
blob59dfe64c310122df5b3fbed556cb4e9cdaaf01d5
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 final java.io.PrintWriter log;
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 final java.io.PrintWriter log;
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 util.utils.pause(200);
135 log.println(" Listener called: "+ notificationListener.finishedDispatch);
137 return notificationListener.finishedDispatch;
138 } else {
139 return false;
144 * Retrieves object relations and creates new listeners.
145 * @throws StatusException If one of relations not found.
147 @Override
148 public void before() {
149 listener = new TestStatusListener(log) ;
150 url = (URL) tEnv.getObjRelation("XDispatch.URL") ;
152 if (url == null) throw new StatusException
153 (Status.failed("Relation not found.")) ;
157 * Calls the method using URL from relation. <p>
158 * Has <b> OK </b> status if one listener (not removed) is called, and
159 * another (removed) is not.
160 * The following method tests are to be completed successfully before :
161 * <ul>
162 * <li> <code>addStatusListener</code> :
163 * to check that the listener is called
164 * </li>
165 * </ul>
167 public void _dispatch() {
168 requiredMethod("addStatusListener()") ;
170 boolean result = true ;
172 oObj.dispatch(url, new PropertyValue[0]) ;
174 util.utils.pause(200);
176 log.println("Listener called: "+ listener.statusChangedCalled);
178 result = listener.statusChangedCalled;
180 if (!result) {
181 result = checkXDispatchWithNotification();
184 tRes.tested("dispatch()", result) ;
188 * Adds two listeners. <p>
189 * Has <b> OK </b> status if no runtime exceptions occurred.
191 public void _addStatusListener() {
193 boolean result = true ;
194 oObj.addStatusListener(listener, url) ;
196 tRes.tested("addStatusListener()", result) ;
200 * Removes the listener added before. <p>
201 * Has <b> OK </b> status if the dispatch call doesn't call the listener.
202 * The following method tests are to be completed successfully before :
203 * <ul>
204 * <li> <code> dispatch() </code> : to have a listener to remove
205 * </li>
206 * </ul>
208 public void _removeStatusListener() {
209 requiredMethod("dispatch()") ;
210 listener.statusChangedCalled = false;
211 boolean result = true ;
212 oObj.removeStatusListener(listener, url) ;
214 oObj.dispatch(url, new PropertyValue[0]) ;
216 util.utils.pause(200);
218 System.out.println("Listener called: "+ listener.statusChangedCalled);
220 result = ! listener.statusChangedCalled;
222 tRes.tested("removeStatusListener()", result) ;