Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / awt / _XTopWindow.java
blobaa47164c362df4ea5d6f289c74322992d407746d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTopWindow.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.awt;
33 import java.io.PrintWriter;
35 import lib.MultiMethodTest;
37 import com.sun.star.awt.XMenuBar;
38 import com.sun.star.awt.XTopWindow;
39 import com.sun.star.awt.XTopWindowListener;
40 import com.sun.star.lang.EventObject;
41 import com.sun.star.lang.XMultiServiceFactory;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
45 /**
46 * Testing <code>com.sun.star.awt.XTopWindow</code>
47 * interface methods :
48 * <ul>
49 * <li><code> addTopWindowListener()</code></li>
50 * <li><code> removeTopWindowListener()</code></li>
51 * <li><code> toFront()</code></li>
52 * <li><code> toBack()</code></li>
53 * <li><code> setMenuBar()</code></li>
54 * </ul> <p>
55 * Test is <b> NOT </b> multithread compilant. <p>
56 * @see com.sun.star.awt.XTopWindow
58 public class _XTopWindow extends MultiMethodTest {
60 public XTopWindow oObj = null;
62 /**
63 * Listener implementation which sets flags on different
64 * method calls.
66 protected class TestListener implements XTopWindowListener {
67 private PrintWriter log = null ;
68 public boolean activated = false ;
69 public boolean deactivated = false ;
71 public TestListener(PrintWriter log) {
72 this.log = log ;
75 public void initListener() {
76 activated = false;
77 deactivated = false;
80 public void windowOpened(EventObject e) {
81 log.println("windowOpened() called") ;
83 public void windowClosing(EventObject e) {
84 log.println("windowClosing() called") ;
86 public void windowClosed(EventObject e) {
87 log.println("windowClosed() called") ;
89 public void windowMinimized(EventObject e) {
90 log.println("windowMinimized() called") ;
92 public void windowNormalized(EventObject e) {
93 log.println("windowNormalized() called") ;
95 public void windowActivated(EventObject e) {
96 activated = true;
97 log.println("windowActivated() called") ;
99 public void windowDeactivated(EventObject e) {
100 deactivated = true;
101 log.println("windowDeactivated() called") ;
103 public void disposing(EventObject e) {}
106 protected TestListener listener = null ;
108 XTextDocument aTextDoc = null;
111 protected void before() {
112 aTextDoc = util.WriterTools.createTextDoc((XMultiServiceFactory)tParam.getMSF());
116 * Adds a listener . <p>
118 * Has <b>OK</b> status always (listener calls are checked in
119 * other methods. <p>
121 public void _addTopWindowListener() {
122 listener = new TestListener(log) ;
124 oObj.addTopWindowListener(listener) ;
126 tRes.tested("addTopWindowListener()", true);
130 * Removes a listener added before. <p>
131 * Has <b>OK</b> status always. <p>
132 * The following method tests are to be completed successfully before :
133 * <ul>
134 * <li> <code> toBack </code> : to have a definite method execution
135 * order.</li>
136 * </ul>
138 public void _removeTopWindowListener() {
139 executeMethod("toBack()");
141 oObj.removeTopWindowListener(listener);
143 tRes.tested("removeTopWindowListener()", true);
147 * Moves the window to front and check the listener calls. <p>
148 * Has <b>OK</b> status if listener <code>activated</code> method
149 * was called.
151 public void _toFront() {
152 requiredMethod("addTopWindowListener()");
153 listener.initListener();
154 oObj.toFront();
155 shortWait();
157 tRes.tested("toFront()", listener.activated && !listener.deactivated);
161 * This method doesn't do anything the Office implementation. <p>
162 * So it has always <b>OK</b> status
164 public void _toBack() {
165 oObj.toBack();
166 tRes.tested("toBack()", true);
170 * Creates a simple menu bar and adds to the window. <p>
171 * Has <b>OK</b> status if no runtime exceptions occured.
173 public void _setMenuBar() {
174 XMenuBar menu = null ;
175 boolean result = true ;
177 try {
178 menu = (XMenuBar) UnoRuntime.queryInterface(XMenuBar.class,
179 ((XMultiServiceFactory)tParam.getMSF()).
180 createInstance("com.sun.star.awt.MenuBar")) ;
181 } catch (com.sun.star.uno.Exception e) {
182 log.println("Can't instanciate MenuBar service") ;
183 result = false ;
186 menu.insertItem((short)1, "MenuItem",
187 com.sun.star.awt.MenuItemStyle.CHECKABLE, (short)1) ;
189 oObj.setMenuBar(menu) ;
191 tRes.tested("setMenuBar()", result) ;
195 * Disposes the document created in <code>before</code> method.
197 protected void after() {
198 aTextDoc.dispose();
201 private void shortWait() {
202 try {
203 Thread.sleep(1000) ;
204 } catch (InterruptedException e) {
205 System.out.println("While waiting :" + e) ;