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.util;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.util.XRefreshListener;
29 import com.sun.star.util.XRefreshable;
30 
31 /**
32 * Testing <code>com.sun.star.util.XRefreshable</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> refresh()</code></li>
36 *  <li><code> addRefreshListener()</code></li>
37 *  <li><code> removeRefreshListener()</code></li>
38 * </ul> <p>
39 * Test is <b> NOT </b> multithread compilant. <p>
40 * @see com.sun.star.util.XRefreshable
41 */
42 public class _XRefreshable extends MultiMethodTest {
43 
44     public XRefreshable oObj = null;
45 
46     final boolean listenerCalled[] = new boolean[1];
47 
48 
49     /**
50     * <code>XRefreshListener</code> implementation which
51     * sets a flag when <code>refreshed</code> method is
52     * called.
53     */
54     public class MyRefreshListener implements XRefreshListener {
refreshed(com.sun.star.lang.EventObject e)55         public void refreshed (com.sun.star.lang.EventObject e) {
56             listenerCalled[0] = true;
57         }
58 
disposing(com.sun.star.lang.EventObject obj)59         public void disposing (com.sun.star.lang.EventObject obj) {}
60     }
61 
62     XRefreshListener listener = new MyRefreshListener();
63 
64     /**
65     * Just adds a listener. <p>
66     * Always has <b>OK</b> status.
67     */
_addRefreshListener()68     public void _addRefreshListener() {
69 
70          oObj.addRefreshListener(listener) ;
71          tRes.tested("addRefreshListener()", true);
72     }
73 
74     /**
75     * Calls the method and checks if the listener was called. <p>
76     * Has <b>OK</b> status if listener's flag is set after call.
77     * The following method tests are to be completed successfully before :
78     * <ul>
79     *  <li> <code> addRefreshListener </code> : to have a listener added.</li>
80     * </ul>
81     */
_refresh()82     public void _refresh() {
83 
84         requiredMethod("addRefreshListener()");
85 
86         oObj.refresh();
87 
88         tRes.tested("refresh()", listenerCalled[0]);
89         if (!listenerCalled[0])
90             log.println("RefreshListener wasn't called after refresh");
91 
92     }
93 
94     /**
95     * Removes the listener added before and calls <code>refresh</code>
96     * method. Listener must not be called. <p>
97     * Has <b>OK</b> status if listener's flag isn't changed.
98     * <ul>
99     *  <li> <code> refresh </code> : listener added must be already
100     *    tested.</li>
101     * </ul>
102     */
_removeRefreshListener()103     public void _removeRefreshListener() {
104         requiredMethod("refresh()");
105         listenerCalled[0] = false;
106 
107         oObj.removeRefreshListener(listener) ;
108         oObj.refresh();
109 
110         tRes.tested("removeRefreshListener()", !listenerCalled[0]);
111         if (listenerCalled[0])
112             log.println("RefreshListener was called after removing");
113     }
114 } // finish class _XRefreshable
115 
116