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 package ifc.frame; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.frame.XController; 31 import com.sun.star.frame.XModel; 32 import com.sun.star.view.XSelectionSupplier; 33 34 import lib.MultiMethodTest; 35 36 37 /** 38 * Testing <code>com.sun.star.frame.XModel</code> 39 * interface methods: 40 * <ul> 41 * <li><code> attachResource() </code></li> 42 * <li><code> connectController() </code></li> 43 * <li><code> disconnectController() </code></li> 44 * <li><code> getArgs() </code></li> 45 * <li><code> getCurrentController() </code></li> 46 * <li><code> getCurrentSelection() </code></li> 47 * <li><code> getURL() </code></li> 48 * <li><code> hasControllersLocked() </code></li> 49 * <li><code> lockControllers() </code></li> 50 * <li><code> setCurrentController() </code></li> 51 * <li><code> unlockControllers() </code></li> 52 * </ul><p> 53 * This test needs the following object relations : 54 * <ul> 55 * <li> <code>'CONT2'</code> (of type <code>XController</code>): 56 * a controller used as an argument for several test methods </li> 57 * <li> <code>'TOSELECT'</code> (of type <code>Object</code>): 58 * something, we want to select from document </li> 59 * <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>): 60 * supplier, we use to select something in a document </li> 61 * </ul> <p> 62 * Test is <b> NOT </b> multithread compilant. <p> 63 * @see com.sun.star.frame.XModel 64 */ 65 public class _XModel extends MultiMethodTest { 66 public XModel oObj = null; 67 boolean result = true; 68 69 /** 70 * Test calls the method. <p> 71 * Has <b> OK </b> status if the method returns true. 72 */ 73 public void _attachResource() { 74 log.println("opening DataSourceBrowser"); 75 76 PropertyValue[] noArgs = new PropertyValue[0]; 77 result = oObj.attachResource(".component:DB/DataSourceBrowser", noArgs); 78 tRes.tested("attachResource()", result); 79 } 80 81 /** 82 * After obtaining object relation 'CONT2' and storing old controller, 83 * test calls the method, then result is checked.<p> 84 * Has <b> OK </b> status if controller, gotten after method call is not 85 * equal to a previous controller. 86 */ 87 public void _connectController() { 88 XController cont2 = (XController) tEnv.getObjRelation("CONT2"); 89 XController old = oObj.getCurrentController(); 90 result = false; 91 92 if (cont2 == null) { 93 log.println("No controller no show"); 94 } else { 95 oObj.connectController(cont2); 96 97 String oldFrame = old.getFrame().getName(); 98 String newFrame = cont2.getFrame().getName(); 99 result = (!oldFrame.equals(newFrame)); 100 } 101 102 tRes.tested("connectController()", result); 103 } 104 105 /** 106 * After obtaining object relation 'CONT2', test calls the method, 107 * then result is checked.<p> 108 * Has <b> OK </b> status if controller, gotten after method call is not 109 * equal to a controller we use as an argument to method. 110 */ 111 public void _disconnectController() { 112 XController cont2 = (XController) tEnv.getObjRelation("CONT2"); 113 result = false; 114 115 if (cont2 == null) { 116 log.println("No controller no show"); 117 } else { 118 oObj.disconnectController(cont2); 119 result = (oObj.getCurrentController() != cont2); 120 } 121 122 tRes.tested("disconnectController()", result); 123 } 124 125 /** 126 * Test calls the method. <p> 127 * Has <b> OK </b> status if the method does not return null. 128 */ 129 public void _getArgs() { 130 tRes.tested("getArgs()", oObj.getArgs() != null); 131 } 132 133 /** 134 * Test calls the method. <p> 135 * Has <b> OK </b> status if the method does not return null. 136 */ 137 public void _getCurrentController() { 138 XController ctrl = oObj.getCurrentController(); 139 tRes.tested("getCurrentController()", ctrl != null); 140 } 141 142 /** 143 * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares 144 * selection and calls the method. <p> 145 * Has <b> OK </b> status if the method does not return null. 146 */ 147 public void _getCurrentSelection() { 148 XSelectionSupplier selsupp = (XSelectionSupplier) tEnv.getObjRelation( 149 "SELSUPP"); 150 Object toSelect = tEnv.getObjRelation("TOSELECT"); 151 result = false; 152 153 if (selsupp == null) { 154 log.println("No Selection Supplier no show"); 155 } else { 156 try { 157 selsupp.select(toSelect); 158 } catch (com.sun.star.lang.IllegalArgumentException e) { 159 log.println("Exception occured while select:"); 160 e.printStackTrace(log); 161 162 return; 163 } 164 165 Object sel = oObj.getCurrentSelection(); 166 result = (sel != null); 167 } 168 169 tRes.tested("getCurrentSelection()", result); 170 } 171 172 /** 173 * Test calls the method. <p> 174 * Has <b> OK </b> status if the method does not return null. 175 */ 176 public void _getURL() { 177 String url = oObj.getURL(); 178 log.println("The url: " + url); 179 tRes.tested("getURL()", url != null); 180 } 181 182 /** 183 * if controller is not locked, test calls the method. <p> 184 * Has <b> OK </b> status if the method returns true. <p> 185 * The following method tests are to be completed successfully before : 186 * <ul> 187 * <li> <code> lockControllers() </code> : locks controllers </li> 188 * </ul> 189 */ 190 public void _hasControllersLocked() { 191 requiredMethod("lockControllers()"); 192 tRes.tested("hasControllersLocked()", oObj.hasControllersLocked()); 193 } 194 195 /** 196 * Test calls the method, then result is checked.<p> 197 * Has <b> OK </b> status if method locks controllers. 198 */ 199 public void _lockControllers() { 200 oObj.lockControllers(); 201 result = oObj.hasControllersLocked(); 202 tRes.tested("lockControllers()", result); 203 } 204 205 /** 206 * After obtaining object relation 'CONT2' and storing old controller, 207 * controller cont2 is connected, then this controller is 208 * setting as current. 209 * Sets the old controller as current. 210 * <p>Has <b> OK </b> status if set and gotten controllers are not equal. 211 */ 212 public void _setCurrentController() { 213 XController cont2 = (XController) tEnv.getObjRelation("CONT2"); 214 XController old = oObj.getCurrentController(); 215 result = false; 216 217 if (cont2 == null) { 218 log.println("No controller no show"); 219 } else { 220 oObj.connectController(cont2); 221 222 try { 223 oObj.setCurrentController(cont2); 224 } catch (com.sun.star.container.NoSuchElementException e) { 225 log.print("Cannot set current controller:"); 226 e.printStackTrace(log); 227 } 228 229 result = (oObj.getCurrentController() != old); 230 231 try { 232 oObj.setCurrentController(old); 233 } catch (com.sun.star.container.NoSuchElementException e) { 234 log.print("Cannot set current controller:"); 235 e.printStackTrace(log); 236 } 237 } 238 239 tRes.tested("setCurrentController()", result); 240 } 241 242 /** 243 * Test calls the method. <p> 244 * Has <b> OK </b> status if method unlocks controllers. 245 * <p> 246 * The following method tests are to be completed successfully before : 247 * <ul> 248 * <li> <code> hasControllersLocked() </code> : checks if controllers are 249 * locked </li> 250 * </ul> 251 */ 252 public void _unlockControllers() { 253 requiredMethod("hasControllersLocked()"); 254 oObj.unlockControllers(); 255 result = !oObj.hasControllersLocked(); 256 tRes.tested("unlockControllers()", result); 257 } 258 } 259