merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / ifc / frame / _XFrameLoader.java
blob813a7075e0345025ab29193a479148ec92e9d463
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFrameLoader.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.frame;
33 import lib.MultiMethodTest;
34 import lib.Status;
35 import lib.StatusException;
36 import util.SOfficeFactory;
38 import com.sun.star.beans.PropertyValue;
39 import com.sun.star.frame.XDesktop;
40 import com.sun.star.frame.XFrame;
41 import com.sun.star.frame.XFrameLoader;
42 import com.sun.star.frame.XLoadEventListener;
43 import com.sun.star.lang.EventObject;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.uno.UnoRuntime;
49 /**
50 * Testing <code>com.sun.star.frame.XFrameLoader</code>
51 * interface methods :
52 * <ul>
53 * <li><code> load()</code></li>
54 * <li><code> cancel()</code></li>
55 * </ul> <p>
56 * This test needs the following object relations :
57 * <ul>
58 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
59 * an url or component to be loaded </li>
60 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
61 * (of type <code>com.sun.star.frame.XFrame</code>):
62 * a target frame where component to be loaded. If this
63 * relation is ommited then a text document created and its
64 * frame is used. </li>
65 * <li> <code>'FrameLoader.args'</code> <b>(optional)</b>
66 * (of type <code>Object[]</code>):
67 * necessary arguuments for loading a component. If ommited
68 * then zero length array is passed as parameter</li>
69 * <ul> <p>
70 * Test is <b> NOT </b> multithread compilant. <p>
71 * @see com.sun.star.frame.XFrameLoader
73 public class _XFrameLoader extends MultiMethodTest {
75 public XFrameLoader oObj = null; // oObj filled by MultiMethodTest
76 private String url = null ;
77 private XFrame frame = null ;
78 private PropertyValue[] args = new PropertyValue[0] ;
80 /**
81 * Implemetation of load listener which geristers all it's calls.
83 protected class TestListener implements XLoadEventListener {
84 public boolean finished = false ;
85 public boolean cancelled = false ;
87 public void loadFinished(XFrameLoader l) {
88 finished = true ;
90 public void loadCancelled(XFrameLoader l) {
91 cancelled = true ;
93 public void disposing(EventObject e) {}
96 TestListener listener = new TestListener() ;
97 XComponent frameSup = null ;
99 /**
100 * Retrieves all relations. If optional ones are not found
101 * creates their default values. <p>
102 * @throws StatusException If one of required relations not found.
104 public void before() {
105 url = (String) tEnv.getObjRelation("FrameLoader.URL") ;
106 frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ;
108 if (frame == null) {
109 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
111 try {
112 log.println( "creating a textdocument" );
113 frameSup = SOF.createTextDoc( null );
115 Object oDsk = ((XMultiServiceFactory)tParam.getMSF())
116 .createInstance("com.sun.star.frame.Desktop") ;
117 XDesktop dsk = (XDesktop)
118 UnoRuntime.queryInterface(XDesktop.class, oDsk) ;
120 shortWait() ;
121 frame = dsk.getCurrentFrame() ;
122 } catch ( com.sun.star.uno.Exception e ) {
123 // Some exception occures.FAILED
124 e.printStackTrace( log );
125 throw new StatusException( "Couldn't create a frame.", e );
129 Object args = tEnv.getObjRelation("FrameLoader.args") ;
130 if (args != null) this.args = (PropertyValue[]) args ;
132 if (url == null /*|| frame == null*/) {
133 throw new StatusException
134 (Status.failed("Some relations not found")) ;
138 private boolean loaded = false ;
141 * Firts <code>cancel</code> method test is called.
142 * If in that test loaing process was interrupted by
143 * <code>cancel</code> call then <code>load</code> test
144 * executes. It loads a component, waits some moment to
145 * listener have a chance to be called and then checks
146 * if the load listener was called. <p>
147 * Has <b>OK</b> status if <code>cancel</code> method test
148 * didn't interrupt loading and it was successfull, or
149 * if in this method it loads successfull and listener's
150 * <code>finished</code> method was called.
151 * The following method tests are to be executed before :
152 * <ul>
153 * <li> <code> cancel() </code> </li>
154 * </ul>
156 public void _load() {
157 executeMethod("cancel()") ;
159 if (!loaded) {
160 oObj.load(frame, url, args, listener) ;
162 shortWait();
164 loaded = listener.finished ;
167 tRes.tested("load()", loaded) ;
171 * Starts to load a component and then immediatly tries to
172 * cancel the process. <p>
173 * Has <b>OK</b> status if the process was cancelled or
174 * finished (appropriate listener methods were called).
176 public void _cancel() {
177 boolean result = true ;
179 oObj.load(frame, url, args, listener) ;
180 oObj.cancel() ;
182 shortWait();
184 if (listener.cancelled) {
185 log.println("Loading was canceled.") ;
187 if (listener.finished) {
188 log.println("Loading was finished.") ;
189 loaded = true ;
191 if (!listener.cancelled && !listener.finished) {
192 log.println("Loading was not canceled and not finished") ;
193 result = false ;
196 tRes.tested("cancel()", result) ;
199 public void after() {
200 if (frameSup != null) frameSup.dispose() ;
201 frame.dispose();
204 private void shortWait() {
205 try {
206 Thread.sleep(5000);
208 catch (InterruptedException ex) {