1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.util; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.util.XFlushListener; 33 import com.sun.star.util.XFlushable; 34 35 /** 36 * Testing <code>com.sun.star.util.XFlushable</code> 37 * interface methods : 38 * <ul> 39 * <li><code> flush()</code></li> 40 * <li><code> addFlushListener()</code></li> 41 * <li><code> removeFlushListener()</code></li> 42 * </ul> <p> 43 * Test is <b> NOT </b> multithread compilant. <p> 44 * @see com.sun.star.util.XFlushable 45 */ 46 public class _XFlushable extends MultiMethodTest { 47 48 // oObj filled by MultiMethodTest 49 public XFlushable oObj = null ; 50 51 /** 52 * Simple <code>XFlushListener</code> implementation which 53 * just registers if any calls to its methods were made. 54 */ 55 private class MyFlushListener implements XFlushListener{ 56 boolean called = false ; 57 public void flushed(com.sun.star.lang.EventObject e) { 58 called = true ; 59 } 60 public void disposing(com.sun.star.lang.EventObject e) {} 61 public void reset() { called = false; } 62 public boolean wasFlushed() { return called; } 63 } 64 65 private MyFlushListener listener1 = new MyFlushListener(), 66 listener2 = new MyFlushListener() ; 67 68 /** 69 * Test call method <code>flush</code> and checks if added listener 70 * was called and removed one wasn't. <p> 71 * Has OK status if no exception has occured. <p> 72 * Methods to be executed before : 73 * {@link #_addFlushListener}, 74 * {@link #_removeFlushListener} 75 */ 76 public void _flush() { 77 executeMethod("addFlushListener()") ; 78 executeMethod("removeFlushListener()") ; 79 80 oObj.flush() ; 81 82 tRes.tested("flush()", true) ; 83 tRes.tested("addFlushListener()", listener2.wasFlushed()) ; 84 tRes.tested("removeFlushListener()", !listener1.wasFlushed()) ; 85 } 86 87 /** 88 * Test adds two listeners, one of which will be removed then.<p> 89 * Has OK status if the listener was called on <code>flush()</code> 90 * method call. 91 */ 92 public void _addFlushListener() { 93 oObj.addFlushListener(listener1) ; 94 oObj.addFlushListener(listener2) ; 95 } 96 97 /** 98 * Test removes one of two listeners added before. <p> 99 * Has OK status if the listener removed wasn't called on 100 * <code>flush()</code> method call. 101 * Methods to be executed before : 102 * {@link #_addFlushListener}, 103 */ 104 public void _removeFlushListener() { 105 executeMethod("addFlushListener()") ; 106 107 oObj.removeFlushListener(listener1) ; 108 } 109 110 } // finish class _XFlushable 111 112