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.XControl; 33 import com.sun.star.awt.XControlModel; 34 import com.sun.star.awt.XToolkit; 35 import com.sun.star.awt.XView; 36 import com.sun.star.awt.XWindowPeer; 37 import com.sun.star.uno.XInterface; 38 39 /** 40 * Testing <code>com.sun.star.awt.XControl</code> 41 * interface methods: 42 * <ul> 43 * <li><code> setContext() </code></li> 44 * <li><code> getContext() </code></li> 45 * <li><code> createPeer() </code></li> 46 * <li><code> getPeer() </code></li> 47 * <li><code> setModel() </code></li> 48 * <li><code> getModel() </code></li> 49 * <li><code> setDesignMode() </code></li> 50 * <li><code> isDesignMode() </code></li> 51 * <li><code> isTransparent() </code></li> 52 * <li><code> getView() </code></li> 53 * </ul><p> 54 * This test needs the following object relations : 55 * <ul> 56 * <li> <code>'CONTEXT'</code> (of type <code>XInterface</code>): 57 * used as a parameter to setContext() and for testing getContext().</li> 58 * <li> <code>'WINPEER'</code> (of type <code>XWindowPeer</code>): 59 * used as a parameter to createPeer() and for testing getPeer()</li> 60 * <li> <code>'TOOLKIT'</code> (of type <code>XToolkit</code>): 61 * used as a parameter to createPeer()</li> 62 * <li> <code>'MODEL'</code> (of type <code>XControlModel</code>): 63 * used as a parameter to setModel() and for testing getModel()</li> 64 * <ul> <p> 65 * Test is <b> NOT </b> multithread compilant. <p> 66 * @see com.sun.star.awt.XControl 67 */ 68 public class _XControl extends MultiMethodTest { 69 public XControl oObj = null; 70 public XControlModel aModel = null; 71 public boolean desMode; 72 73 /** 74 * After test calls the method, the Context is set to a corresponding 75 * object relation.<p> 76 * Has <b> OK </b> status if the method successfully returns 77 * and no exceptions were thrown. <p> 78 */ 79 public void _setContext() { 80 XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT"); 81 oObj.setContext(cont); 82 tRes.tested("setContext()",true); 83 } 84 85 /** 86 * After test calls the method, the Context is gotten and compared 87 * with object relation 'CONTEXT'.<p> 88 * Has <b> OK </b> status if get value is equals to value set before.<p> 89 * The following method tests are to be completed successfully before: 90 * <ul> 91 * <li> <code> setContext() </code> : set Context to a corresponding 92 * object relation</li> 93 * </ul> 94 */ 95 public void _getContext() { 96 requiredMethod("setContext()"); 97 XInterface cont = (XInterface) tEnv.getObjRelation("CONTEXT"); 98 Object get = oObj.getContext(); 99 boolean res = get.equals(cont); 100 if (!res) { 101 log.println("!!! Error: getting: "+get.toString()); 102 log.println("!!! expected: "+cont.toString()); 103 } 104 tRes.tested("getContext()",res); 105 } 106 107 108 /** 109 * The objects needed to create peer are obtained 110 * from corresponding object relations, then the peer is created. 111 * <p> 112 * Has <b> OK </b> status if the method successfully returns 113 * and no exceptions were thrown. 114 */ 115 public void _createPeer() { 116 XWindowPeer the_win = (XWindowPeer) tEnv.getObjRelation("WINPEER"); 117 XToolkit the_kit = (XToolkit) tEnv.getObjRelation("TOOLKIT"); 118 oObj.createPeer(the_kit,the_win); 119 tRes.tested("createPeer()",true); 120 } 121 122 /** 123 * Test calls the method. Then the the object ralation 'WINPEER' is 124 * obtained, and compared with the peer, gotten from (XControl) oObj 125 * variable.<p> 126 * Has <b> OK </b> status if peer gotten isn't null 127 * The following method tests are to be completed successfully before : 128 */ 129 public void _getPeer() { 130 requiredMethod("createPeer()"); 131 boolean res = false; 132 XWindowPeer get = oObj.getPeer(); 133 if (get == null) { 134 log.println("The method 'getPeer' returns NULL"); 135 } else { 136 res = true; 137 } 138 tRes.tested("getPeer()",res); 139 } 140 141 142 /** 143 * At first current model is obtained and saved to variable aModel. 144 * Then object relation 'MODEL' is gotten and test calls the method. <p> 145 * Has <b> OK </b> status if the method successfully returns 146 * and no exceptions were thrown. 147 */ 148 public void _setModel() { 149 aModel = oObj.getModel(); 150 XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL"); 151 oObj.setModel(the_model); 152 tRes.tested("setModel()",true); 153 } 154 155 /** 156 * Test calls the method, then object relation 'MODEL' is gotten and 157 * compared with object returned by the method. Then previously saved 158 * value of model (aModel) restored to (XControl) oObj<p> 159 * Has <b> OK </b> status if models set and get are equal. <p> 160 * The following method tests are to be completed successfully before : 161 * <ul> 162 * <li> <code> setModel() </code> : setting model from corresponding 163 * object relation </li> 164 * </ul> 165 */ 166 public void _getModel() { 167 requiredMethod("setModel()"); 168 XControlModel the_model = (XControlModel) tEnv.getObjRelation("MODEL"); 169 XControlModel get = oObj.getModel(); 170 boolean res = (get.equals(the_model)); 171 if (!res) { 172 log.println("getting: "+get.toString()); 173 log.println("expected: "+the_model.toString()); 174 } 175 if (aModel != null) { 176 oObj.setModel(aModel); 177 } 178 tRes.tested("getModel()",res); 179 } 180 181 /** 182 * Test calls the method. Then mode is checked using isDesignMode().<p> 183 * Has <b> OK </b> status if mode is swithed. 184 */ 185 public void _setDesignMode() { 186 desMode = oObj.isDesignMode(); 187 oObj.setDesignMode(!desMode); 188 tRes.tested("setDesignMode()",oObj.isDesignMode() == !desMode); 189 } 190 191 /** 192 * The mode is changed and result is checked.<p> 193 * Has <b> OK </b> status if the mode changed successfully. 194 */ 195 public void _isDesignMode() { 196 requiredMethod("setDesignMode()"); 197 oObj.setDesignMode(desMode); 198 tRes.tested("isDesignMode()", oObj.isDesignMode() == desMode); 199 } 200 201 /** 202 * Test calls the method.<p> 203 * Has <b> OK </b> status if the method successfully returns 204 * and no exceptions were thrown. <p> 205 */ 206 public void _isTransparent() { 207 boolean isT = oObj.isTransparent(); 208 tRes.tested("isTransparent()",true ); 209 } 210 211 /** 212 * Test calls the method.<p> 213 * Has <b> OK </b> status if the method returns not null. <p> 214 */ 215 public void _getView() { 216 XView the_view = oObj.getView(); 217 tRes.tested("getView()", the_view != null); 218 } 219 220 } 221 222 223