Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XSynchronousFrameLoader.java
blob2f430afa6e39c403e4ddd365b7c33fdec655667f
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 ************************************************************************/
28 package ifc.frame;
30 import lib.MultiMethodTest;
31 import lib.Status;
32 import lib.StatusException;
33 import util.SOfficeFactory;
35 import com.sun.star.beans.PropertyValue;
36 import com.sun.star.frame.XDesktop;
37 import com.sun.star.frame.XFrame;
38 import com.sun.star.frame.XSynchronousFrameLoader;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.util.URL;
43 import com.sun.star.util.XURLTransformer;
45 /**
46 * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code>
47 * interface methods :
48 * <ul>
49 * <li><code> load()</code></li>
50 * <li><code> cancel()</code></li>
51 * </ul> <p>
52 * This test needs the following object relations :
53 * <ul>
54 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
55 * an url of component to be loaded </li>
56 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
57 * (of type <code>com.sun.star.frame.XFrame</code>):
58 * a target frame where component to be loaded. If this
59 * relation is ommited then a text document created and its
60 * frame is used. </li>
61 * <ul> <p>
63 * @see com.sun.star.frame.XSynchronousFrameLoader
65 public class _XSynchronousFrameLoader extends MultiMethodTest {
67 public XSynchronousFrameLoader oObj = null; // oObj filled by MultiMethodTest
68 private String url = null ;
69 private XFrame frame = null ;
70 private XComponent frameSup = null ;
71 private PropertyValue[] descr = null;
73 /**
74 * Retrieves all relations. If optional relation
75 * <code>FrameLoader.Frame</code> not found
76 * creates a new document and otains its frame for loading. <p>
78 * Also <code>MediaDescriptor</code> is created using
79 * URL from <code>FrameLoader.URL</code> relation.
81 * @throws StatusException If one of required relations not found.
83 public void before() {
84 url = (String) tEnv.getObjRelation("FrameLoader.URL") ;
85 frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ;
87 if (url == null) {
88 throw new StatusException(Status.failed("Some relations not found")) ;
91 SOfficeFactory SOF = SOfficeFactory.getFactory(
92 (XMultiServiceFactory)tParam.getMSF() );
94 XURLTransformer xURLTrans = null;
96 // if frame is not contained in relations the writer frmame will be used.
97 if (frame == null) {
98 try {
99 log.println( "creating a textdocument" );
100 frameSup = SOF.createTextDoc( null );
102 Object oDsk = (
103 (XMultiServiceFactory)tParam.getMSF()).createInstance
104 ("com.sun.star.frame.Desktop") ;
105 XDesktop dsk = (XDesktop) UnoRuntime.queryInterface
106 (XDesktop.class, oDsk) ;
107 frame = dsk.getCurrentFrame() ;
109 Object o = (
110 (XMultiServiceFactory)tParam.getMSF()).createInstance
111 ("com.sun.star.util.URLTransformer") ;
112 xURLTrans = (XURLTransformer) UnoRuntime.queryInterface
113 (XURLTransformer.class, o) ;
115 } catch ( com.sun.star.uno.Exception e ) {
116 // Some exception occures.FAILED
117 e.printStackTrace( log );
118 throw new StatusException( "Couldn't create a document.", e );
122 URL[] urlS = new URL[1];
123 urlS[0] = new URL();
124 urlS[0].Complete = url;
125 boolean res = xURLTrans.parseStrict(urlS);
126 log.println("Parsing URL '" + url + "': " + res);
127 descr = new PropertyValue[1] ;
128 descr[0] = new PropertyValue();
129 descr[0].Name = "URL" ;
130 descr[0].Value = urlS[0] ;
135 * Tries to load component to a frame. <p>
136 * Has <b> OK </b> status if <code>true</code> is returned.
138 public void _load() {
139 boolean result = oObj.load(descr, frame) ;
141 tRes.tested("load()", result) ;
145 * Tries to load component to a frame in separate thread to
146 * avoid blocking of the current thread and imediately
147 * cancels loading. <p>
149 * Has <b> OK </b> status if <code>flase</code> is returned,
150 * i.e. loading was not completed.
152 public void _cancel() {
153 requiredMethod("load()") ;
155 final boolean[] result = new boolean[1] ;
157 (new Thread() {
158 public void run() {
159 result[0] = oObj.load(descr, frame);
161 }).start();
163 oObj.cancel() ;
165 try {
166 Thread.sleep(1000);
167 } catch (InterruptedException ex) {}
170 tRes.tested("cancel()", !result[0]) ;
174 * Disposes document if it was created for frame supplying.
176 protected void after() {
177 if (frameSup != null) {
178 frameSup.dispose();