Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XModel.java
blobfcc54dd8b2784de2c98b398ba5b337fd0aec0554
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
27 package ifc.frame;
29 import com.sun.star.beans.PropertyValue;
30 import com.sun.star.frame.XController;
31 import com.sun.star.frame.XModel;
32 import com.sun.star.view.XSelectionSupplier;
34 import lib.MultiMethodTest;
37 /**
38 * Testing <code>com.sun.star.frame.XModel</code>
39 * interface methods:
40 * <ul>
41 * <li><code> attachResource() </code></li>
42 * <li><code> connectController() </code></li>
43 * <li><code> disconnectController() </code></li>
44 * <li><code> getArgs() </code></li>
45 * <li><code> getCurrentController() </code></li>
46 * <li><code> getCurrentSelection() </code></li>
47 * <li><code> getURL() </code></li>
48 * <li><code> hasControllersLocked() </code></li>
49 * <li><code> lockControllers() </code></li>
50 * <li><code> setCurrentController() </code></li>
51 * <li><code> unlockControllers() </code></li>
52 * </ul><p>
53 * This test needs the following object relations :
54 * <ul>
55 * <li> <code>'CONT2'</code> (of type <code>XController</code>):
56 * a controller used as an argument for several test methods </li>
57 * <li> <code>'TOSELECT'</code> (of type <code>Object</code>):
58 * something, we want to select from document </li>
59 * <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>):
60 * supplier, we use to select something in a document </li>
61 * </ul> <p>
62 * Test is <b> NOT </b> multithread compilant. <p>
63 * @see com.sun.star.frame.XModel
65 public class _XModel extends MultiMethodTest {
66 public XModel oObj = null;
67 boolean result = true;
69 /**
70 * Test calls the method. <p>
71 * Has <b> OK </b> status if the method returns true.
73 public void _attachResource() {
74 log.println("opening DataSourceBrowser");
76 PropertyValue[] noArgs = new PropertyValue[0];
77 result = oObj.attachResource(".component:DB/DataSourceBrowser", noArgs);
78 tRes.tested("attachResource()", result);
81 /**
82 * After obtaining object relation 'CONT2' and storing old controller,
83 * test calls the method, then result is checked.<p>
84 * Has <b> OK </b> status if controller, gotten after method call is not
85 * equal to a previous controller.
87 public void _connectController() {
88 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
89 XController old = oObj.getCurrentController();
90 result = false;
92 if (cont2 == null) {
93 log.println("No controller no show");
94 } else {
95 oObj.connectController(cont2);
97 String oldFrame = old.getFrame().getName();
98 String newFrame = cont2.getFrame().getName();
99 result = (!oldFrame.equals(newFrame));
102 tRes.tested("connectController()", result);
106 * After obtaining object relation 'CONT2', test calls the method,
107 * then result is checked.<p>
108 * Has <b> OK </b> status if controller, gotten after method call is not
109 * equal to a controller we use as an argument to method.
111 public void _disconnectController() {
112 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
113 result = false;
115 if (cont2 == null) {
116 log.println("No controller no show");
117 } else {
118 oObj.disconnectController(cont2);
119 result = (oObj.getCurrentController() != cont2);
122 tRes.tested("disconnectController()", result);
126 * Test calls the method. <p>
127 * Has <b> OK </b> status if the method does not return null.
129 public void _getArgs() {
130 tRes.tested("getArgs()", oObj.getArgs() != null);
134 * Test calls the method. <p>
135 * Has <b> OK </b> status if the method does not return null.
137 public void _getCurrentController() {
138 XController ctrl = oObj.getCurrentController();
139 tRes.tested("getCurrentController()", ctrl != null);
143 * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares
144 * selection and calls the method. <p>
145 * Has <b> OK </b> status if the method does not return null.
147 public void _getCurrentSelection() {
148 XSelectionSupplier selsupp = (XSelectionSupplier) tEnv.getObjRelation(
149 "SELSUPP");
150 Object toSelect = tEnv.getObjRelation("TOSELECT");
151 result = false;
153 if (selsupp == null) {
154 log.println("No Selection Supplier no show");
155 } else {
156 try {
157 selsupp.select(toSelect);
158 } catch (com.sun.star.lang.IllegalArgumentException e) {
159 log.println("Exception occurred while select:");
160 e.printStackTrace(log);
162 return;
165 Object sel = oObj.getCurrentSelection();
166 result = (sel != null);
169 tRes.tested("getCurrentSelection()", result);
173 * Test calls the method. <p>
174 * Has <b> OK </b> status if the method does not return null.
176 public void _getURL() {
177 String url = oObj.getURL();
178 log.println("The url: " + url);
179 tRes.tested("getURL()", url != null);
183 * if controller is not locked, test calls the method. <p>
184 * Has <b> OK </b> status if the method returns true. <p>
185 * The following method tests are to be completed successfully before :
186 * <ul>
187 * <li> <code> lockControllers() </code> : locks controllers </li>
188 * </ul>
190 public void _hasControllersLocked() {
191 requiredMethod("lockControllers()");
192 tRes.tested("hasControllersLocked()", oObj.hasControllersLocked());
196 * Test calls the method, then result is checked.<p>
197 * Has <b> OK </b> status if method locks controllers.
199 public void _lockControllers() {
200 oObj.lockControllers();
201 result = oObj.hasControllersLocked();
202 tRes.tested("lockControllers()", result);
206 * After obtaining object relation 'CONT2' and storing old controller,
207 * controller cont2 is connected, then this controller is
208 * setting as current.
209 * Sets the old controller as current.
210 * <p>Has <b> OK </b> status if set and gotten controllers are not equal.
212 public void _setCurrentController() {
213 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
214 XController old = oObj.getCurrentController();
215 result = false;
217 if (cont2 == null) {
218 log.println("No controller no show");
219 } else {
220 oObj.connectController(cont2);
222 try {
223 oObj.setCurrentController(cont2);
224 } catch (com.sun.star.container.NoSuchElementException e) {
225 log.print("Cannot set current controller:");
226 e.printStackTrace(log);
229 result = (oObj.getCurrentController() != old);
231 try {
232 oObj.setCurrentController(old);
233 } catch (com.sun.star.container.NoSuchElementException e) {
234 log.print("Cannot set current controller:");
235 e.printStackTrace(log);
239 tRes.tested("setCurrentController()", result);
243 * Test calls the method. <p>
244 * Has <b> OK </b> status if method unlocks controllers.
245 * <p>
246 * The following method tests are to be completed successfully before :
247 * <ul>
248 * <li> <code> hasControllersLocked() </code> : checks if controllers are
249 * locked </li>
250 * </ul>
252 public void _unlockControllers() {
253 requiredMethod("hasControllersLocked()");
254 oObj.unlockControllers();
255 result = !oObj.hasControllersLocked();
256 tRes.tested("unlockControllers()", result);