1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir package ifc.frame; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import lib.MultiMethodTest; 31*cdf0e10cSrcweir import lib.Status; 32*cdf0e10cSrcweir import lib.StatusException; 33*cdf0e10cSrcweir import util.SOfficeFactory; 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir import com.sun.star.beans.PropertyValue; 36*cdf0e10cSrcweir import com.sun.star.frame.XDesktop; 37*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 38*cdf0e10cSrcweir import com.sun.star.frame.XFrameLoader; 39*cdf0e10cSrcweir import com.sun.star.frame.XLoadEventListener; 40*cdf0e10cSrcweir import com.sun.star.lang.EventObject; 41*cdf0e10cSrcweir import com.sun.star.lang.XComponent; 42*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 43*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir /** 47*cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XFrameLoader</code> 48*cdf0e10cSrcweir * interface methods : 49*cdf0e10cSrcweir * <ul> 50*cdf0e10cSrcweir * <li><code> load()</code></li> 51*cdf0e10cSrcweir * <li><code> cancel()</code></li> 52*cdf0e10cSrcweir * </ul> <p> 53*cdf0e10cSrcweir * This test needs the following object relations : 54*cdf0e10cSrcweir * <ul> 55*cdf0e10cSrcweir * <li> <code>'FrameLoader.URL'</code> (of type <code>String</code>): 56*cdf0e10cSrcweir * an url or component to be loaded </li> 57*cdf0e10cSrcweir * <li> <code>'FrameLoader.Frame'</code> <b>(optional)</b> 58*cdf0e10cSrcweir * (of type <code>com.sun.star.frame.XFrame</code>): 59*cdf0e10cSrcweir * a target frame where component to be loaded. If this 60*cdf0e10cSrcweir * relation is ommited then a text document created and its 61*cdf0e10cSrcweir * frame is used. </li> 62*cdf0e10cSrcweir * <li> <code>'FrameLoader.args'</code> <b>(optional)</b> 63*cdf0e10cSrcweir * (of type <code>Object[]</code>): 64*cdf0e10cSrcweir * necessary arguuments for loading a component. If ommited 65*cdf0e10cSrcweir * then zero length array is passed as parameter</li> 66*cdf0e10cSrcweir * <ul> <p> 67*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 68*cdf0e10cSrcweir * @see com.sun.star.frame.XFrameLoader 69*cdf0e10cSrcweir */ 70*cdf0e10cSrcweir public class _XFrameLoader extends MultiMethodTest { 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir public XFrameLoader oObj = null; // oObj filled by MultiMethodTest 73*cdf0e10cSrcweir private String url = null ; 74*cdf0e10cSrcweir private XFrame frame = null ; 75*cdf0e10cSrcweir private PropertyValue[] args = new PropertyValue[0] ; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir /** 78*cdf0e10cSrcweir * Implemetation of load listener which geristers all it's calls. 79*cdf0e10cSrcweir */ 80*cdf0e10cSrcweir protected class TestListener implements XLoadEventListener { 81*cdf0e10cSrcweir public boolean finished = false ; 82*cdf0e10cSrcweir public boolean cancelled = false ; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir public void loadFinished(XFrameLoader l) { 85*cdf0e10cSrcweir finished = true ; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir public void loadCancelled(XFrameLoader l) { 88*cdf0e10cSrcweir cancelled = true ; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir public void disposing(EventObject e) {} 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir TestListener listener = new TestListener() ; 94*cdf0e10cSrcweir XComponent frameSup = null ; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir /** 97*cdf0e10cSrcweir * Retrieves all relations. If optional ones are not found 98*cdf0e10cSrcweir * creates their default values. <p> 99*cdf0e10cSrcweir * @throws StatusException If one of required relations not found. 100*cdf0e10cSrcweir */ 101*cdf0e10cSrcweir public void before() { 102*cdf0e10cSrcweir url = (String) tEnv.getObjRelation("FrameLoader.URL") ; 103*cdf0e10cSrcweir frame = (XFrame) tEnv.getObjRelation("FrameLoader.Frame") ; 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir if (frame == null) { 106*cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir try { 109*cdf0e10cSrcweir log.println( "creating a textdocument" ); 110*cdf0e10cSrcweir frameSup = SOF.createTextDoc( null ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir Object oDsk = ((XMultiServiceFactory)tParam.getMSF()) 113*cdf0e10cSrcweir .createInstance("com.sun.star.frame.Desktop") ; 114*cdf0e10cSrcweir XDesktop dsk = (XDesktop) 115*cdf0e10cSrcweir UnoRuntime.queryInterface(XDesktop.class, oDsk) ; 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir shortWait() ; 118*cdf0e10cSrcweir frame = dsk.getCurrentFrame() ; 119*cdf0e10cSrcweir } catch ( com.sun.star.uno.Exception e ) { 120*cdf0e10cSrcweir // Some exception occures.FAILED 121*cdf0e10cSrcweir e.printStackTrace( log ); 122*cdf0e10cSrcweir throw new StatusException( "Couldn't create a frame.", e ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir Object args = tEnv.getObjRelation("FrameLoader.args") ; 127*cdf0e10cSrcweir if (args != null) this.args = (PropertyValue[]) args ; 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir if (url == null /*|| frame == null*/) { 130*cdf0e10cSrcweir throw new StatusException 131*cdf0e10cSrcweir (Status.failed("Some relations not found")) ; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir private boolean loaded = false ; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir /** 138*cdf0e10cSrcweir * Firts <code>cancel</code> method test is called. 139*cdf0e10cSrcweir * If in that test loaing process was interrupted by 140*cdf0e10cSrcweir * <code>cancel</code> call then <code>load</code> test 141*cdf0e10cSrcweir * executes. It loads a component, waits some moment to 142*cdf0e10cSrcweir * listener have a chance to be called and then checks 143*cdf0e10cSrcweir * if the load listener was called. <p> 144*cdf0e10cSrcweir * Has <b>OK</b> status if <code>cancel</code> method test 145*cdf0e10cSrcweir * didn't interrupt loading and it was successfull, or 146*cdf0e10cSrcweir * if in this method it loads successfull and listener's 147*cdf0e10cSrcweir * <code>finished</code> method was called. 148*cdf0e10cSrcweir * The following method tests are to be executed before : 149*cdf0e10cSrcweir * <ul> 150*cdf0e10cSrcweir * <li> <code> cancel() </code> </li> 151*cdf0e10cSrcweir * </ul> 152*cdf0e10cSrcweir */ 153*cdf0e10cSrcweir public void _load() { 154*cdf0e10cSrcweir executeMethod("cancel()") ; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir if (!loaded) { 157*cdf0e10cSrcweir oObj.load(frame, url, args, listener) ; 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir shortWait(); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir loaded = listener.finished ; 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir tRes.tested("load()", loaded) ; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir /** 168*cdf0e10cSrcweir * Starts to load a component and then immediatly tries to 169*cdf0e10cSrcweir * cancel the process. <p> 170*cdf0e10cSrcweir * Has <b>OK</b> status if the process was cancelled or 171*cdf0e10cSrcweir * finished (appropriate listener methods were called). 172*cdf0e10cSrcweir */ 173*cdf0e10cSrcweir public void _cancel() { 174*cdf0e10cSrcweir boolean result = true ; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir oObj.load(frame, url, args, listener) ; 177*cdf0e10cSrcweir oObj.cancel() ; 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir shortWait(); 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if (listener.cancelled) { 182*cdf0e10cSrcweir log.println("Loading was canceled.") ; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir if (listener.finished) { 185*cdf0e10cSrcweir log.println("Loading was finished.") ; 186*cdf0e10cSrcweir loaded = true ; 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir if (!listener.cancelled && !listener.finished) { 189*cdf0e10cSrcweir log.println("Loading was not canceled and not finished") ; 190*cdf0e10cSrcweir result = false ; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir tRes.tested("cancel()", result) ; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir public void after() { 197*cdf0e10cSrcweir if (frameSup != null) frameSup.dispose() ; 198*cdf0e10cSrcweir frame.dispose(); 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir private void shortWait() { 202*cdf0e10cSrcweir try { 203*cdf0e10cSrcweir Thread.sleep(5000); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir catch (InterruptedException ex) { 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211