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.XFlushListener;
29 import com.sun.star.util.XFlushable;
30 
31 /**
32  * Testing <code>com.sun.star.util.XFlushable</code>
33  * interface methods :
34  * <ul>
35  *  <li><code> flush()</code></li>
36  *  <li><code> addFlushListener()</code></li>
37  *  <li><code> removeFlushListener()</code></li>
38  * </ul> <p>
39  * Test is <b> NOT </b> multithread compilant. <p>
40  * @see com.sun.star.util.XFlushable
41  */
42 public class _XFlushable extends MultiMethodTest {
43 
44     // oObj filled by MultiMethodTest
45     public XFlushable oObj = null ;
46 
47     /**
48      * Simple <code>XFlushListener</code> implementation which
49      * just registers if any calls to its methods were made.
50      */
51     private class MyFlushListener implements XFlushListener{
52         boolean called = false ;
flushed(com.sun.star.lang.EventObject e)53         public void flushed(com.sun.star.lang.EventObject e) {
54             called = true ;
55         }
disposing(com.sun.star.lang.EventObject e)56         public void disposing(com.sun.star.lang.EventObject e) {}
reset()57         public void reset() { called = false; }
wasFlushed()58         public boolean wasFlushed() { return called; }
59     }
60 
61     private MyFlushListener listener1 = new MyFlushListener(),
62                             listener2 = new MyFlushListener() ;
63 
64     /**
65     * Test call method <code>flush</code> and checks if added listener
66     * was called and removed one wasn't. <p>
67     * Has OK status if no exception has occured. <p>
68     *     Methods to be executed before :
69     * {@link #_addFlushListener},
70     * {@link #_removeFlushListener}
71     */
_flush()72     public void _flush() {
73         executeMethod("addFlushListener()") ;
74         executeMethod("removeFlushListener()") ;
75 
76         oObj.flush() ;
77 
78         tRes.tested("flush()", true) ;
79         tRes.tested("addFlushListener()", listener2.wasFlushed()) ;
80         tRes.tested("removeFlushListener()", !listener1.wasFlushed()) ;
81     }
82 
83     /**
84     * Test adds two listeners, one of which will be removed then.<p>
85     * Has OK status if the listener was called on <code>flush()</code>
86     * method call.
87     */
_addFlushListener()88     public void _addFlushListener() {
89         oObj.addFlushListener(listener1) ;
90         oObj.addFlushListener(listener2) ;
91     }
92 
93     /**
94     * Test removes one of two listeners added before. <p>
95     * Has OK status if the listener removed wasn't called on
96     * <code>flush()</code> method call.
97     *     Methods to be executed before :
98     * {@link #_addFlushListener},
99     */
_removeFlushListener()100     public void _removeFlushListener() {
101         executeMethod("addFlushListener()") ;
102 
103         oObj.removeFlushListener(listener1) ;
104     }
105 
106 }  // finish class _XFlushable
107 
108