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