Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFrameLoader.java
blob0fb7b9acd2254a6ab6eaed4d5303bd7f3977662b
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.XFrameLoader;
30 import com.sun.star.frame.XLoadEventListener;
31 import com.sun.star.lang.EventObject;
32 import com.sun.star.lang.XComponent;
33 import com.sun.star.uno.UnoRuntime;
36 /**
37 * Testing <code>com.sun.star.frame.XFrameLoader</code>
38 * interface methods :
39 * <ul>
40 * <li><code> load()</code></li>
41 * <li><code> cancel()</code></li>
42 * </ul> <p>
43 * This test needs the following object relations :
44 * <ul>
45 * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>):
46 * an url or component to be loaded </li>
47 * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b>
48 * (of type <code>com.sun.star.frame.XFrame</code>):
49 * a target frame where component to be loaded. If this
50 * relation is omitted then a text document created and its
51 * frame is used. </li>
52 * <li> <code>'FrameLoader.args'</code> <b>(optional)</b>
53 * (of type <code>Object[]</code>):
54 * necessary arguuments for loading a component. If omitted
55 * then zero length array is passed as parameter</li>
56 * <ul> <p>
57 * Test is <b> NOT </b> multithread compliant. <p>
58 * @see com.sun.star.frame.XFrameLoader
60 public class _XFrameLoader extends MultiMethodTest {
62 public XFrameLoader oObj = null; // oObj filled by MultiMethodTest
63 private String url = null ;
64 private XFrame frame = null ;
65 private PropertyValue[] args = new PropertyValue[0] ;
67 /**
68 * Implemetation of load listener which geristers all its calls.
70 protected class TestListener implements XLoadEventListener {
71 public boolean finished = false ;
72 public boolean cancelled = false ;
74 public void loadFinished(XFrameLoader l) {
75 finished = true ;
77 public void loadCancelled(XFrameLoader l) {
78 cancelled = true ;
80 public void disposing(EventObject e) {}
83 TestListener listener = new TestListener() ;
84 XComponent frameSup = null ;
86 /**
87 * Retrieves all relations. If optional ones are not found
88 * creates their default values. <p>
89 * @throws StatusException If one of required relations not found.
91 @Override
92 public void before() {
93 url = (String) tEnv.getObjRelation("FrameLoader.URL") ;
94 frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ;
96 if (frame == null) {
97 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
99 try {
100 log.println( "creating a textdocument" );
101 frameSup = SOF.createTextDoc( null );
103 Object oDsk = tParam.getMSF()
104 .createInstance("com.sun.star.frame.Desktop") ;
105 XDesktop dsk = UnoRuntime.queryInterface(XDesktop.class, oDsk) ;
107 util.utils.shortWait();
108 frame = dsk.getCurrentFrame() ;
109 } catch ( com.sun.star.uno.Exception e ) {
110 // Some exception occurs.FAILED
111 e.printStackTrace( log );
112 throw new StatusException( "Couldn't create a frame.", e );
116 Object args = tEnv.getObjRelation("FrameLoader.args") ;
117 if (args != null) this.args = (PropertyValue[]) args ;
119 if (url == null /*|| frame == null*/) {
120 throw new StatusException
121 (Status.failed("Some relations not found")) ;
125 private boolean loaded = false ;
128 * First <code>cancel</code> method test is called.
129 * If in that test loaing process was interrupted by
130 * <code>cancel</code> call then <code>load</code> test
131 * executes. It loads a component, waits some moment to
132 * listener have a chance to be called and then checks
133 * if the load listener was called.<p>
134 * Has <b>OK</b> status if <code>cancel</code> method test
135 * didn't interrupt loading and it was successful, or
136 * if in this method it loads successful and listener's
137 * <code>finished</code> method was called.
138 * The following method tests are to be executed before:
139 * <ul>
140 * <li> <code> cancel() </code> </li>
141 * </ul>
143 public void _load() {
144 executeMethod("cancel()") ;
146 if (!loaded) {
147 oObj.load(frame, url, args, listener) ;
149 util.utils.shortWait();
151 loaded = listener.finished ;
154 tRes.tested("load()", loaded) ;
158 * Starts to load a component and then immediately tries to
159 * cancel the process. <p>
160 * Has <b>OK</b> status if the process was cancelled or
161 * finished (appropriate listener methods were called).
163 public void _cancel() {
164 boolean result = true ;
166 oObj.load(frame, url, args, listener) ;
167 oObj.cancel() ;
169 util.utils.shortWait();
171 if (listener.cancelled) {
172 log.println("Loading was canceled.") ;
174 if (listener.finished) {
175 log.println("Loading was finished.") ;
176 loaded = true ;
178 if (!listener.cancelled && !listener.finished) {
179 log.println("Loading was not canceled and not finished") ;
180 result = false ;
183 tRes.tested("cancel()", result) ;
186 @Override
187 public void after() {
188 if (frameSup != null) frameSup.dispose() ;
189 frame.dispose();