1 /* 2 * This file is part of the LibreOffice project. 3 * 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/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 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 . 17 */ 18 19 package ifc.awt; 20 21 import java.io.PrintWriter; 22 23 import lib.MultiMethodTest; 24 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.text.XTextDocument; 30 import com.sun.star.uno.UnoRuntime; 31 32 /** 33 * Testing <code>com.sun.star.awt.XTopWindow</code> 34 * interface methods : 35 * <ul> 36 * <li><code> addTopWindowListener()</code></li> 37 * <li><code> removeTopWindowListener()</code></li> 38 * <li><code> toFront()</code></li> 39 * <li><code> toBack()</code></li> 40 * <li><code> setMenuBar()</code></li> 41 * </ul> <p> 42 * Test is <b> NOT </b> multithread compliant. <p> 43 * @see com.sun.star.awt.XTopWindow 44 */ 45 public class _XTopWindow extends MultiMethodTest { 46 47 public XTopWindow oObj = null; 48 49 /** 50 * Listener implementation which sets flags on different 51 * method calls. 52 */ 53 protected static class TestListener implements XTopWindowListener { 54 private final PrintWriter log; 55 public boolean activated = false ; 56 public boolean deactivated = false ; 57 TestListener(PrintWriter log)58 public TestListener(PrintWriter log) { 59 this.log = log ; 60 } 61 initListener()62 public void initListener() { 63 activated = false; 64 deactivated = false; 65 } 66 windowOpened(EventObject e)67 public void windowOpened(EventObject e) { 68 log.println("windowOpened() called") ; 69 } windowClosing(EventObject e)70 public void windowClosing(EventObject e) { 71 log.println("windowClosing() called") ; 72 } windowClosed(EventObject e)73 public void windowClosed(EventObject e) { 74 log.println("windowClosed() called") ; 75 } windowMinimized(EventObject e)76 public void windowMinimized(EventObject e) { 77 log.println("windowMinimized() called") ; 78 } windowNormalized(EventObject e)79 public void windowNormalized(EventObject e) { 80 log.println("windowNormalized() called") ; 81 } windowActivated(EventObject e)82 public void windowActivated(EventObject e) { 83 activated = true; 84 log.println("windowActivated() called") ; 85 } windowDeactivated(EventObject e)86 public void windowDeactivated(EventObject e) { 87 deactivated = true; 88 log.println("windowDeactivated() called") ; 89 } disposing(EventObject e)90 public void disposing(EventObject e) {} 91 } 92 93 protected TestListener listener = null ; 94 95 XTextDocument aTextDoc = null; 96 97 98 @Override before()99 protected void before() { 100 aTextDoc = util.WriterTools.createTextDoc(tParam.getMSF()); 101 } 102 103 /** 104 * Adds a listener . <p> 105 * 106 * Has <b>OK</b> status always (listener calls are checked in 107 * other methods. <p> 108 */ _addTopWindowListener()109 public void _addTopWindowListener() { 110 listener = new TestListener(log) ; 111 112 oObj.addTopWindowListener(listener) ; 113 114 tRes.tested("addTopWindowListener()", true); 115 } 116 117 /** 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> 125 */ _removeTopWindowListener()126 public void _removeTopWindowListener() { 127 executeMethod("toBack()"); 128 129 oObj.removeTopWindowListener(listener); 130 131 tRes.tested("removeTopWindowListener()", true); 132 } 133 134 /** 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. 138 */ _toFront()139 public void _toFront() { 140 requiredMethod("addTopWindowListener()"); 141 listener.initListener(); 142 oObj.toFront(); 143 waitForEventIdle(); 144 145 tRes.tested("toFront()", listener.activated && !listener.deactivated); 146 } 147 148 /** 149 * This method doesn't do anything the Office implementation. <p> 150 * So it has always <b>OK</b> status 151 */ _toBack()152 public void _toBack() { 153 oObj.toBack(); 154 tRes.tested("toBack()", true); 155 } 156 157 /** 158 * Creates a simple menu bar and adds to the window. <p> 159 * Has <b>OK</b> status if no runtime exceptions occurred. 160 */ _setMenuBar()161 public void _setMenuBar() { 162 XMenuBar menu = null ; 163 boolean result = true ; 164 165 try { 166 menu = UnoRuntime.queryInterface(XMenuBar.class, 167 tParam.getMSF(). 168 createInstance("com.sun.star.awt.MenuBar")) ; 169 170 menu.insertItem((short)1, "MenuItem", 171 com.sun.star.awt.MenuItemStyle.CHECKABLE, (short)1) ; 172 173 oObj.setMenuBar(menu) ; 174 } catch (com.sun.star.uno.Exception e) { 175 log.println("Can't instantiate MenuBar service") ; 176 result = false ; 177 } 178 179 tRes.tested("setMenuBar()", result) ; 180 } 181 182 /** 183 * Disposes the document created in <code>before</code> method. 184 */ 185 @Override after()186 protected void after() { 187 aTextDoc.dispose(); 188 } 189 } 190 191