1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.awt;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.awt.Rectangle;
29 import com.sun.star.awt.WindowDescriptor;
30 import com.sun.star.awt.XDevice;
31 import com.sun.star.awt.XRegion;
32 import com.sun.star.awt.XToolkit;
33 import com.sun.star.awt.XWindowPeer;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.uno.UnoRuntime;
36 
37 /**
38 * Testing <code>com.sun.star.awt.XToolkit</code>
39 * interface methods:
40 * <ul>
41 *  <li><code> getDesktopWindow() </code></li>
42 *  <li><code> getWorkArea() </code></li>
43 *  <li><code> createWindow() </code></li>
44 *  <li><code> createWindows() </code></li>
45 *  <li><code> createScreenCompatibleDevice() </code></li>
46 *  <li><code> createRegion() </code></li>
47 * </ul><p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.awt.XToolkit
50 */
51 public class _XToolkit extends MultiMethodTest {
52     public XToolkit oObj = null;
53 
54     /**
55     * Test calls the method. <p>
56     * Has <b> OK </b> status always, because Desktop component
57     * currently is not supported as visible.
58     */
_getDesktopWindow()59     public void _getDesktopWindow() {
60         XWindowPeer win = oObj.getDesktopWindow();
61         if (win == null) {
62             log.println("getDesktopWindow() returns NULL");
63         }
64         tRes.tested("getDesktopWindow()", true);
65     }
66 
67     /**
68     * Test calls the method. <p>
69     * Has <b> OK </b> status if the method does not return null.
70     */
_getWorkArea()71     public void _getWorkArea() {
72         Rectangle area = oObj.getWorkArea();
73         tRes.tested("getWorkArea()", area != null);
74     }
75 
76     /**
77     * Test calls the method. <p>
78     * Has <b> OK </b> status if the method does not return null.
79     */
_createWindow()80     public void _createWindow() {
81         boolean res = false;
82         try {
83             XWindowPeer cWin = oObj.createWindow(
84                 createDesc(new Rectangle(0,0,100,100)));
85             if (cWin == null) {
86                 log.println("createWindow() create a NULL Object");
87             } else {
88                 UnoRuntime.queryInterface(XComponent.class, cWin).dispose();
89                 res = true;
90             }
91         } catch (com.sun.star.lang.IllegalArgumentException ex) {
92             log.println("Exception occured while checking 'createWindow':");
93             ex.printStackTrace(log);
94         }
95         tRes.tested("createWindow()", res);
96     }
97 
98     /**
99     * After defining of WindowDescriptor array, test calls the method. <p>
100     * Has <b> OK </b> status if all elements of the returned array are
101     * not null.
102     */
_createWindows()103     public void _createWindows() {
104         boolean res = false;
105         try {
106             WindowDescriptor[] descs = new WindowDescriptor[2];
107             descs[0] = createDesc(new Rectangle(0,0,100,100));
108             descs[1] = createDesc(new Rectangle(100,100,200,200));
109             XWindowPeer[] cWins = oObj.createWindows(descs);
110             if ( (cWins[0] == null) || (cWins[1] == null) ) {
111                 log.println("createWindows() creates NULL Windows");
112             } else {
113                 UnoRuntime.queryInterface(XComponent.class, cWins[0]).dispose();
114                 UnoRuntime.queryInterface(XComponent.class, cWins[1]).dispose();
115                 res = true;
116             }
117         } catch (com.sun.star.lang.IllegalArgumentException ex) {
118             log.println("Exception occured while checking 'createWindows':");
119             ex.printStackTrace(log);
120         }
121         tRes.tested("createWindows()", res);
122     }
123 
124     /**
125     * Test calls the method. <p>
126     * Has <b> OK </b> status if the method does not return null.
127     */
_createScreenCompatibleDevice()128     public void _createScreenCompatibleDevice() {
129         XDevice dev = oObj.createScreenCompatibleDevice(100, 100);
130         tRes.tested("createScreenCompatibleDevice()", dev != null);
131     }
132 
133     /**
134     * Test calls the method. <p>
135     * Has <b> OK </b> status if the method does not return null.
136     */
_createRegion()137     public void _createRegion() {
138         XRegion reg = oObj.createRegion();
139         tRes.tested("createRegion()", reg != null);
140     }
141 
142     /**
143     * Just creates the WindowDescriptor as an argument for createWindow().
144     */
createDesc(Rectangle rect)145     public WindowDescriptor createDesc(Rectangle rect) {
146         XWindowPeer win = (XWindowPeer) tEnv.getObjRelation("WINPEER");
147         return new WindowDescriptor(com.sun.star.awt.WindowClass.TOP,
148             "", win, (short) -1, rect, com.sun.star.awt.WindowAttribute.SHOW);
149     }
150 
151 }
152 
153