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.frame; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.frame.XController; 33 import com.sun.star.frame.XFrame; 34 import com.sun.star.frame.XModel; 35 import com.sun.star.util.XModifiable; 36 37 38 /** 39 * Testing <code>com.sun.star.frame.XController</code> 40 * interface methods: 41 * <ul> 42 * <li><code> getFrame() </code></li> 43 * <li><code> attachFrame() </code></li> 44 * <li><code> getModel() </code></li> 45 * <li><code> attachModel() </code></li> 46 * <li><code> getViewData() </code></li> 47 * <li><code> restoreViewData() </code></li> 48 * <li><code> suspend() </code></li> 49 * </ul><p> 50 * This test needs the following object relations : 51 * <ul> 52 * <li> <code>'Frame'</code> (of type <code>XFrame</code>): 53 * any other frame, used for tests</li> 54 * <li> <code>'FirstModel'</code> (of type <code>XModel</code>): 55 * model of a controller tested</li> 56 * <li> <code>'SecondModel'</code> (of type <code>XModel</code>): 57 * other model, used for tests </li> 58 * <li> <code>'HasViewData'</code> (of type <code>Boolean</code>): 59 * (optional relation) if it exsists, so controller has no view data</li> 60 * <li> <code>'SecondController'</code> (of type <code>XController</code>): 61 * other controller, used for tests </li> 62 * </ul> <p> 63 * Test is <b> NOT </b> multithread compilant. <p> 64 * @see com.sun.star.frame.XController 65 */ 66 public class _XController extends MultiMethodTest { 67 public XController oObj = null; 68 public XModel firstModel = null; 69 public XModel secondModel = null; 70 public XFrame frame = null; 71 public Object ViewData = null; 72 73 /** 74 * Test calls the method. <p> 75 * Has <b> OK </b> status if the method returns object, that's equal to 76 * previously obtained object relation 'Frame'. 77 * The following method tests are to be completed successfully before: 78 * <ul> 79 * <li> <code> attachFrame() </code> : attachs frame obtained object 80 * relation 'Frame' </li> 81 * </ul> 82 */ 83 public void _getFrame() { 84 requiredMethod("attachFrame()"); 85 XFrame getting = oObj.getFrame(); 86 boolean eq = getting.equals(frame); 87 if ( !eq ) { 88 log.println("Getting: " + getting.toString()); 89 log.println("Expected: " + frame.toString()); 90 } 91 tRes.tested("getFrame()", eq); 92 } 93 94 /** 95 * After obtaining a corresponding object relation test calls the method. 96 * Has <b> OK </b> status if no exceptions were thrown. <p> 97 */ 98 public void _attachFrame() { 99 frame = (XFrame) tEnv.getObjRelation("Frame"); 100 oObj.attachFrame(frame); 101 tRes.tested("attachFrame()", true); 102 } 103 104 /** 105 * At first object relation 'FirstModel' is gotten. Then test calls the 106 * method. <p> 107 * Has <b> OK </b> status if string repersentation of an object, returned by 108 * the method is equal to string representation of corresponding object 109 * relation. 110 */ 111 public void _getModel() { 112 firstModel = (XModel) tEnv.getObjRelation("FirstModel"); 113 XModel getting = oObj.getModel(); 114 String out1 = ""; 115 String out2 = ""; 116 if ( (firstModel == null) ) out1="none"; 117 else out1 = firstModel.toString(); 118 if ( (getting == null) ) out2="none"; else out2 = getting.toString(); 119 boolean eq = out1.equals(out2); 120 if ( !eq ) { 121 log.println("Getting: " + out2); 122 log.println("Expected: " + out1); 123 } 124 tRes.tested("getModel()", eq); 125 } 126 127 /** 128 * At first, we obtain an object relation 'SecondModel'. Then test calls 129 * the method and check result. <p> 130 * Has <b> OK </b> status if method returns true and attached model is 131 * equal to a model 'SecondModel' obtained before. 132 * <p> 133 * The following method tests are to be completed successfully before : 134 * <ul> 135 * <li> <code> getModel() </code> : returns model (XModel) of the 136 * XController object</li> 137 * </ul> 138 */ 139 public void _attachModel() { 140 boolean result = false; 141 142 requiredMethod("getModel()"); 143 secondModel = (XModel) tEnv.getObjRelation("SecondModel"); 144 XModel gotBefore = oObj.getModel(); 145 boolean attached = oObj.attachModel(secondModel); 146 XModel gotAfter = oObj.getModel(); 147 if ( attached ) { 148 if ( ! gotBefore.equals(gotAfter) ) { 149 if ( gotAfter.equals(secondModel) ) { 150 result = true; 151 } else { 152 log.println("Attached and gotten models are not equal"); 153 log.println("Getting: " + gotAfter.toString()); 154 log.println("Expected: " + secondModel.toString()); 155 } 156 } else { 157 log.println("method did not change model"); 158 } 159 } else { 160 result=true; 161 log.println("attachModel() returns false"); 162 log.println("as expected, see #82938"); 163 } 164 tRes.tested("attachModel()", result); 165 oObj.attachModel(firstModel); 166 } 167 168 /** 169 * At first gotten object relation 'HasViewData' is checked. Then if 170 * 'HasViewData' is null, test calls the method. <p> 171 * Has <b> OK </b> status if obtained object relation is not null, or if 172 * the method does not return null. 173 */ 174 public void _getViewData() { 175 if (tEnv.getObjRelation("HasViewData") != null) { 176 log.println("This Object has no View Data"); 177 tRes.tested("getViewData()", true); 178 return; 179 } 180 ViewData = oObj.getViewData(); 181 tRes.tested( "getViewData()", ViewData != null ); 182 } 183 184 /** 185 * If obtained object relation 'HasViewData' is null, test calls the method. 186 * <p>Has <b> OK </b> status if obtained object relation is not null, or 187 * if no exceptions were thrown while method call.<p> 188 * The following method tests are to be completed successfully before : 189 * <ul> 190 * <li> <code> getViewData() </code> : gets view data of an object. </li> 191 * </ul> 192 */ 193 public void _restoreViewData() { 194 requiredMethod("getViewData()"); 195 if (tEnv.getObjRelation("HasViewData") != null) { 196 log.println("This Object has no View Data"); 197 tRes.tested("restoreViewData()", true); 198 return; 199 } 200 oObj.restoreViewData(ViewData); 201 tRes.tested( "restoreViewData()", true ); 202 } 203 204 /** 205 * Has <b> OK </b> status if the method returns true.<p> 206 * The following method tests are to be completed successfully before : 207 * <ul> 208 * <li> <code> restoreViewData() </code> : restores view status of an 209 * object </li> 210 * </ul> 211 */ 212 public void _suspend() { 213 requiredMethod("restoreViewData()"); 214 XModifiable modify = (XModifiable) tEnv.getObjRelation("Modifiable"); 215 if (modify != null) { 216 try { 217 modify.setModified(false); 218 } catch (com.sun.star.beans.PropertyVetoException pve) { 219 log.println("PropertyVetoException, couldn't change Modify flag"); 220 } 221 } 222 tRes.tested( "suspend()", oObj.suspend(true) ); 223 } 224 225 } 226 227