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 lib.MultiMethodTest; 31 32 import com.sun.star.awt.Rectangle; 33 import com.sun.star.awt.WindowDescriptor; 34 import com.sun.star.awt.XDevice; 35 import com.sun.star.awt.XRegion; 36 import com.sun.star.awt.XToolkit; 37 import com.sun.star.awt.XWindowPeer; 38 import com.sun.star.lang.XComponent; 39 import com.sun.star.uno.UnoRuntime; 40 41 /** 42 * Testing <code>com.sun.star.awt.XToolkit</code> 43 * interface methods: 44 * <ul> 45 * <li><code> getDesktopWindow() </code></li> 46 * <li><code> getWorkArea() </code></li> 47 * <li><code> createWindow() </code></li> 48 * <li><code> createWindows() </code></li> 49 * <li><code> createScreenCompatibleDevice() </code></li> 50 * <li><code> createRegion() </code></li> 51 * </ul><p> 52 * Test is <b> NOT </b> multithread compilant. <p> 53 * @see com.sun.star.awt.XToolkit 54 */ 55 public class _XToolkit extends MultiMethodTest { 56 public XToolkit oObj = null; 57 58 /** 59 * Test calls the method. <p> 60 * Has <b> OK </b> status always, because Desktop component 61 * currently is not supported as visible. 62 */ 63 public void _getDesktopWindow() { 64 XWindowPeer win = oObj.getDesktopWindow(); 65 if (win == null) { 66 log.println("getDesktopWindow() returns NULL"); 67 } 68 tRes.tested("getDesktopWindow()", true); 69 } 70 71 /** 72 * Test calls the method. <p> 73 * Has <b> OK </b> status if the method does not return null. 74 */ 75 public void _getWorkArea() { 76 Rectangle area = oObj.getWorkArea(); 77 tRes.tested("getWorkArea()", area != null); 78 } 79 80 /** 81 * Test calls the method. <p> 82 * Has <b> OK </b> status if the method does not return null. 83 */ 84 public void _createWindow() { 85 boolean res = false; 86 try { 87 XWindowPeer cWin = oObj.createWindow( 88 createDesc(new Rectangle(0,0,100,100))); 89 if (cWin == null) { 90 log.println("createWindow() create a NULL Object"); 91 } else { 92 UnoRuntime.queryInterface(XComponent.class, cWin).dispose(); 93 res = true; 94 } 95 } catch (com.sun.star.lang.IllegalArgumentException ex) { 96 log.println("Exception occured while checking 'createWindow':"); 97 ex.printStackTrace(log); 98 } 99 tRes.tested("createWindow()", res); 100 } 101 102 /** 103 * After defining of WindowDescriptor array, test calls the method. <p> 104 * Has <b> OK </b> status if all elements of the returned array are 105 * not null. 106 */ 107 public void _createWindows() { 108 boolean res = false; 109 try { 110 WindowDescriptor[] descs = new WindowDescriptor[2]; 111 descs[0] = createDesc(new Rectangle(0,0,100,100)); 112 descs[1] = createDesc(new Rectangle(100,100,200,200)); 113 XWindowPeer[] cWins = oObj.createWindows(descs); 114 if ( (cWins[0] == null) || (cWins[1] == null) ) { 115 log.println("createWindows() creates NULL Windows"); 116 } else { 117 UnoRuntime.queryInterface(XComponent.class, cWins[0]).dispose(); 118 UnoRuntime.queryInterface(XComponent.class, cWins[1]).dispose(); 119 res = true; 120 } 121 } catch (com.sun.star.lang.IllegalArgumentException ex) { 122 log.println("Exception occured while checking 'createWindows':"); 123 ex.printStackTrace(log); 124 } 125 tRes.tested("createWindows()", res); 126 } 127 128 /** 129 * Test calls the method. <p> 130 * Has <b> OK </b> status if the method does not return null. 131 */ 132 public void _createScreenCompatibleDevice() { 133 XDevice dev = oObj.createScreenCompatibleDevice(100, 100); 134 tRes.tested("createScreenCompatibleDevice()", dev != null); 135 } 136 137 /** 138 * Test calls the method. <p> 139 * Has <b> OK </b> status if the method does not return null. 140 */ 141 public void _createRegion() { 142 XRegion reg = oObj.createRegion(); 143 tRes.tested("createRegion()", reg != null); 144 } 145 146 /** 147 * Just creates the WindowDescriptor as an argument for createWindow(). 148 */ 149 public WindowDescriptor createDesc(Rectangle rect) { 150 XWindowPeer win = (XWindowPeer) tEnv.getObjRelation("WINPEER"); 151 return new WindowDescriptor(com.sun.star.awt.WindowClass.TOP, 152 "", win, (short) -1, rect, com.sun.star.awt.WindowAttribute.SHOW); 153 } 154 155 } 156 157