bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / awt / _XTopWindow.java
blobca056c780afde081353ecbcdf240d901d3da2ace
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package ifc.awt;
21 import java.io.PrintWriter;
23 import lib.MultiMethodTest;
25 import com.sun.star.awt.XMenuBar;
26 import com.sun.star.awt.XTopWindow;
27 import com.sun.star.awt.XTopWindowListener;
28 import com.sun.star.lang.EventObject;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XTextDocument;
31 import com.sun.star.uno.UnoRuntime;
33 /**
34 * Testing <code>com.sun.star.awt.XTopWindow</code>
35 * interface methods :
36 * <ul>
37 * <li><code> addTopWindowListener()</code></li>
38 * <li><code> removeTopWindowListener()</code></li>
39 * <li><code> toFront()</code></li>
40 * <li><code> toBack()</code></li>
41 * <li><code> setMenuBar()</code></li>
42 * </ul> <p>
43 * Test is <b> NOT </b> multithread compilant. <p>
44 * @see com.sun.star.awt.XTopWindow
46 public class _XTopWindow extends MultiMethodTest {
48 public XTopWindow oObj = null;
50 /**
51 * Listener implementation which sets flags on different
52 * method calls.
54 protected class TestListener implements XTopWindowListener {
55 private PrintWriter log = null ;
56 public boolean activated = false ;
57 public boolean deactivated = false ;
59 public TestListener(PrintWriter log) {
60 this.log = log ;
63 public void initListener() {
64 activated = false;
65 deactivated = false;
68 public void windowOpened(EventObject e) {
69 log.println("windowOpened() called") ;
71 public void windowClosing(EventObject e) {
72 log.println("windowClosing() called") ;
74 public void windowClosed(EventObject e) {
75 log.println("windowClosed() called") ;
77 public void windowMinimized(EventObject e) {
78 log.println("windowMinimized() called") ;
80 public void windowNormalized(EventObject e) {
81 log.println("windowNormalized() called") ;
83 public void windowActivated(EventObject e) {
84 activated = true;
85 log.println("windowActivated() called") ;
87 public void windowDeactivated(EventObject e) {
88 deactivated = true;
89 log.println("windowDeactivated() called") ;
91 public void disposing(EventObject e) {}
94 protected TestListener listener = null ;
96 XTextDocument aTextDoc = null;
99 protected void before() {
100 aTextDoc = util.WriterTools.createTextDoc((XMultiServiceFactory)tParam.getMSF());
104 * Adds a listener . <p>
106 * Has <b>OK</b> status always (listener calls are checked in
107 * other methods. <p>
109 public void _addTopWindowListener() {
110 listener = new TestListener(log) ;
112 oObj.addTopWindowListener(listener) ;
114 tRes.tested("addTopWindowListener()", true);
118 * Removes a listener added before. <p>
119 * Has <b>OK</b> status always. <p>
120 * The following method tests are to be completed successfully before :
121 * <ul>
122 * <li> <code> toBack </code> : to have a definite method execution
123 * order.</li>
124 * </ul>
126 public void _removeTopWindowListener() {
127 executeMethod("toBack()");
129 oObj.removeTopWindowListener(listener);
131 tRes.tested("removeTopWindowListener()", true);
135 * Moves the window to front and check the listener calls. <p>
136 * Has <b>OK</b> status if listener <code>activated</code> method
137 * was called.
139 public void _toFront() {
140 requiredMethod("addTopWindowListener()");
141 listener.initListener();
142 oObj.toFront();
143 shortWait();
145 tRes.tested("toFront()", listener.activated && !listener.deactivated);
149 * This method doesn't do anything the Office implementation. <p>
150 * So it has always <b>OK</b> status
152 public void _toBack() {
153 oObj.toBack();
154 tRes.tested("toBack()", true);
158 * Creates a simple menu bar and adds to the window. <p>
159 * Has <b>OK</b> status if no runtime exceptions occurred.
161 public void _setMenuBar() {
162 XMenuBar menu = null ;
163 boolean result = true ;
165 try {
166 menu = UnoRuntime.queryInterface(XMenuBar.class,
167 ((XMultiServiceFactory)tParam.getMSF()).
168 createInstance("com.sun.star.awt.MenuBar")) ;
169 } catch (com.sun.star.uno.Exception e) {
170 log.println("Can't instanciate MenuBar service") ;
171 result = false ;
174 menu.insertItem((short)1, "MenuItem",
175 com.sun.star.awt.MenuItemStyle.CHECKABLE, (short)1) ;
177 oObj.setMenuBar(menu) ;
179 tRes.tested("setMenuBar()", result) ;
183 * Disposes the document created in <code>before</code> method.
185 protected void after() {
186 aTextDoc.dispose();
189 private void shortWait() {
190 try {
191 Thread.sleep(1000) ;
192 } catch (InterruptedException e) {
193 System.out.println("While waiting :" + e) ;