Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XSynchronousFrameLoader.java
blob6b3ed19d0265de34413206eab0f749f0f68a9a9e
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 .
19 package ifc.frame;
21 import lib.MultiMethodTest;
22 import lib.Status;
23 import lib.StatusException;
24 import util.SOfficeFactory;
26 import com.sun.star.beans.PropertyValue;
27 import com.sun.star.frame.XDesktop;
28 import com.sun.star.frame.XFrame;
29 import com.sun.star.frame.XSynchronousFrameLoader;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.uno.UnoRuntime;
32 import com.sun.star.util.URL;
33 import com.sun.star.util.XURLTransformer;
35 /**
36 * Testing <code>com.sun.star.frame.XSynchronousFrameLoader</code>
37 * interface methods :
38 * <ul>
39 * <li><code> load()</code></li>
40 * <li><code> cancel()</code></li>
41 * </ul> <p>
42 * This test needs the following object relations :
43 * <ul>
44 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
45 * an url of component to be loaded </li>
46 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
47 * (of type <code>com.sun.star.frame.XFrame</code>):
48 * a target frame where component to be loaded. If this
49 * relation is omitted then a text document created and its
50 * frame is used. </li>
51 * <ul> <p>
53 * @see com.sun.star.frame.XSynchronousFrameLoader
55 public class _XSynchronousFrameLoader extends MultiMethodTest {
57 public XSynchronousFrameLoader oObj = null; // oObj filled by MultiMethodTest
58 private XFrame frame = null ;
59 private XComponent frameSup = null ;
60 private PropertyValue[] descr = null;
62 /**
63 * Retrieves all relations. If optional relation
64 * <code>FrameLoader.Frame</code> not found
65 * creates a new document and otains its frame for loading. <p>
67 * Also <code>MediaDescriptor</code> is created using
68 * URL from <code>FrameLoader.URL</code> relation.
70 * @throws StatusException If one of required relations not found.
72 @Override
73 public void before() {
74 String url = (String) tEnv.getObjRelation("FrameLoader.URL") ;
75 frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ;
77 if (url == null) {
78 throw new StatusException(Status.failed("Some relations not found")) ;
81 SOfficeFactory SOF = SOfficeFactory.getFactory(
82 tParam.getMSF() );
84 XURLTransformer xURLTrans = null;
86 // if frame is not contained in relations the writer frmame will be used.
87 if (frame == null) {
88 try {
89 log.println( "creating a textdocument" );
90 frameSup = SOF.createTextDoc( null );
92 Object oDsk = tParam.getMSF().createInstance
93 ("com.sun.star.frame.Desktop") ;
94 XDesktop dsk = UnoRuntime.queryInterface
95 (XDesktop.class, oDsk) ;
96 frame = dsk.getCurrentFrame() ;
98 Object o = tParam.getMSF().createInstance
99 ("com.sun.star.util.URLTransformer") ;
100 xURLTrans = UnoRuntime.queryInterface
101 (XURLTransformer.class, o) ;
103 } catch ( com.sun.star.uno.Exception e ) {
104 // Some exception occurs.FAILED
105 e.printStackTrace( log );
106 throw new StatusException( "Couldn't create a document.", e );
110 URL[] urlS = new URL[1];
111 urlS[0] = new URL();
112 urlS[0].Complete = url;
113 boolean res = xURLTrans.parseStrict(urlS);
114 log.println("Parsing URL '" + url + "': " + res);
115 descr = new PropertyValue[1] ;
116 descr[0] = new PropertyValue();
117 descr[0].Name = "URL" ;
118 descr[0].Value = urlS[0] ;
123 * Tries to load component to a frame. <p>
124 * Has <b> OK </b> status if <code>true</code> is returned.
126 public void _load() {
127 boolean result = oObj.load(descr, frame) ;
129 tRes.tested("load()", result) ;
133 * Tries to load component to a frame in separate thread to
134 * avoid blocking of the current thread and immediately
135 * cancels loading. <p>
137 * Has <b> OK </b> status if <code>flase</code> is returned,
138 * i.e. loading was not completed.
140 public void _cancel() {
141 requiredMethod("load()") ;
143 final boolean[] result = new boolean[1] ;
145 (new Thread() {
146 @Override
147 public void run() {
148 result[0] = oObj.load(descr, frame);
150 }).start();
152 oObj.cancel() ;
154 util.utils.pause(1000);
157 tRes.tested("cancel()", !result[0]) ;
161 * Disposes document if it was created for frame supplying.
163 @Override
164 protected void after() {
165 if (frameSup != null) {
166 frameSup.dispose();