1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.frame; 29 30 31 import com.sun.star.beans.PropertyValue; 32 import com.sun.star.util.URL; 33 import lib.MultiMethodTest; 34 import lib.Status; 35 import lib.StatusException; 36 import com.sun.star.frame.XNotifyingDispatch; 37 import com.sun.star.frame.DispatchResultEvent; 38 39 /** 40 * Testing <code>com.sun.star.frame.XNotifyingDispatch</code> 41 * interface methods : 42 * <ul> 43 * <li><code> dispatchWithNotification()</code></li> 44 * </ul> <p> 45 * This test needs the following object relations : 46 * <ul> 47 * <li> <code>'XDispatch.URL'</code> (of type <code>com.sun.star.util.URL 48 * </code>): URL for passing to <code>dispatch()</code> method. </li> 49 * <li> <code>[OPTIONAL] 'XNotifyingDispatchArgument'</code> 50 * (of type sequence<code>com::sun::star::beans::PropertyValue 51 * </code>): argumets for <code>dispatchWithNotification()</code> method. </li> 52 * <ul> <p> 53 * @see com.sun.star.frame.XDispatch 54 * @see com.sun.star.frame.XNotifyingDispatch 55 * @see ifc.frmae._XDispatch 56 */ 57 public class _XNotifyingDispatch extends MultiMethodTest { 58 59 public XNotifyingDispatch oObj = null; 60 61 62 /** 63 * Listener implementation which sets flags on appropriate method calls 64 */ 65 protected class TestNotificationListener implements 66 com.sun.star.frame.XDispatchResultListener { 67 public boolean disposingCalled = false ; 68 public boolean finishedDispatch = false ; 69 private java.io.PrintWriter log = null ; 70 71 public TestNotificationListener(java.io.PrintWriter log) { 72 this.log = log ; 73 } 74 75 public void disposing(com.sun.star.lang.EventObject e) { 76 disposingCalled = true ; 77 log.println(" disposing was called.") ; 78 } 79 80 public void dispatchFinished( DispatchResultEvent e) { 81 finishedDispatch = true ; 82 log.println(" dispatchFinished was called.") ; 83 } 84 85 } 86 87 TestNotificationListener notificationListener = null; 88 PropertyValue[] arguments = null; 89 URL url = null ; 90 91 /** 92 * Retrieves object relations and creates new listeners. 93 * @throws StatusException If one of relations not found. 94 */ 95 public void before() { 96 notificationListener = new TestNotificationListener(log) ; 97 url = (URL) tEnv.getObjRelation("XDispatch.URL") ; 98 99 if (url == null) throw new StatusException 100 (Status.failed("Relation not found.")) ; 101 102 arguments = (PropertyValue[]) 103 tEnv.getObjRelation("XNotifyingDispatchArgument"); 104 } 105 106 /** 107 * Calls the method using URL and arguments from relation. <p> 108 * Has <b> OK </b> status if listener is called. 109 * The following method tests are to be completed successfully before : 110 */ 111 public void _dispatchWithNotification() { 112 113 boolean result = true ; 114 115 oObj.dispatchWithNotification(url, arguments, notificationListener); 116 117 try { 118 Thread.sleep(200); 119 } 120 catch(java.lang.InterruptedException e) {} 121 122 log.println("Listener called: "+ notificationListener.finishedDispatch); 123 124 result = notificationListener.finishedDispatch; 125 126 127 tRes.tested("dispatchWithNotification()", result) ; 128 } 129 130 } 131 132