1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
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
;
39 * Testing <code>com.sun.star.frame.XController</code>
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>
50 * This test needs the following object relations :
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>
63 * Test is <b> NOT </b> multithread compilant. <p>
64 * @see com.sun.star.frame.XController
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;
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:
79 * <li> <code> attachFrame() </code> : attachs frame obtained object
80 * relation 'Frame' </li>
83 public void _getFrame() {
84 requiredMethod("attachFrame()");
85 XFrame getting
= oObj
.getFrame();
86 boolean eq
= getting
.equals(frame
);
88 log
.println("Getting: " + getting
.toString());
89 log
.println("Expected: " + frame
.toString());
91 tRes
.tested("getFrame()", eq
);
95 * After obtaining a corresponding object relation test calls the method.
96 * Has <b> OK </b> status if no exceptions were thrown. <p>
98 public void _attachFrame() {
99 frame
= (XFrame
) tEnv
.getObjRelation("Frame");
100 oObj
.attachFrame(frame
);
101 tRes
.tested("attachFrame()", true);
105 * At first object relation 'FirstModel' is gotten. Then test calls the
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
111 public void _getModel() {
112 firstModel
= (XModel
) tEnv
.getObjRelation("FirstModel");
113 XModel getting
= oObj
.getModel();
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
);
121 log
.println("Getting: " + out2
);
122 log
.println("Expected: " + out1
);
124 tRes
.tested("getModel()", eq
);
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.
133 * The following method tests are to be completed successfully before :
135 * <li> <code> getModel() </code> : returns model (XModel) of the
136 * XController object</li>
139 public void _attachModel() {
140 boolean result
= false;
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();
148 if ( ! gotBefore
.equals(gotAfter
) ) {
149 if ( gotAfter
.equals(secondModel
) ) {
152 log
.println("Attached and gotten models are not equal");
153 log
.println("Getting: " + gotAfter
.toString());
154 log
.println("Expected: " + secondModel
.toString());
157 log
.println("method did not change model");
161 log
.println("attachModel() returns false");
162 log
.println("as expected, see #82938");
164 tRes
.tested("attachModel()", result
);
165 oObj
.attachModel(firstModel
);
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.
174 public void _getViewData() {
175 if (tEnv
.getObjRelation("HasViewData") != null) {
176 log
.println("This Object has no View Data");
177 tRes
.tested("getViewData()", true);
180 ViewData
= oObj
.getViewData();
181 tRes
.tested( "getViewData()", ViewData
!= null );
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 :
190 * <li> <code> getViewData() </code> : gets view data of an object. </li>
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);
200 oObj
.restoreViewData(ViewData
);
201 tRes
.tested( "restoreViewData()", true );
205 * Has <b> OK </b> status if the method returns true.<p>
206 * The following method tests are to be completed successfully before :
208 * <li> <code> restoreViewData() </code> : restores view status of an
212 public void _suspend() {
213 requiredMethod("restoreViewData()");
214 XModifiable modify
= (XModifiable
) tEnv
.getObjRelation("Modifiable");
215 if (modify
!= null) {
217 modify
.setModified(false);
218 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
219 log
.println("PropertyVetoException, couldn't change Modify flag");
222 tRes
.tested( "suspend()", oObj
.suspend(true) );