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