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