xref: /AOO41X/main/qadevOOo/tests/java/ifc/awt/_XTopWindow.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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.awt;
29 
30 import java.io.PrintWriter;
31 
32 import lib.MultiMethodTest;
33 
34 import com.sun.star.awt.XMenuBar;
35 import com.sun.star.awt.XTopWindow;
36 import com.sun.star.awt.XTopWindowListener;
37 import com.sun.star.lang.EventObject;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 
42 /**
43 * Testing <code>com.sun.star.awt.XTopWindow</code>
44 * interface methods :
45 * <ul>
46 *  <li><code> addTopWindowListener()</code></li>
47 *  <li><code> removeTopWindowListener()</code></li>
48 *  <li><code> toFront()</code></li>
49 *  <li><code> toBack()</code></li>
50 *  <li><code> setMenuBar()</code></li>
51 * </ul> <p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.awt.XTopWindow
54 */
55 public class _XTopWindow extends MultiMethodTest {
56 
57     public XTopWindow oObj = null;
58 
59     /**
60     * Listener implementation which sets flags on different
61     * method calls.
62     */
63     protected class TestListener implements XTopWindowListener {
64         private PrintWriter log = null ;
65         public boolean activated = false ;
66         public boolean deactivated = false ;
67 
68         public TestListener(PrintWriter log) {
69             this.log = log ;
70         }
71 
72         public void initListener() {
73             activated = false;
74             deactivated = false;
75         }
76 
77         public void windowOpened(EventObject e) {
78             log.println("windowOpened() called") ;
79         }
80         public void windowClosing(EventObject e) {
81             log.println("windowClosing() called") ;
82         }
83         public void windowClosed(EventObject e) {
84             log.println("windowClosed() called") ;
85         }
86         public void windowMinimized(EventObject e) {
87             log.println("windowMinimized() called") ;
88         }
89         public void windowNormalized(EventObject e) {
90             log.println("windowNormalized() called") ;
91         }
92         public void windowActivated(EventObject e) {
93             activated = true;
94             log.println("windowActivated() called") ;
95         }
96         public void windowDeactivated(EventObject e) {
97             deactivated = true;
98             log.println("windowDeactivated() called") ;
99         }
100         public void disposing(EventObject e) {}
101     }
102 
103     protected TestListener listener = null ;
104 
105     XTextDocument aTextDoc = null;
106 
107 
108     protected void before() {
109         aTextDoc = util.WriterTools.createTextDoc((XMultiServiceFactory)tParam.getMSF());
110     }
111 
112     /**
113      * Adds a listener . <p>
114      *
115      * Has <b>OK</b> status always (listener calls are checked in
116      * other methods. <p>
117      */
118     public void _addTopWindowListener() {
119         listener = new TestListener(log) ;
120 
121         oObj.addTopWindowListener(listener) ;
122 
123         tRes.tested("addTopWindowListener()", true);
124     }
125 
126     /**
127      * Removes a listener added before. <p>
128      * Has <b>OK</b> status always. <p>
129      * The following method tests are to be completed successfully before :
130      * <ul>
131      *  <li> <code> toBack </code> : to have a definite method execution
132      *    order.</li>
133      * </ul>
134      */
135     public void _removeTopWindowListener() {
136         executeMethod("toBack()");
137 
138         oObj.removeTopWindowListener(listener);
139 
140         tRes.tested("removeTopWindowListener()", true);
141     }
142 
143     /**
144      * Moves the window to front and check the listener calls. <p>
145      * Has <b>OK</b> status if listener <code>activated</code> method
146      * was called.
147      */
148     public void _toFront() {
149         requiredMethod("addTopWindowListener()");
150         listener.initListener();
151         oObj.toFront();
152         shortWait();
153 
154         tRes.tested("toFront()", listener.activated && !listener.deactivated);
155     }
156 
157     /**
158      * This method doesn't do anything the Office implementation. <p>
159      * So it has always <b>OK</b> status
160      */
161     public void _toBack() {
162         oObj.toBack();
163         tRes.tested("toBack()", true);
164     }
165 
166     /**
167     * Creates a simple menu bar and adds to the window. <p>
168     * Has <b>OK</b> status if no runtime exceptions occured.
169     */
170     public void _setMenuBar() {
171         XMenuBar menu = null ;
172         boolean result = true ;
173 
174         try {
175             menu = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class,
176                 ((XMultiServiceFactory)tParam.getMSF()).
177                 createInstance("com.sun.star.awt.MenuBar")) ;
178         } catch (com.sun.star.uno.Exception e) {
179             log.println("Can't instanciate MenuBar service") ;
180             result = false ;
181         }
182 
183         menu.insertItem((short)1, "MenuItem",
184             com.sun.star.awt.MenuItemStyle.CHECKABLE, (short)1) ;
185 
186         oObj.setMenuBar(menu) ;
187 
188         tRes.tested("setMenuBar()", result) ;
189     }
190 
191     /**
192      * Disposes the document created in <code>before</code> method.
193      */
194     protected void after() {
195         aTextDoc.dispose();
196     }
197 
198     private void shortWait() {
199         try {
200             Thread.sleep(1000) ;
201         } catch (InterruptedException e) {
202             System.out.println("While waiting :" + e) ;
203         }
204     }
205 }
206 
207