1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.frame; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir import com.sun.star.frame.XController; 33*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 34*cdf0e10cSrcweir import com.sun.star.frame.XModel; 35*cdf0e10cSrcweir import com.sun.star.util.XModifiable; 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XController</code> 40*cdf0e10cSrcweir * interface methods: 41*cdf0e10cSrcweir * <ul> 42*cdf0e10cSrcweir * <li><code> getFrame() </code></li> 43*cdf0e10cSrcweir * <li><code> attachFrame() </code></li> 44*cdf0e10cSrcweir * <li><code> getModel() </code></li> 45*cdf0e10cSrcweir * <li><code> attachModel() </code></li> 46*cdf0e10cSrcweir * <li><code> getViewData() </code></li> 47*cdf0e10cSrcweir * <li><code> restoreViewData() </code></li> 48*cdf0e10cSrcweir * <li><code> suspend() </code></li> 49*cdf0e10cSrcweir * </ul><p> 50*cdf0e10cSrcweir * This test needs the following object relations : 51*cdf0e10cSrcweir * <ul> 52*cdf0e10cSrcweir * <li> <code>'Frame'</code> (of type <code>XFrame</code>): 53*cdf0e10cSrcweir * any other frame, used for tests</li> 54*cdf0e10cSrcweir * <li> <code>'FirstModel'</code> (of type <code>XModel</code>): 55*cdf0e10cSrcweir * model of a controller tested</li> 56*cdf0e10cSrcweir * <li> <code>'SecondModel'</code> (of type <code>XModel</code>): 57*cdf0e10cSrcweir * other model, used for tests </li> 58*cdf0e10cSrcweir * <li> <code>'HasViewData'</code> (of type <code>Boolean</code>): 59*cdf0e10cSrcweir * (optional relation) if it exsists, so controller has no view data</li> 60*cdf0e10cSrcweir * <li> <code>'SecondController'</code> (of type <code>XController</code>): 61*cdf0e10cSrcweir * other controller, used for tests </li> 62*cdf0e10cSrcweir * </ul> <p> 63*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 64*cdf0e10cSrcweir * @see com.sun.star.frame.XController 65*cdf0e10cSrcweir */ 66*cdf0e10cSrcweir public class _XController extends MultiMethodTest { 67*cdf0e10cSrcweir public XController oObj = null; 68*cdf0e10cSrcweir public XModel firstModel = null; 69*cdf0e10cSrcweir public XModel secondModel = null; 70*cdf0e10cSrcweir public XFrame frame = null; 71*cdf0e10cSrcweir public Object ViewData = null; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir /** 74*cdf0e10cSrcweir * Test calls the method. <p> 75*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns object, that's equal to 76*cdf0e10cSrcweir * previously obtained object relation 'Frame'. 77*cdf0e10cSrcweir * The following method tests are to be completed successfully before: 78*cdf0e10cSrcweir * <ul> 79*cdf0e10cSrcweir * <li> <code> attachFrame() </code> : attachs frame obtained object 80*cdf0e10cSrcweir * relation 'Frame' </li> 81*cdf0e10cSrcweir * </ul> 82*cdf0e10cSrcweir */ 83*cdf0e10cSrcweir public void _getFrame() { 84*cdf0e10cSrcweir requiredMethod("attachFrame()"); 85*cdf0e10cSrcweir XFrame getting = oObj.getFrame(); 86*cdf0e10cSrcweir boolean eq = getting.equals(frame); 87*cdf0e10cSrcweir if ( !eq ) { 88*cdf0e10cSrcweir log.println("Getting: " + getting.toString()); 89*cdf0e10cSrcweir log.println("Expected: " + frame.toString()); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir tRes.tested("getFrame()", eq); 92*cdf0e10cSrcweir } 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir /** 95*cdf0e10cSrcweir * After obtaining a corresponding object relation test calls the method. 96*cdf0e10cSrcweir * Has <b> OK </b> status if no exceptions were thrown. <p> 97*cdf0e10cSrcweir */ 98*cdf0e10cSrcweir public void _attachFrame() { 99*cdf0e10cSrcweir frame = (XFrame) tEnv.getObjRelation("Frame"); 100*cdf0e10cSrcweir oObj.attachFrame(frame); 101*cdf0e10cSrcweir tRes.tested("attachFrame()", true); 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir /** 105*cdf0e10cSrcweir * At first object relation 'FirstModel' is gotten. Then test calls the 106*cdf0e10cSrcweir * method. <p> 107*cdf0e10cSrcweir * Has <b> OK </b> status if string repersentation of an object, returned by 108*cdf0e10cSrcweir * the method is equal to string representation of corresponding object 109*cdf0e10cSrcweir * relation. 110*cdf0e10cSrcweir */ 111*cdf0e10cSrcweir public void _getModel() { 112*cdf0e10cSrcweir firstModel = (XModel) tEnv.getObjRelation("FirstModel"); 113*cdf0e10cSrcweir XModel getting = oObj.getModel(); 114*cdf0e10cSrcweir String out1 = ""; 115*cdf0e10cSrcweir String out2 = ""; 116*cdf0e10cSrcweir if ( (firstModel == null) ) out1="none"; 117*cdf0e10cSrcweir else out1 = firstModel.toString(); 118*cdf0e10cSrcweir if ( (getting == null) ) out2="none"; else out2 = getting.toString(); 119*cdf0e10cSrcweir boolean eq = out1.equals(out2); 120*cdf0e10cSrcweir if ( !eq ) { 121*cdf0e10cSrcweir log.println("Getting: " + out2); 122*cdf0e10cSrcweir log.println("Expected: " + out1); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir tRes.tested("getModel()", eq); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir /** 128*cdf0e10cSrcweir * At first, we obtain an object relation 'SecondModel'. Then test calls 129*cdf0e10cSrcweir * the method and check result. <p> 130*cdf0e10cSrcweir * Has <b> OK </b> status if method returns true and attached model is 131*cdf0e10cSrcweir * equal to a model 'SecondModel' obtained before. 132*cdf0e10cSrcweir * <p> 133*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 134*cdf0e10cSrcweir * <ul> 135*cdf0e10cSrcweir * <li> <code> getModel() </code> : returns model (XModel) of the 136*cdf0e10cSrcweir * XController object</li> 137*cdf0e10cSrcweir * </ul> 138*cdf0e10cSrcweir */ 139*cdf0e10cSrcweir public void _attachModel() { 140*cdf0e10cSrcweir boolean result = false; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir requiredMethod("getModel()"); 143*cdf0e10cSrcweir secondModel = (XModel) tEnv.getObjRelation("SecondModel"); 144*cdf0e10cSrcweir XModel gotBefore = oObj.getModel(); 145*cdf0e10cSrcweir boolean attached = oObj.attachModel(secondModel); 146*cdf0e10cSrcweir XModel gotAfter = oObj.getModel(); 147*cdf0e10cSrcweir if ( attached ) { 148*cdf0e10cSrcweir if ( ! gotBefore.equals(gotAfter) ) { 149*cdf0e10cSrcweir if ( gotAfter.equals(secondModel) ) { 150*cdf0e10cSrcweir result = true; 151*cdf0e10cSrcweir } else { 152*cdf0e10cSrcweir log.println("Attached and gotten models are not equal"); 153*cdf0e10cSrcweir log.println("Getting: " + gotAfter.toString()); 154*cdf0e10cSrcweir log.println("Expected: " + secondModel.toString()); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir } else { 157*cdf0e10cSrcweir log.println("method did not change model"); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } else { 160*cdf0e10cSrcweir result=true; 161*cdf0e10cSrcweir log.println("attachModel() returns false"); 162*cdf0e10cSrcweir log.println("as expected, see #82938"); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir tRes.tested("attachModel()", result); 165*cdf0e10cSrcweir oObj.attachModel(firstModel); 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir /** 169*cdf0e10cSrcweir * At first gotten object relation 'HasViewData' is checked. Then if 170*cdf0e10cSrcweir * 'HasViewData' is null, test calls the method. <p> 171*cdf0e10cSrcweir * Has <b> OK </b> status if obtained object relation is not null, or if 172*cdf0e10cSrcweir * the method does not return null. 173*cdf0e10cSrcweir */ 174*cdf0e10cSrcweir public void _getViewData() { 175*cdf0e10cSrcweir if (tEnv.getObjRelation("HasViewData") != null) { 176*cdf0e10cSrcweir log.println("This Object has no View Data"); 177*cdf0e10cSrcweir tRes.tested("getViewData()", true); 178*cdf0e10cSrcweir return; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir ViewData = oObj.getViewData(); 181*cdf0e10cSrcweir tRes.tested( "getViewData()", ViewData != null ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir /** 185*cdf0e10cSrcweir * If obtained object relation 'HasViewData' is null, test calls the method. 186*cdf0e10cSrcweir * <p>Has <b> OK </b> status if obtained object relation is not null, or 187*cdf0e10cSrcweir * if no exceptions were thrown while method call.<p> 188*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 189*cdf0e10cSrcweir * <ul> 190*cdf0e10cSrcweir * <li> <code> getViewData() </code> : gets view data of an object. </li> 191*cdf0e10cSrcweir * </ul> 192*cdf0e10cSrcweir */ 193*cdf0e10cSrcweir public void _restoreViewData() { 194*cdf0e10cSrcweir requiredMethod("getViewData()"); 195*cdf0e10cSrcweir if (tEnv.getObjRelation("HasViewData") != null) { 196*cdf0e10cSrcweir log.println("This Object has no View Data"); 197*cdf0e10cSrcweir tRes.tested("restoreViewData()", true); 198*cdf0e10cSrcweir return; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir oObj.restoreViewData(ViewData); 201*cdf0e10cSrcweir tRes.tested( "restoreViewData()", true ); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir /** 205*cdf0e10cSrcweir * Has <b> OK </b> status if the method returns true.<p> 206*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 207*cdf0e10cSrcweir * <ul> 208*cdf0e10cSrcweir * <li> <code> restoreViewData() </code> : restores view status of an 209*cdf0e10cSrcweir * object </li> 210*cdf0e10cSrcweir * </ul> 211*cdf0e10cSrcweir */ 212*cdf0e10cSrcweir public void _suspend() { 213*cdf0e10cSrcweir requiredMethod("restoreViewData()"); 214*cdf0e10cSrcweir XModifiable modify = (XModifiable) tEnv.getObjRelation("Modifiable"); 215*cdf0e10cSrcweir if (modify != null) { 216*cdf0e10cSrcweir try { 217*cdf0e10cSrcweir modify.setModified(false); 218*cdf0e10cSrcweir } catch (com.sun.star.beans.PropertyVetoException pve) { 219*cdf0e10cSrcweir log.println("PropertyVetoException, couldn't change Modify flag"); 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir tRes.tested( "suspend()", oObj.suspend(true) ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir } 226*cdf0e10cSrcweir 227