2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.frame
.XController
;
24 import com
.sun
.star
.frame
.XFrame
;
25 import com
.sun
.star
.frame
.XModel
;
26 import com
.sun
.star
.util
.XModifiable
;
30 * Testing <code>com.sun.star.frame.XController</code>
33 * <li><code> getFrame() </code></li>
34 * <li><code> attachFrame() </code></li>
35 * <li><code> getModel() </code></li>
36 * <li><code> attachModel() </code></li>
37 * <li><code> getViewData() </code></li>
38 * <li><code> restoreViewData() </code></li>
39 * <li><code> suspend() </code></li>
41 * This test needs the following object relations :
43 * <li> <code>'Frame'</code> (of type <code>XFrame</code>):
44 * any other frame, used for tests</li>
45 * <li> <code>'FirstModel'</code> (of type <code>XModel</code>):
46 * model of a controller tested</li>
47 * <li> <code>'SecondModel'</code> (of type <code>XModel</code>):
48 * other model, used for tests </li>
49 * <li> <code>'HasViewData'</code> (of type <code>Boolean</code>):
50 * (optional relation) if it exsists, so controller has no view data</li>
51 * <li> <code>'SecondController'</code> (of type <code>XController</code>):
52 * other controller, used for tests </li>
54 * Test is <b> NOT </b> multithread compliant. <p>
55 * @see com.sun.star.frame.XController
57 public class _XController
extends MultiMethodTest
{
58 public XController oObj
= null;
59 public XModel firstModel
= null;
60 public XModel secondModel
= null;
61 public XFrame frame
= null;
62 public Object ViewData
= null;
65 * Test calls the method. <p>
66 * Has <b> OK </b> status if the method returns object, that's equal to
67 * previously obtained object relation 'Frame'.
68 * The following method tests are to be completed successfully before:
70 * <li> <code> attachFrame() </code> : attachs frame obtained object
71 * relation 'Frame' </li>
74 public void _getFrame() {
75 requiredMethod("attachFrame()");
76 XFrame getting
= oObj
.getFrame();
77 boolean eq
= getting
.equals(frame
);
79 log
.println("Getting: " + getting
.toString());
80 log
.println("Expected: " + frame
.toString());
82 tRes
.tested("getFrame()", eq
);
86 * After obtaining a corresponding object relation test calls the method.
87 * Has <b> OK </b> status if no exceptions were thrown. <p>
89 public void _attachFrame() {
90 frame
= (XFrame
) tEnv
.getObjRelation("Frame");
91 oObj
.attachFrame(frame
);
92 tRes
.tested("attachFrame()", true);
96 * At first object relation 'FirstModel' is gotten. Then test calls the
98 * Has <b> OK </b> status if string repersentation of an object, returned by
99 * the method is equal to string representation of corresponding object
102 public void _getModel() {
103 firstModel
= (XModel
) tEnv
.getObjRelation("FirstModel");
104 XModel getting
= oObj
.getModel();
107 if ( (firstModel
== null) ) out1
="none";
108 else out1
= firstModel
.toString();
109 if ( (getting
== null) ) out2
="none"; else out2
= getting
.toString();
110 boolean eq
= out1
.equals(out2
);
112 log
.println("Getting: " + out2
);
113 log
.println("Expected: " + out1
);
115 tRes
.tested("getModel()", eq
);
119 * At first, we obtain an object relation 'SecondModel'. Then test calls
120 * the method and check result. <p>
121 * Has <b> OK </b> status if method returns true and attached model is
122 * equal to a model 'SecondModel' obtained before.
124 * The following method tests are to be completed successfully before :
126 * <li> <code> getModel() </code> : returns model (XModel) of the
127 * XController object</li>
130 public void _attachModel() {
131 boolean result
= false;
133 requiredMethod("getModel()");
134 secondModel
= (XModel
) tEnv
.getObjRelation("SecondModel");
135 XModel gotBefore
= oObj
.getModel();
136 boolean attached
= oObj
.attachModel(secondModel
);
137 XModel gotAfter
= oObj
.getModel();
139 if ( ! gotBefore
.equals(gotAfter
) ) {
140 if ( gotAfter
.equals(secondModel
) ) {
143 log
.println("Attached and gotten models are not equal");
144 log
.println("Getting: " + gotAfter
.toString());
145 log
.println("Expected: " + secondModel
.toString());
148 log
.println("method did not change model");
152 log
.println("attachModel() returns false");
153 log
.println("as expected, see #82938");
155 tRes
.tested("attachModel()", result
);
156 oObj
.attachModel(firstModel
);
160 * At first gotten object relation 'HasViewData' is checked. Then if
161 * 'HasViewData' is null, test calls the method. <p>
162 * Has <b> OK </b> status if obtained object relation is not null, or if
163 * the method does not return null.
165 public void _getViewData() {
166 if (tEnv
.getObjRelation("HasViewData") != null) {
167 log
.println("This Object has no View Data");
168 tRes
.tested("getViewData()", true);
171 ViewData
= oObj
.getViewData();
172 tRes
.tested( "getViewData()", ViewData
!= null );
176 * If obtained object relation 'HasViewData' is null, test calls the method.
177 * <p>Has <b> OK </b> status if obtained object relation is not null, or
178 * if no exceptions were thrown while method call.<p>
179 * The following method tests are to be completed successfully before :
181 * <li> <code> getViewData() </code> : gets view data of an object. </li>
184 public void _restoreViewData() {
185 requiredMethod("getViewData()");
186 if (tEnv
.getObjRelation("HasViewData") != null) {
187 log
.println("This Object has no View Data");
188 tRes
.tested("restoreViewData()", true);
191 oObj
.restoreViewData(ViewData
);
192 tRes
.tested( "restoreViewData()", true );
196 * Has <b> OK </b> status if the method returns true.<p>
197 * The following method tests are to be completed successfully before :
199 * <li> <code> restoreViewData() </code> : restores view status of an
203 public void _suspend() {
204 requiredMethod("restoreViewData()");
205 XModifiable modify
= (XModifiable
) tEnv
.getObjRelation("Modifiable");
206 if (modify
!= null) {
208 modify
.setModified(false);
209 } catch (com
.sun
.star
.beans
.PropertyVetoException pve
) {
210 log
.println("PropertyVetoException, couldn't change Modify flag");
213 tRes
.tested( "suspend()", oObj
.suspend(true) );