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