/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.frame;
import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;
import util.SOfficeFactory;
import com.sun.star.beans.PropertyValue;
import com.sun.star.frame.XDesktop;
import com.sun.star.frame.XFrame;
import com.sun.star.frame.XFrameLoader;
import com.sun.star.frame.XLoadEventListener;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.uno.UnoRuntime;
/**
* Testing com.sun.star.frame.XFrameLoader
* interface methods :
*
load()
cancel()
* This test needs the following object relations : *
'FrameLoader.URL'
(of type String
):
* an url or component to be loaded 'FrameLoader.Frame'
(optional)
* (of type com.sun.star.frame.XFrame
):
* a target frame where component to be loaded. If this
* relation is omitted then a text document created and its
* frame is used. 'FrameLoader.args'
(optional)
* (of type Object[]
):
* necessary arguuments for loading a component. If omitted
* then zero length array is passed as parameter* Test is NOT multithread compilant.
* @see com.sun.star.frame.XFrameLoader */ public class _XFrameLoader extends MultiMethodTest { public XFrameLoader oObj = null; // oObj filled by MultiMethodTest private String url = null ; private XFrame frame = null ; private PropertyValue[] args = new PropertyValue[0] ; /** * Implemetation of load listener which geristers all it's calls. */ protected class TestListener implements XLoadEventListener { public boolean finished = false ; public boolean cancelled = false ; public void loadFinished(XFrameLoader l) { finished = true ; } public void loadCancelled(XFrameLoader l) { cancelled = true ; } public void disposing(EventObject e) {} } TestListener listener = new TestListener() ; XComponent frameSup = null ; /** * Retrieves all relations. If optional ones are not found * creates their default values.
* @throws StatusException If one of required relations not found.
*/
public void before() {
url = (String) tEnv.getObjRelation("FrameLoader.URL") ;
frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ;
if (frame == null) {
SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
try {
log.println( "creating a textdocument" );
frameSup = SOF.createTextDoc( null );
Object oDsk = ((XMultiServiceFactory)tParam.getMSF())
.createInstance("com.sun.star.frame.Desktop") ;
XDesktop dsk = (XDesktop)
UnoRuntime.queryInterface(XDesktop.class, oDsk) ;
shortWait() ;
frame = dsk.getCurrentFrame() ;
} catch ( com.sun.star.uno.Exception e ) {
// Some exception occured.FAILED
e.printStackTrace( log );
throw new StatusException( "Couldn't create a frame.", e );
}
}
Object args = tEnv.getObjRelation("FrameLoader.args") ;
if (args != null) this.args = (PropertyValue[]) args ;
if (url == null /*|| frame == null*/) {
throw new StatusException
(Status.failed("Some relations not found")) ;
}
}
private boolean loaded = false ;
/**
* Firts cancel
method test is called.
* If in that test loaing process was interrupted by
* cancel
call then load
test
* executes. It loads a component, waits some moment to
* listener have a chance to be called and then checks
* if the load listener was called.
* Has OK status if cancel
method test
* didn't interrupt loading and it was successful, or
* if in this method it loads successful and listener's
* finished
method was called.
* The following method tests are to be executed before :
*
cancel()
* Has OK status if the process was cancelled or * finished (appropriate listener methods were called). */ public void _cancel() { boolean result = true ; oObj.load(frame, url, args, listener) ; oObj.cancel() ; shortWait(); if (listener.cancelled) { log.println("Loading was canceled.") ; } if (listener.finished) { log.println("Loading was finished.") ; loaded = true ; } if (!listener.cancelled && !listener.finished) { log.println("Loading was not canceled and not finished") ; result = false ; } tRes.tested("cancel()", result) ; } public void after() { if (frameSup != null) frameSup.dispose() ; frame.dispose(); } private void shortWait() { try { Thread.sleep(5000); } catch (InterruptedException ex) { } } }