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