1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package ifc.frame; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.MultiMethodTest; 29cdf0e10cSrcweir 30cdf0e10cSrcweir import com.sun.star.frame.DispatchDescriptor; 31cdf0e10cSrcweir import com.sun.star.frame.XDispatch; 32cdf0e10cSrcweir import com.sun.star.frame.XDispatchProvider; 33cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterception; 34cdf0e10cSrcweir import com.sun.star.frame.XDispatchProviderInterceptor; 35cdf0e10cSrcweir import com.sun.star.util.URL; 36cdf0e10cSrcweir 37cdf0e10cSrcweir /** 38cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XDispatchProviderInterception</code> 39cdf0e10cSrcweir * interface methods : 40cdf0e10cSrcweir * <ul> 41cdf0e10cSrcweir * <li><code> registerDispatchProviderInterceptor()</code></li> 42cdf0e10cSrcweir * <li><code> releaseDispatchProviderInterceptor()</code></li> 43cdf0e10cSrcweir * </ul> <p> 44cdf0e10cSrcweir * @see com.sun.star.frame.XDispatchProviderInterception 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir public class _XDispatchProviderInterception extends MultiMethodTest { 47cdf0e10cSrcweir 48cdf0e10cSrcweir public XDispatchProviderInterception oObj = null; 49cdf0e10cSrcweir 50cdf0e10cSrcweir /** 51cdf0e10cSrcweir * Implementation of <code>XDispatchProviderInterceptor</code> interface 52cdf0e10cSrcweir * which writes info about method calls to log, stores master and 53cdf0e10cSrcweir * slave interceptors, and redirect all dispatch queries to the master 54cdf0e10cSrcweir * provider. 55cdf0e10cSrcweir */ 56cdf0e10cSrcweir public class TestInterceptor implements XDispatchProviderInterceptor { 57cdf0e10cSrcweir private PrintWriter log = null ; 58cdf0e10cSrcweir public XDispatchProvider master = null, slave = null ; 59cdf0e10cSrcweir TestInterceptor(PrintWriter log)60cdf0e10cSrcweir public TestInterceptor(PrintWriter log) { 61cdf0e10cSrcweir this.log = log ; 62cdf0e10cSrcweir } 63cdf0e10cSrcweir getSlaveDispatchProvider()64cdf0e10cSrcweir public XDispatchProvider getSlaveDispatchProvider() { 65cdf0e10cSrcweir log.println("getSlaveDispatchProvider() called.") ; 66cdf0e10cSrcweir return slave; 67cdf0e10cSrcweir } getMasterDispatchProvider()68cdf0e10cSrcweir public XDispatchProvider getMasterDispatchProvider() { 69cdf0e10cSrcweir log.println("getMasterDispatchProvider() called.") ; 70cdf0e10cSrcweir return master; 71cdf0e10cSrcweir } setSlaveDispatchProvider(XDispatchProvider prov)72cdf0e10cSrcweir public void setSlaveDispatchProvider(XDispatchProvider prov) { 73cdf0e10cSrcweir log.println("setSlaveDispatchProvider(" + prov + ") called.") ; 74cdf0e10cSrcweir slave = prov ; 75cdf0e10cSrcweir } setMasterDispatchProvider(XDispatchProvider prov)76cdf0e10cSrcweir public void setMasterDispatchProvider(XDispatchProvider prov) { 77cdf0e10cSrcweir log.println("setMasterDispatchProvider(" + prov + ") called.") ; 78cdf0e10cSrcweir master = prov ; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir queryDispatch(URL url, String frame, int flags)81cdf0e10cSrcweir public XDispatch queryDispatch(URL url, String frame, int flags) { 82cdf0e10cSrcweir log.println("my queryDispatch('" + url.Complete + "', '" + 83cdf0e10cSrcweir frame + "', " + flags + ") called.") ; 84cdf0e10cSrcweir return slave.queryDispatch(url, frame, flags) ; 85cdf0e10cSrcweir } queryDispatches(DispatchDescriptor[] desc)86cdf0e10cSrcweir public XDispatch[] queryDispatches(DispatchDescriptor[] desc) { 87cdf0e10cSrcweir log.println("my queryDispatches() called.") ; 88cdf0e10cSrcweir return slave.queryDispatches(desc) ; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir TestInterceptor interceptor = null ; 94cdf0e10cSrcweir /** 95cdf0e10cSrcweir * Cereates new interceptor implementation. 96cdf0e10cSrcweir */ before()97cdf0e10cSrcweir public void before() { 98cdf0e10cSrcweir interceptor = new TestInterceptor(log) ; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir /** 102cdf0e10cSrcweir * Registers new interceptor implementation. <p> 103cdf0e10cSrcweir * Has <b> OK </b> status if during registering interceptor's 104cdf0e10cSrcweir * <code>setMasterDispatchProvider</code> method with non null 105cdf0e10cSrcweir * parameter was called. <p> 106cdf0e10cSrcweir */ _registerDispatchProviderInterceptor()107cdf0e10cSrcweir public void _registerDispatchProviderInterceptor() { 108cdf0e10cSrcweir 109cdf0e10cSrcweir boolean result = true ; 110cdf0e10cSrcweir oObj.registerDispatchProviderInterceptor(interceptor) ; 111cdf0e10cSrcweir 112cdf0e10cSrcweir result = interceptor.master != null ; 113cdf0e10cSrcweir 114cdf0e10cSrcweir tRes.tested("registerDispatchProviderInterceptor()", result) ; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir /** 118cdf0e10cSrcweir * Releases interceptor. <p> 119cdf0e10cSrcweir * Has <b> OK </b> status if during method call interceptor's 120cdf0e10cSrcweir * <code>setMasterDispatchProvider</code> method with <code>null</code> 121cdf0e10cSrcweir * parameter was called. <p> 122cdf0e10cSrcweir * The following method tests are to be completed successfully before : 123cdf0e10cSrcweir * <ul> 124cdf0e10cSrcweir * <li> <code> registerDispatchProviderInterceptor </code> </li> 125cdf0e10cSrcweir * </ul> 126cdf0e10cSrcweir */ _releaseDispatchProviderInterceptor()127cdf0e10cSrcweir public void _releaseDispatchProviderInterceptor() { 128cdf0e10cSrcweir requiredMethod("registerDispatchProviderInterceptor()") ; 129cdf0e10cSrcweir 130cdf0e10cSrcweir boolean result = true ; 131cdf0e10cSrcweir oObj.releaseDispatchProviderInterceptor(interceptor) ; 132cdf0e10cSrcweir 133cdf0e10cSrcweir result = interceptor.master == null ; 134cdf0e10cSrcweir 135cdf0e10cSrcweir tRes.tested("releaseDispatchProviderInterceptor()", result) ; 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139