1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XModel.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.PropertyValue
;
33 import com
.sun
.star
.frame
.XController
;
34 import com
.sun
.star
.frame
.XModel
;
35 import com
.sun
.star
.view
.XSelectionSupplier
;
37 import lib
.MultiMethodTest
;
41 * Testing <code>com.sun.star.frame.XModel</code>
44 * <li><code> attachResource() </code></li>
45 * <li><code> connectController() </code></li>
46 * <li><code> disconnectController() </code></li>
47 * <li><code> getArgs() </code></li>
48 * <li><code> getCurrentController() </code></li>
49 * <li><code> getCurrentSelection() </code></li>
50 * <li><code> getURL() </code></li>
51 * <li><code> hasControllersLocked() </code></li>
52 * <li><code> lockControllers() </code></li>
53 * <li><code> setCurrentController() </code></li>
54 * <li><code> unlockControllers() </code></li>
56 * This test needs the following object relations :
58 * <li> <code>'CONT2'</code> (of type <code>XController</code>):
59 * a controller used as an argument for several test methods </li>
60 * <li> <code>'TOSELECT'</code> (of type <code>Object</code>):
61 * something, we want to select from document </li>
62 * <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>):
63 * supplier, we use to select something in a document </li>
65 * Test is <b> NOT </b> multithread compilant. <p>
66 * @see com.sun.star.frame.XModel
68 public class _XModel
extends MultiMethodTest
{
69 public XModel oObj
= null;
70 boolean result
= true;
73 * Test calls the method. <p>
74 * Has <b> OK </b> status if the method returns true.
76 public void _attachResource() {
77 log
.println("opening DataSourceBrowser");
79 PropertyValue
[] noArgs
= new PropertyValue
[0];
80 result
= oObj
.attachResource(".component:DB/DataSourceBrowser", noArgs
);
81 tRes
.tested("attachResource()", result
);
85 * After obtaining object relation 'CONT2' and storing old controller,
86 * test calls the method, then result is checked.<p>
87 * Has <b> OK </b> status if controller, gotten after method call is not
88 * equal to a previous controller.
90 public void _connectController() {
91 XController cont2
= (XController
) tEnv
.getObjRelation("CONT2");
92 XController old
= oObj
.getCurrentController();
96 log
.println("No controller no show");
98 oObj
.connectController(cont2
);
100 String oldFrame
= old
.getFrame().getName();
101 String newFrame
= cont2
.getFrame().getName();
102 result
= (!oldFrame
.equals(newFrame
));
105 tRes
.tested("connectController()", result
);
109 * After obtaining object relation 'CONT2', test calls the method,
110 * then result is checked.<p>
111 * Has <b> OK </b> status if controller, gotten after method call is not
112 * equal to a controller we use as an argument to method.
114 public void _disconnectController() {
115 XController cont2
= (XController
) tEnv
.getObjRelation("CONT2");
119 log
.println("No controller no show");
121 oObj
.disconnectController(cont2
);
122 result
= (oObj
.getCurrentController() != cont2
);
125 tRes
.tested("disconnectController()", result
);
129 * Test calls the method. <p>
130 * Has <b> OK </b> status if the method does not return null.
132 public void _getArgs() {
133 tRes
.tested("getArgs()", oObj
.getArgs() != null);
137 * Test calls the method. <p>
138 * Has <b> OK </b> status if the method does not return null.
140 public void _getCurrentController() {
141 XController ctrl
= oObj
.getCurrentController();
142 tRes
.tested("getCurrentController()", ctrl
!= null);
146 * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares
147 * selection and calls the method. <p>
148 * Has <b> OK </b> status if the method does not return null.
150 public void _getCurrentSelection() {
151 XSelectionSupplier selsupp
= (XSelectionSupplier
) tEnv
.getObjRelation(
153 Object toSelect
= tEnv
.getObjRelation("TOSELECT");
156 if (selsupp
== null) {
157 log
.println("No Selection Supplier no show");
160 selsupp
.select(toSelect
);
161 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
162 log
.println("Exception occured while select:");
163 e
.printStackTrace(log
);
168 Object sel
= oObj
.getCurrentSelection();
169 result
= (sel
!= null);
172 tRes
.tested("getCurrentSelection()", result
);
176 * Test calls the method. <p>
177 * Has <b> OK </b> status if the method does not return null.
179 public void _getURL() {
180 String url
= oObj
.getURL();
181 log
.println("The url: " + url
);
182 tRes
.tested("getURL()", url
!= null);
186 * if controller is not locked, test calls the method. <p>
187 * Has <b> OK </b> status if the method returns true. <p>
188 * The following method tests are to be completed successfully before :
190 * <li> <code> lockControllers() </code> : locks controllers </li>
193 public void _hasControllersLocked() {
194 requiredMethod("lockControllers()");
195 tRes
.tested("hasControllersLocked()", oObj
.hasControllersLocked());
199 * Test calls the method, then result is checked.<p>
200 * Has <b> OK </b> status if method locks controllers.
202 public void _lockControllers() {
203 oObj
.lockControllers();
204 result
= oObj
.hasControllersLocked();
205 tRes
.tested("lockControllers()", result
);
209 * After obtaining object relation 'CONT2' and storing old controller,
210 * controller cont2 is connected, then this controller is
211 * setting as current.
212 * Sets the old controller as current.
213 * <p>Has <b> OK </b> status if set and gotten controllers are not equal.
215 public void _setCurrentController() {
216 XController cont2
= (XController
) tEnv
.getObjRelation("CONT2");
217 XController old
= oObj
.getCurrentController();
221 log
.println("No controller no show");
223 oObj
.connectController(cont2
);
226 oObj
.setCurrentController(cont2
);
227 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
228 log
.print("Cannot set current controller:");
229 e
.printStackTrace(log
);
232 result
= (oObj
.getCurrentController() != old
);
235 oObj
.setCurrentController(old
);
236 } catch (com
.sun
.star
.container
.NoSuchElementException e
) {
237 log
.print("Cannot set current controller:");
238 e
.printStackTrace(log
);
242 tRes
.tested("setCurrentController()", result
);
246 * Test calls the method. <p>
247 * Has <b> OK </b> status if method unlocks controllers.
249 * The following method tests are to be completed successfully before :
251 * <li> <code> hasControllersLocked() </code> : checks if controllers are
255 public void _unlockControllers() {
256 requiredMethod("hasControllersLocked()");
257 oObj
.unlockControllers();
258 result
= !oObj
.hasControllersLocked();
259 tRes
.tested("unlockControllers()", result
);