1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.frame; 25cdf0e10cSrcweir 26cdf0e10cSrcweir 27cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 28cdf0e10cSrcweir import com.sun.star.util.URL; 29cdf0e10cSrcweir import lib.MultiMethodTest; 30cdf0e10cSrcweir import lib.Status; 31cdf0e10cSrcweir import lib.StatusException; 32cdf0e10cSrcweir import com.sun.star.frame.XNotifyingDispatch; 33cdf0e10cSrcweir import com.sun.star.frame.DispatchResultEvent; 34cdf0e10cSrcweir 35cdf0e10cSrcweir /** 36cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XNotifyingDispatch</code> 37cdf0e10cSrcweir * interface methods : 38cdf0e10cSrcweir * <ul> 39cdf0e10cSrcweir * <li><code> dispatchWithNotification()</code></li> 40cdf0e10cSrcweir * </ul> <p> 41cdf0e10cSrcweir * This test needs the following object relations : 42cdf0e10cSrcweir * <ul> 43cdf0e10cSrcweir * <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL 44cdf0e10cSrcweir * </code>): URL for passing to <code>dispatch()</code> method. </li> 45cdf0e10cSrcweir * <li> <code>[OPTIONAL] 'XNotifyingDispatchArgument'</code> 46cdf0e10cSrcweir * (of type sequence<code>com::sun::star::beans::PropertyValue 47cdf0e10cSrcweir * </code>): argumets for <code>dispatchWithNotification()</code> method. </li> 48cdf0e10cSrcweir * <ul> <p> 49cdf0e10cSrcweir * @see com.sun.star.frame.XDispatch 50cdf0e10cSrcweir * @see com.sun.star.frame.XNotifyingDispatch 51*e6b649b5SPedro Giffuni * @see ifc.frame._XDispatch 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir public class _XNotifyingDispatch extends MultiMethodTest { 54cdf0e10cSrcweir 55cdf0e10cSrcweir public XNotifyingDispatch oObj = null; 56cdf0e10cSrcweir 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** 59cdf0e10cSrcweir * Listener implementation which sets flags on appropriate method calls 60cdf0e10cSrcweir */ 61cdf0e10cSrcweir protected class TestNotificationListener implements 62cdf0e10cSrcweir com.sun.star.frame.XDispatchResultListener { 63cdf0e10cSrcweir public boolean disposingCalled = false ; 64cdf0e10cSrcweir public boolean finishedDispatch = false ; 65cdf0e10cSrcweir private java.io.PrintWriter log = null ; 66cdf0e10cSrcweir TestNotificationListener(java.io.PrintWriter log)67cdf0e10cSrcweir public TestNotificationListener(java.io.PrintWriter log) { 68cdf0e10cSrcweir this.log = log ; 69cdf0e10cSrcweir } 70cdf0e10cSrcweir disposing(com.sun.star.lang.EventObject e)71cdf0e10cSrcweir public void disposing(com.sun.star.lang.EventObject e) { 72cdf0e10cSrcweir disposingCalled = true ; 73cdf0e10cSrcweir log.println(" disposing was called.") ; 74cdf0e10cSrcweir } 75cdf0e10cSrcweir dispatchFinished( DispatchResultEvent e)76cdf0e10cSrcweir public void dispatchFinished( DispatchResultEvent e) { 77cdf0e10cSrcweir finishedDispatch = true ; 78cdf0e10cSrcweir log.println(" dispatchFinished was called.") ; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir } 82cdf0e10cSrcweir 83cdf0e10cSrcweir TestNotificationListener notificationListener = null; 84cdf0e10cSrcweir PropertyValue[] arguments = null; 85cdf0e10cSrcweir URL url = null ; 86cdf0e10cSrcweir 87cdf0e10cSrcweir /** 88cdf0e10cSrcweir * Retrieves object relations and creates new listeners. 89cdf0e10cSrcweir * @throws StatusException If one of relations not found. 90cdf0e10cSrcweir */ before()91cdf0e10cSrcweir public void before() { 92cdf0e10cSrcweir notificationListener = new TestNotificationListener(log) ; 93cdf0e10cSrcweir url = (URL) tEnv.getObjRelation("XDispatch.URL") ; 94cdf0e10cSrcweir 95cdf0e10cSrcweir if (url == null) throw new StatusException 96cdf0e10cSrcweir (Status.failed("Relation not found.")) ; 97cdf0e10cSrcweir 98cdf0e10cSrcweir arguments = (PropertyValue[]) 99cdf0e10cSrcweir tEnv.getObjRelation("XNotifyingDispatchArgument"); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir 102cdf0e10cSrcweir /** 103cdf0e10cSrcweir * Calls the method using URL and arguments from relation. <p> 104cdf0e10cSrcweir * Has <b> OK </b> status if listener is called. 105cdf0e10cSrcweir * The following method tests are to be completed successfully before : 106cdf0e10cSrcweir */ _dispatchWithNotification()107cdf0e10cSrcweir public void _dispatchWithNotification() { 108cdf0e10cSrcweir 109cdf0e10cSrcweir boolean result = true ; 110cdf0e10cSrcweir 111cdf0e10cSrcweir oObj.dispatchWithNotification(url, arguments, notificationListener); 112cdf0e10cSrcweir 113cdf0e10cSrcweir try { 114cdf0e10cSrcweir Thread.sleep(200); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir catch(java.lang.InterruptedException e) {} 117cdf0e10cSrcweir 118cdf0e10cSrcweir log.println("Listener called: "+ notificationListener.finishedDispatch); 119cdf0e10cSrcweir 120cdf0e10cSrcweir result = notificationListener.finishedDispatch; 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir tRes.tested("dispatchWithNotification()", result) ; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128