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