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