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 32*cdf0e10cSrcweir import com.sun.star.container.XIndexAccess; 33*cdf0e10cSrcweir import com.sun.star.frame.XFrame; 34*cdf0e10cSrcweir import com.sun.star.frame.XFramesSupplier; 35*cdf0e10cSrcweir import com.sun.star.uno.AnyConverter; 36*cdf0e10cSrcweir import com.sun.star.uno.Type; 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir /** 39*cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XFramesSupplier</code> 40*cdf0e10cSrcweir * interface methods: 41*cdf0e10cSrcweir * <ul> 42*cdf0e10cSrcweir * <li><code> getActiveFrame() </code></li> 43*cdf0e10cSrcweir * <li><code> getFrames() </code></li> 44*cdf0e10cSrcweir * <li><code> setActiveFrame() </code></li> 45*cdf0e10cSrcweir * </ul><p> 46*cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p> 47*cdf0e10cSrcweir * @see com.sun.star.frame.XFramesSupplier 48*cdf0e10cSrcweir */ 49*cdf0e10cSrcweir public class _XFramesSupplier extends MultiMethodTest { 50*cdf0e10cSrcweir public static XFramesSupplier oObj = null; 51*cdf0e10cSrcweir protected XIndexAccess frames = null ; 52*cdf0e10cSrcweir protected XFrame active = null ; 53*cdf0e10cSrcweir protected int activeIdx = -1 ; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir /** 56*cdf0e10cSrcweir * Test calls the method, then result is checked. Also active frame index 57*cdf0e10cSrcweir * is saved in activeIdx variable.<p> 58*cdf0e10cSrcweir * 59*cdf0e10cSrcweir * Has <b> OK </b> status if the method does not return null and the object 60*cdf0e10cSrcweir * contains returned frame. Or if no frames available and the method 61*cdf0e10cSrcweir * returns null.<p> 62*cdf0e10cSrcweir * 63*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 64*cdf0e10cSrcweir * <ul> 65*cdf0e10cSrcweir * <li> <code> getFrames() </code> : obtains frames from the object </li> 66*cdf0e10cSrcweir * </ul> 67*cdf0e10cSrcweir */ 68*cdf0e10cSrcweir public void _getActiveFrame() { 69*cdf0e10cSrcweir boolean result = true ; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir requiredMethod("getFrames()") ; 72*cdf0e10cSrcweir active = oObj.getActiveFrame() ; 73*cdf0e10cSrcweir if (active == null) { 74*cdf0e10cSrcweir // if no child frames then no active frame could be 75*cdf0e10cSrcweir result = oObj.getFrames().getCount() == 0; 76*cdf0e10cSrcweir log.println("getActiveFrame() returned null") ; 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir else { 79*cdf0e10cSrcweir boolean hasActiveFrame = false ; 80*cdf0e10cSrcweir for (int i = 0; i < frames.getCount(); i++) { 81*cdf0e10cSrcweir XFrame fr = null ; 82*cdf0e10cSrcweir try { 83*cdf0e10cSrcweir fr = null; 84*cdf0e10cSrcweir try { 85*cdf0e10cSrcweir fr = (XFrame) AnyConverter.toObject( 86*cdf0e10cSrcweir new Type(XFrame.class),frames.getByIndex(i)); 87*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 88*cdf0e10cSrcweir log.println("Can't convert any"); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 91*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 92*cdf0e10cSrcweir e.printStackTrace(log) ; 93*cdf0e10cSrcweir return; 94*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 95*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 96*cdf0e10cSrcweir e.printStackTrace(log) ; 97*cdf0e10cSrcweir return; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir if (active.equals(fr)) { 100*cdf0e10cSrcweir hasActiveFrame = true ; 101*cdf0e10cSrcweir activeIdx = i ; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir if (!hasActiveFrame) { 105*cdf0e10cSrcweir log.println("getActiveFrame() isn't contained " + 106*cdf0e10cSrcweir "in getFrames() collection") ; 107*cdf0e10cSrcweir result = false ; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir tRes.tested("getActiveFrame()", result) ; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir /** 115*cdf0e10cSrcweir * Test calls the method, then result is checked. <p> 116*cdf0e10cSrcweir * Has <b> OK </b> status if the method does not return null, 117*cdf0e10cSrcweir * number of returned frames is not zero and each of them is not null too. 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir public void _getFrames() { 120*cdf0e10cSrcweir boolean result = true ; 121*cdf0e10cSrcweir int cnt = 0; 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir frames = oObj.getFrames() ; 124*cdf0e10cSrcweir if (frames != null) { 125*cdf0e10cSrcweir cnt = frames.getCount() ; 126*cdf0e10cSrcweir // if (cnt == 0) result = false ; 127*cdf0e10cSrcweir log.println("There are " + cnt + " frames.") ; 128*cdf0e10cSrcweir } else { 129*cdf0e10cSrcweir log.println("getFrames() returned null !!!") ; 130*cdf0e10cSrcweir result = false ; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir for (int i = 0; i < cnt; i++) { 133*cdf0e10cSrcweir try { 134*cdf0e10cSrcweir if (frames.getByIndex(i) == null) { 135*cdf0e10cSrcweir log.println("Frame(" + i + ") == null") ; 136*cdf0e10cSrcweir result = false ; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 139*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 140*cdf0e10cSrcweir e.printStackTrace(log) ; 141*cdf0e10cSrcweir return; 142*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 143*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 144*cdf0e10cSrcweir e.printStackTrace(log) ; 145*cdf0e10cSrcweir return; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir tRes.tested("getFrames()", result) ; 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir /** 153*cdf0e10cSrcweir * After selecting frame to be activated, test calls the method. <p> 154*cdf0e10cSrcweir * 155*cdf0e10cSrcweir * Has <b> OK </b> status if set and gotten active frames are equal.<p> 156*cdf0e10cSrcweir * 157*cdf0e10cSrcweir * The following method tests are to be completed successfully before : 158*cdf0e10cSrcweir * <ul> 159*cdf0e10cSrcweir * <li> <code> getActiveFrame() </code> : gets active frame </li> 160*cdf0e10cSrcweir * </ul> 161*cdf0e10cSrcweir */ 162*cdf0e10cSrcweir public void _setActiveFrame() { 163*cdf0e10cSrcweir boolean result = true ; 164*cdf0e10cSrcweir XFrame sFrame = null ; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir requiredMethod("getActiveFrame()") ; 167*cdf0e10cSrcweir if (frames.getCount() > 1) { 168*cdf0e10cSrcweir try { 169*cdf0e10cSrcweir if (activeIdx != 0) 170*cdf0e10cSrcweir try { 171*cdf0e10cSrcweir sFrame = (XFrame) AnyConverter.toObject( 172*cdf0e10cSrcweir new Type(XFrame.class),frames.getByIndex(0)); 173*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 174*cdf0e10cSrcweir log.println("Can't convert any"); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir else 177*cdf0e10cSrcweir try { 178*cdf0e10cSrcweir sFrame = (XFrame) AnyConverter.toObject( 179*cdf0e10cSrcweir new Type(XFrame.class),frames.getByIndex(1)); 180*cdf0e10cSrcweir } catch (com.sun.star.lang.IllegalArgumentException iae) { 181*cdf0e10cSrcweir log.println("Can't convert any"); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } catch (com.sun.star.lang.WrappedTargetException e) { 184*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 185*cdf0e10cSrcweir e.printStackTrace(log) ; 186*cdf0e10cSrcweir return; 187*cdf0e10cSrcweir } catch (com.sun.star.lang.IndexOutOfBoundsException e) { 188*cdf0e10cSrcweir log.println("Exception occured while calling getByIndex() method :") ; 189*cdf0e10cSrcweir e.printStackTrace(log) ; 190*cdf0e10cSrcweir return; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } else if (frames.getCount() > 0) { 193*cdf0e10cSrcweir sFrame = active ; 194*cdf0e10cSrcweir } else { 195*cdf0e10cSrcweir sFrame = null; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir oObj.setActiveFrame(sFrame) ; 199*cdf0e10cSrcweir XFrame gFrame = oObj.getActiveFrame() ; 200*cdf0e10cSrcweir if (!(gFrame == null && sFrame == null 201*cdf0e10cSrcweir || sFrame.equals(gFrame))) { 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir log.println("Active frame set is not equal frame get: FAILED"); 204*cdf0e10cSrcweir result = false ; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir tRes.tested("setActiveFrame()", result) ; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir } // finished class _XFramesSupplier 211*cdf0e10cSrcweir 212