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 import java.io.PrintWriter; 31 32 import lib.MultiMethodTest; 33 34 import com.sun.star.frame.DispatchDescriptor; 35 import com.sun.star.frame.XDispatch; 36 import com.sun.star.frame.XDispatchProvider; 37 import com.sun.star.frame.XDispatchProviderInterception; 38 import com.sun.star.frame.XDispatchProviderInterceptor; 39 import com.sun.star.util.URL; 40 41 /** 42 * Testing <code>com.sun.star.frame.XDispatchProviderInterception</code> 43 * interface methods : 44 * <ul> 45 * <li><code> registerDispatchProviderInterceptor()</code></li> 46 * <li><code> releaseDispatchProviderInterceptor()</code></li> 47 * </ul> <p> 48 * @see com.sun.star.frame.XDispatchProviderInterception 49 */ 50 public class _XDispatchProviderInterception extends MultiMethodTest { 51 52 public XDispatchProviderInterception oObj = null; 53 54 /** 55 * Implementation of <code>XDispatchProviderInterceptor</code> interface 56 * which writes info about method calls to log, stores master and 57 * slave interceptors, and redirect all dispatch queries to the master 58 * provider. 59 */ 60 public class TestInterceptor implements XDispatchProviderInterceptor { 61 private PrintWriter log = null ; 62 public XDispatchProvider master = null, slave = null ; 63 64 public TestInterceptor(PrintWriter log) { 65 this.log = log ; 66 } 67 68 public XDispatchProvider getSlaveDispatchProvider() { 69 log.println("getSlaveDispatchProvider() called.") ; 70 return slave; 71 } 72 public XDispatchProvider getMasterDispatchProvider() { 73 log.println("getMasterDispatchProvider() called.") ; 74 return master; 75 } 76 public void setSlaveDispatchProvider(XDispatchProvider prov) { 77 log.println("setSlaveDispatchProvider(" + prov + ") called.") ; 78 slave = prov ; 79 } 80 public void setMasterDispatchProvider(XDispatchProvider prov) { 81 log.println("setMasterDispatchProvider(" + prov + ") called.") ; 82 master = prov ; 83 } 84 85 public XDispatch queryDispatch(URL url, String frame, int flags) { 86 log.println("my queryDispatch('" + url.Complete + "', '" + 87 frame + "', " + flags + ") called.") ; 88 return slave.queryDispatch(url, frame, flags) ; 89 } 90 public XDispatch[] queryDispatches(DispatchDescriptor[] desc) { 91 log.println("my queryDispatches() called.") ; 92 return slave.queryDispatches(desc) ; 93 } 94 } 95 96 97 TestInterceptor interceptor = null ; 98 /** 99 * Cereates new interceptor implementation. 100 */ 101 public void before() { 102 interceptor = new TestInterceptor(log) ; 103 } 104 105 /** 106 * Registers new interceptor implementation. <p> 107 * Has <b> OK </b> status if during registering interceptor's 108 * <code>setMasterDispatchProvider</code> method with non null 109 * parameter was called. <p> 110 */ 111 public void _registerDispatchProviderInterceptor() { 112 113 boolean result = true ; 114 oObj.registerDispatchProviderInterceptor(interceptor) ; 115 116 result = interceptor.master != null ; 117 118 tRes.tested("registerDispatchProviderInterceptor()", result) ; 119 } 120 121 /** 122 * Releases interceptor. <p> 123 * Has <b> OK </b> status if during method call interceptor's 124 * <code>setMasterDispatchProvider</code> method with <code>null</code> 125 * parameter was called. <p> 126 * The following method tests are to be completed successfully before : 127 * <ul> 128 * <li> <code> registerDispatchProviderInterceptor </code> </li> 129 * </ul> 130 */ 131 public void _releaseDispatchProviderInterceptor() { 132 requiredMethod("registerDispatchProviderInterceptor()") ; 133 134 boolean result = true ; 135 oObj.releaseDispatchProviderInterceptor(interceptor) ; 136 137 result = interceptor.master == null ; 138 139 tRes.tested("releaseDispatchProviderInterceptor()", result) ; 140 } 141 } 142 143