Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XModel.java
blob320570b5fa08f37785151694bfdac2e44bf98b1d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 package ifc.frame;
20 import com.sun.star.beans.PropertyValue;
21 import com.sun.star.frame.XController;
22 import com.sun.star.frame.XModel;
23 import com.sun.star.view.XSelectionSupplier;
25 import lib.MultiMethodTest;
28 /**
29 * Testing <code>com.sun.star.frame.XModel</code>
30 * interface methods:
31 * <ul>
32 * <li><code> attachResource() </code></li>
33 * <li><code> connectController() </code></li>
34 * <li><code> disconnectController() </code></li>
35 * <li><code> getArgs() </code></li>
36 * <li><code> getCurrentController() </code></li>
37 * <li><code> getCurrentSelection() </code></li>
38 * <li><code> getURL() </code></li>
39 * <li><code> hasControllersLocked() </code></li>
40 * <li><code> lockControllers() </code></li>
41 * <li><code> setCurrentController() </code></li>
42 * <li><code> unlockControllers() </code></li>
43 * </ul><p>
44 * This test needs the following object relations :
45 * <ul>
46 * <li> <code>'CONT2'</code> (of type <code>XController</code>):
47 * a controller used as an argument for several test methods </li>
48 * <li> <code>'TOSELECT'</code> (of type <code>Object</code>):
49 * something, we want to select from document </li>
50 * <li> <code>'SELSUPP'</code> (of type <code>XSelectionSupplier</code>):
51 * supplier, we use to select something in a document </li>
52 * </ul> <p>
53 * Test is <b> NOT </b> multithread compliant. <p>
54 * @see com.sun.star.frame.XModel
56 public class _XModel extends MultiMethodTest {
57 public XModel oObj = null;
58 boolean result = true;
60 /**
61 * Test calls the method. <p>
62 * Has <b> OK </b> status if the method returns true.
64 public void _attachResource() {
65 log.println("opening DataSourceBrowser");
67 PropertyValue[] noArgs = new PropertyValue[0];
68 result = oObj.attachResource(".component:DB/DataSourceBrowser", noArgs);
69 tRes.tested("attachResource()", result);
72 /**
73 * After obtaining object relation 'CONT2' and storing old controller,
74 * test calls the method, then result is checked.<p>
75 * Has <b> OK </b> status if controller, gotten after method call is not
76 * equal to a previous controller.
78 public void _connectController() {
79 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
80 XController old = oObj.getCurrentController();
81 result = false;
83 if (cont2 == null) {
84 log.println("No controller no show");
85 } else {
86 oObj.connectController(cont2);
88 String oldFrame = old.getFrame().getName();
89 String newFrame = cont2.getFrame().getName();
90 result = (!oldFrame.equals(newFrame));
93 tRes.tested("connectController()", result);
96 /**
97 * After obtaining object relation 'CONT2', test calls the method,
98 * then result is checked.<p>
99 * Has <b> OK </b> status if controller, gotten after method call is not
100 * equal to a controller we use as an argument to method.
102 public void _disconnectController() {
103 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
104 result = false;
106 if (cont2 == null) {
107 log.println("No controller no show");
108 } else {
109 oObj.disconnectController(cont2);
110 result = (oObj.getCurrentController() != cont2);
113 tRes.tested("disconnectController()", result);
117 * Test calls the method. <p>
118 * Has <b> OK </b> status if the method does not return null.
120 public void _getArgs() {
121 tRes.tested("getArgs()", oObj.getArgs() != null);
125 * Test calls the method. <p>
126 * Has <b> OK </b> status if the method does not return null.
128 public void _getCurrentController() {
129 XController ctrl = oObj.getCurrentController();
130 tRes.tested("getCurrentController()", ctrl != null);
134 * After obtaining object relations 'SELSUPP' and 'TOSELECT', test prepares
135 * selection and calls the method. <p>
136 * Has <b> OK </b> status if the method does not return null.
138 public void _getCurrentSelection() {
139 XSelectionSupplier selsupp = (XSelectionSupplier) tEnv.getObjRelation(
140 "SELSUPP");
141 Object toSelect = tEnv.getObjRelation("TOSELECT");
142 result = false;
144 if (selsupp == null) {
145 log.println("No Selection Supplier no show");
146 } else {
147 try {
148 selsupp.select(toSelect);
149 } catch (com.sun.star.lang.IllegalArgumentException e) {
150 log.println("Exception occurred while select:");
151 e.printStackTrace(log);
153 return;
156 Object sel = oObj.getCurrentSelection();
157 result = (sel != null);
160 tRes.tested("getCurrentSelection()", result);
164 * Test calls the method. <p>
165 * Has <b> OK </b> status if the method does not return null.
167 public void _getURL() {
168 String url = oObj.getURL();
169 log.println("The url: " + url);
170 tRes.tested("getURL()", url != null);
174 * if controller is not locked, test calls the method. <p>
175 * Has <b> OK </b> status if the method returns true. <p>
176 * The following method tests are to be completed successfully before :
177 * <ul>
178 * <li> <code> lockControllers() </code> : locks controllers </li>
179 * </ul>
181 public void _hasControllersLocked() {
182 requiredMethod("lockControllers()");
183 tRes.tested("hasControllersLocked()", oObj.hasControllersLocked());
187 * Test calls the method, then result is checked.<p>
188 * Has <b> OK </b> status if method locks controllers.
190 public void _lockControllers() {
191 oObj.lockControllers();
192 result = oObj.hasControllersLocked();
193 tRes.tested("lockControllers()", result);
197 * After obtaining object relation 'CONT2' and storing old controller,
198 * controller cont2 is connected, then this controller is
199 * setting as current.
200 * Sets the old controller as current.
201 * <p>Has <b> OK </b> status if set and gotten controllers are not equal.
203 public void _setCurrentController() {
204 XController cont2 = (XController) tEnv.getObjRelation("CONT2");
205 XController old = oObj.getCurrentController();
206 result = false;
208 if (cont2 == null) {
209 log.println("No controller no show");
210 } else {
211 oObj.connectController(cont2);
213 try {
214 oObj.setCurrentController(cont2);
215 } catch (com.sun.star.container.NoSuchElementException e) {
216 log.print("Cannot set current controller:");
217 e.printStackTrace(log);
220 result = (oObj.getCurrentController() != old);
222 try {
223 oObj.setCurrentController(old);
224 } catch (com.sun.star.container.NoSuchElementException e) {
225 log.print("Cannot set current controller:");
226 e.printStackTrace(log);
230 tRes.tested("setCurrentController()", result);
234 * Test calls the method. <p>
235 * Has <b> OK </b> status if method unlocks controllers.
236 * <p>
237 * The following method tests are to be completed successfully before :
238 * <ul>
239 * <li> <code> hasControllersLocked() </code> : checks if controllers are
240 * locked </li>
241 * </ul>
243 public void _unlockControllers() {
244 requiredMethod("hasControllersLocked()");
245 oObj.unlockControllers();
246 result = !oObj.hasControllersLocked();
247 tRes.tested("unlockControllers()", result);