1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package ifc.frame;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
26cdf0e10cSrcweir import com.sun.star.frame.XController;
27cdf0e10cSrcweir import com.sun.star.frame.XModel;
28cdf0e10cSrcweir import com.sun.star.view.XSelectionSupplier;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import lib.MultiMethodTest;
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /**
34cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XModel</code>
35cdf0e10cSrcweir * interface methods:
36cdf0e10cSrcweir * <ul>
37cdf0e10cSrcweir *  <li><code> attachResource() </code></li>
38cdf0e10cSrcweir *  <li><code> connectController() </code></li>
39cdf0e10cSrcweir *  <li><code> disconnectController() </code></li>
40cdf0e10cSrcweir *  <li><code> getArgs() </code></li>
41cdf0e10cSrcweir *  <li><code> getCurrentController() </code></li>
42cdf0e10cSrcweir *  <li><code> getCurrentSelection() </code></li>
43cdf0e10cSrcweir *  <li><code> getURL() </code></li>
44cdf0e10cSrcweir *  <li><code> hasControllersLocked() </code></li>
45cdf0e10cSrcweir *  <li><code> lockControllers() </code></li>
46cdf0e10cSrcweir *  <li><code> setCurrentController() </code></li>
47cdf0e10cSrcweir *  <li><code> unlockControllers() </code></li>
48cdf0e10cSrcweir * </ul><p>
49cdf0e10cSrcweir * This test needs the following object relations :
50cdf0e10cSrcweir * <ul>
51cdf0e10cSrcweir *  <li> <code>'CONT2'</code> (of type <code>XController</code>):
52cdf0e10cSrcweir *  a controller used as an argument for several test methods </li>
53cdf0e10cSrcweir *  <li> <code>'TOSELECT'</code> (of type <code>Object</code>):
54cdf0e10cSrcweir *   something, we want to select from document </li>
55cdf0e10cSrcweir *  <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>):
56cdf0e10cSrcweir *   supplier, we use to select something in a document </li>
57cdf0e10cSrcweir * </ul> <p>
58cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
59cdf0e10cSrcweir * @see com.sun.star.frame.XModel
60cdf0e10cSrcweir */
61cdf0e10cSrcweir public class _XModel extends MultiMethodTest {
62cdf0e10cSrcweir     public XModel oObj = null;
63cdf0e10cSrcweir     boolean result = true;
64cdf0e10cSrcweir 
65cdf0e10cSrcweir     /**
66cdf0e10cSrcweir     * Test calls the method. <p>
67cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns true.
68cdf0e10cSrcweir     */
_attachResource()69cdf0e10cSrcweir     public void _attachResource() {
70cdf0e10cSrcweir         log.println("opening DataSourceBrowser");
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         PropertyValue[] noArgs = new PropertyValue[0];
73cdf0e10cSrcweir         result = oObj.attachResource(".component:DB/DataSourceBrowser", noArgs);
74cdf0e10cSrcweir         tRes.tested("attachResource()", result);
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     /**
78cdf0e10cSrcweir     * After obtaining object relation 'CONT2' and storing old controller,
79cdf0e10cSrcweir     * test calls the method, then result is checked.<p>
80cdf0e10cSrcweir     * Has <b> OK </b> status if controller, gotten after method call is not
81cdf0e10cSrcweir     * equal to a previous controller.
82cdf0e10cSrcweir     */
_connectController()83cdf0e10cSrcweir     public void _connectController() {
84cdf0e10cSrcweir         XController cont2 = (XController) tEnv.getObjRelation("CONT2");
85cdf0e10cSrcweir         XController old = oObj.getCurrentController();
86cdf0e10cSrcweir         result = false;
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         if (cont2 == null) {
89cdf0e10cSrcweir             log.println("No controller no show");
90cdf0e10cSrcweir         } else {
91cdf0e10cSrcweir             oObj.connectController(cont2);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir             String oldFrame = old.getFrame().getName();
94cdf0e10cSrcweir             String newFrame = cont2.getFrame().getName();
95cdf0e10cSrcweir             result = (!oldFrame.equals(newFrame));
96cdf0e10cSrcweir         }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         tRes.tested("connectController()", result);
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     /**
102cdf0e10cSrcweir     * After obtaining object relation 'CONT2', test calls the method,
103cdf0e10cSrcweir     * then result is checked.<p>
104cdf0e10cSrcweir     * Has <b> OK </b> status if controller, gotten after method call is not
105cdf0e10cSrcweir     * equal to a controller we use as an argument to method.
106cdf0e10cSrcweir     */
_disconnectController()107cdf0e10cSrcweir     public void _disconnectController() {
108cdf0e10cSrcweir         XController cont2 = (XController) tEnv.getObjRelation("CONT2");
109cdf0e10cSrcweir         result = false;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir         if (cont2 == null) {
112cdf0e10cSrcweir             log.println("No controller no show");
113cdf0e10cSrcweir         } else {
114cdf0e10cSrcweir             oObj.disconnectController(cont2);
115cdf0e10cSrcweir             result = (oObj.getCurrentController() != cont2);
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         tRes.tested("disconnectController()", result);
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     /**
122cdf0e10cSrcweir     * Test calls the method. <p>
123cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
124cdf0e10cSrcweir     */
_getArgs()125cdf0e10cSrcweir     public void _getArgs() {
126cdf0e10cSrcweir         tRes.tested("getArgs()", oObj.getArgs() != null);
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir     /**
130cdf0e10cSrcweir     * Test calls the method. <p>
131cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
132cdf0e10cSrcweir     */
_getCurrentController()133cdf0e10cSrcweir     public void _getCurrentController() {
134cdf0e10cSrcweir         XController ctrl = oObj.getCurrentController();
135cdf0e10cSrcweir         tRes.tested("getCurrentController()", ctrl != null);
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     /**
139cdf0e10cSrcweir     * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares
140cdf0e10cSrcweir     * selection and calls the method. <p>
141cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
142cdf0e10cSrcweir     */
_getCurrentSelection()143cdf0e10cSrcweir     public void _getCurrentSelection() {
144cdf0e10cSrcweir         XSelectionSupplier selsupp = (XSelectionSupplier) tEnv.getObjRelation(
145cdf0e10cSrcweir                                              "SELSUPP");
146cdf0e10cSrcweir         Object toSelect = tEnv.getObjRelation("TOSELECT");
147cdf0e10cSrcweir         result = false;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         if (selsupp == null) {
150cdf0e10cSrcweir             log.println("No Selection Supplier no show");
151cdf0e10cSrcweir         } else {
152cdf0e10cSrcweir             try {
153cdf0e10cSrcweir                 selsupp.select(toSelect);
154cdf0e10cSrcweir             } catch (com.sun.star.lang.IllegalArgumentException e) {
155*bb6af6bcSPedro Giffuni                 log.println("Exception occurred while select:");
156cdf0e10cSrcweir                 e.printStackTrace(log);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir                 return;
159cdf0e10cSrcweir             }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir             Object sel = oObj.getCurrentSelection();
162cdf0e10cSrcweir             result = (sel != null);
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         tRes.tested("getCurrentSelection()", result);
166cdf0e10cSrcweir     }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     /**
169cdf0e10cSrcweir     * Test calls the method. <p>
170cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null.
171cdf0e10cSrcweir     */
_getURL()172cdf0e10cSrcweir     public void _getURL() {
173cdf0e10cSrcweir         String url = oObj.getURL();
174cdf0e10cSrcweir         log.println("The url: " + url);
175cdf0e10cSrcweir         tRes.tested("getURL()", url != null);
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     /**
179cdf0e10cSrcweir     * if controller is not locked, test calls the method. <p>
180cdf0e10cSrcweir     * Has <b> OK </b> status if the method returns true. <p>
181cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
182cdf0e10cSrcweir     * <ul>
183cdf0e10cSrcweir     *  <li> <code> lockControllers() </code> : locks controllers </li>
184cdf0e10cSrcweir     * </ul>
185cdf0e10cSrcweir     */
_hasControllersLocked()186cdf0e10cSrcweir     public void _hasControllersLocked() {
187cdf0e10cSrcweir         requiredMethod("lockControllers()");
188cdf0e10cSrcweir         tRes.tested("hasControllersLocked()", oObj.hasControllersLocked());
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     /**
192cdf0e10cSrcweir     * Test calls the method, then result is checked.<p>
193cdf0e10cSrcweir     * Has <b> OK </b> status if method locks controllers.
194cdf0e10cSrcweir     */
_lockControllers()195cdf0e10cSrcweir     public void _lockControllers() {
196cdf0e10cSrcweir         oObj.lockControllers();
197cdf0e10cSrcweir         result = oObj.hasControllersLocked();
198cdf0e10cSrcweir         tRes.tested("lockControllers()", result);
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     /**
202cdf0e10cSrcweir     * After obtaining object relation 'CONT2' and storing old controller,
203cdf0e10cSrcweir     * controller cont2 is connected, then this controller is
204cdf0e10cSrcweir     * setting as current.
205cdf0e10cSrcweir     * Sets the old controller as current.
206cdf0e10cSrcweir     * <p>Has <b> OK </b> status if set and gotten controllers are not equal.
207cdf0e10cSrcweir     */
_setCurrentController()208cdf0e10cSrcweir     public void _setCurrentController() {
209cdf0e10cSrcweir         XController cont2 = (XController) tEnv.getObjRelation("CONT2");
210cdf0e10cSrcweir         XController old = oObj.getCurrentController();
211cdf0e10cSrcweir         result = false;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         if (cont2 == null) {
214cdf0e10cSrcweir             log.println("No controller no show");
215cdf0e10cSrcweir         } else {
216cdf0e10cSrcweir             oObj.connectController(cont2);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir             try {
219cdf0e10cSrcweir                 oObj.setCurrentController(cont2);
220cdf0e10cSrcweir             } catch (com.sun.star.container.NoSuchElementException e) {
221cdf0e10cSrcweir                 log.print("Cannot set current controller:");
222cdf0e10cSrcweir                 e.printStackTrace(log);
223cdf0e10cSrcweir             }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir             result = (oObj.getCurrentController() != old);
226cdf0e10cSrcweir 
227cdf0e10cSrcweir             try {
228cdf0e10cSrcweir                 oObj.setCurrentController(old);
229cdf0e10cSrcweir             } catch (com.sun.star.container.NoSuchElementException e) {
230cdf0e10cSrcweir                 log.print("Cannot set current controller:");
231cdf0e10cSrcweir                 e.printStackTrace(log);
232cdf0e10cSrcweir             }
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         tRes.tested("setCurrentController()", result);
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     /**
239cdf0e10cSrcweir     * Test calls the method. <p>
240cdf0e10cSrcweir     * Has <b> OK </b> status if method unlocks controllers.
241cdf0e10cSrcweir     * <p>
242cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
243cdf0e10cSrcweir     * <ul>
244cdf0e10cSrcweir     *  <li> <code> hasControllersLocked() </code> : checks if controllers are
245cdf0e10cSrcweir     * locked </li>
246cdf0e10cSrcweir     * </ul>
247cdf0e10cSrcweir     */
_unlockControllers()248cdf0e10cSrcweir     public void _unlockControllers() {
249cdf0e10cSrcweir         requiredMethod("hasControllersLocked()");
250cdf0e10cSrcweir         oObj.unlockControllers();
251cdf0e10cSrcweir         result = !oObj.hasControllersLocked();
252cdf0e10cSrcweir         tRes.tested("unlockControllers()", result);
253cdf0e10cSrcweir     }
254cdf0e10cSrcweir }
255