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