1 /*
2  * This file is part of the LibreOffice project.
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
10  *   Licensed to the Apache Software Foundation (ASF) under one or more
11  *   contributor license agreements. See the NOTICE file distributed
12  *   with this work for additional information regarding copyright
13  *   ownership. The ASF licenses this file to you under the Apache
14  *   License, Version 2.0 (the "License"); you may not use this file
15  *   except in compliance with the License. You may obtain a copy of
16  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17  */
18 
19 package ifc.util;
20 
21 import lib.MultiMethodTest;
22 
23 import com.sun.star.util.XFlushListener;
24 import com.sun.star.util.XFlushable;
25 
26 /**
27  * Testing <code>com.sun.star.util.XFlushable</code>
28  * interface methods :
29  * <ul>
30  *  <li><code> flush()</code></li>
31  *  <li><code> addFlushListener()</code></li>
32  *  <li><code> removeFlushListener()</code></li>
33  * </ul> <p>
34  * Test is <b> NOT </b> multithread compliant. <p>
35  * @see com.sun.star.util.XFlushable
36  */
37 public class _XFlushable extends MultiMethodTest {
38 
39     // oObj filled by MultiMethodTest
40     public XFlushable oObj = null ;
41 
42     /**
43      * Simple <code>XFlushListener</code> implementation which
44      * just registers if any calls to its methods were made.
45      */
46     private static class MyFlushListener implements XFlushListener{
47         boolean called = false ;
flushed(com.sun.star.lang.EventObject e)48         public void flushed(com.sun.star.lang.EventObject e) {
49             called = true ;
50         }
disposing(com.sun.star.lang.EventObject e)51         public void disposing(com.sun.star.lang.EventObject e) {}
wasFlushed()52         public boolean wasFlushed() { return called; }
53     }
54 
55     private final MyFlushListener listener1 = new MyFlushListener(),
56                             listener2 = new MyFlushListener() ;
57 
58     /**
59     * Test call method <code>flush</code> and checks if added listener
60     * was called and removed one wasn't. <p>
61     * Has OK status if no exception has occurred. <p>
62     *     Methods to be executed before :
63     * {@link #_addFlushListener},
64     * {@link #_removeFlushListener}
65     */
_flush()66     public void _flush() {
67         executeMethod("addFlushListener()") ;
68         executeMethod("removeFlushListener()") ;
69 
70         oObj.flush() ;
71 
72         tRes.tested("flush()", true) ;
73         tRes.tested("addFlushListener()", listener2.wasFlushed()) ;
74         tRes.tested("removeFlushListener()", !listener1.wasFlushed()) ;
75     }
76 
77     /**
78     * Test adds two listeners, one of which will be removed then.<p>
79     * Has OK status if the listener was called on <code>flush()</code>
80     * method call.
81     */
_addFlushListener()82     public void _addFlushListener() {
83         oObj.addFlushListener(listener1) ;
84         oObj.addFlushListener(listener2) ;
85     }
86 
87     /**
88     * Test removes one of two listeners added before. <p>
89     * Has OK status if the listener removed wasn't called on
90     * <code>flush()</code> method call.
91     *     Methods to be executed before :
92     * {@link #_addFlushListener},
93     */
_removeFlushListener()94     public void _removeFlushListener() {
95         executeMethod("addFlushListener()") ;
96 
97         oObj.removeFlushListener(listener1) ;
98     }
99 
100 }  // finish class _XFlushable
101 
102