1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFramesSupplier.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.frame
.XFrame
;
37 import com
.sun
.star
.frame
.XFramesSupplier
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
42 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
45 * <li><code> getActiveFrame() </code></li>
46 * <li><code> getFrames() </code></li>
47 * <li><code> setActiveFrame() </code></li>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.frame.XFramesSupplier
52 public class _XFramesSupplier
extends MultiMethodTest
{
53 public static XFramesSupplier oObj
= null;
54 protected XIndexAccess frames
= null ;
55 protected XFrame active
= null ;
56 protected int activeIdx
= -1 ;
59 * Test calls the method, then result is checked. Also active frame index
60 * is saved in activeIdx variable.<p>
62 * Has <b> OK </b> status if the method does not return null and the object
63 * contains returned frame. Or if no frames available and the method
66 * The following method tests are to be completed successfully before :
68 * <li> <code> getFrames() </code> : obtains frames from the object </li>
71 public void _getActiveFrame() {
72 boolean result
= true ;
74 requiredMethod("getFrames()") ;
75 active
= oObj
.getActiveFrame() ;
77 // if no child frames then no active frame could be
78 result
= oObj
.getFrames().getCount() == 0;
79 log
.println("getActiveFrame() returned null") ;
82 boolean hasActiveFrame
= false ;
83 for (int i
= 0; i
< frames
.getCount(); i
++) {
88 fr
= (XFrame
) AnyConverter
.toObject(
89 new Type(XFrame
.class),frames
.getByIndex(i
));
90 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
91 log
.println("Can't convert any");
93 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
94 log
.println("Exception occured while calling getByIndex() method :") ;
95 e
.printStackTrace(log
) ;
97 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
98 log
.println("Exception occured while calling getByIndex() method :") ;
99 e
.printStackTrace(log
) ;
102 if (active
.equals(fr
)) {
103 hasActiveFrame
= true ;
107 if (!hasActiveFrame
) {
108 log
.println("getActiveFrame() isn't contained " +
109 "in getFrames() collection") ;
114 tRes
.tested("getActiveFrame()", result
) ;
118 * Test calls the method, then result is checked. <p>
119 * Has <b> OK </b> status if the method does not return null,
120 * number of returned frames is not zero and each of them is not null too.
122 public void _getFrames() {
123 boolean result
= true ;
126 frames
= oObj
.getFrames() ;
127 if (frames
!= null) {
128 cnt
= frames
.getCount() ;
129 // if (cnt == 0) result = false ;
130 log
.println("There are " + cnt
+ " frames.") ;
132 log
.println("getFrames() returned null !!!") ;
135 for (int i
= 0; i
< cnt
; i
++) {
137 if (frames
.getByIndex(i
) == null) {
138 log
.println("Frame(" + i
+ ") == null") ;
141 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
142 log
.println("Exception occured while calling getByIndex() method :") ;
143 e
.printStackTrace(log
) ;
145 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
146 log
.println("Exception occured while calling getByIndex() method :") ;
147 e
.printStackTrace(log
) ;
152 tRes
.tested("getFrames()", result
) ;
156 * After selecting frame to be activated, test calls the method. <p>
158 * Has <b> OK </b> status if set and gotten active frames are equal.<p>
160 * The following method tests are to be completed successfully before :
162 * <li> <code> getActiveFrame() </code> : gets active frame </li>
165 public void _setActiveFrame() {
166 boolean result
= true ;
167 XFrame sFrame
= null ;
169 requiredMethod("getActiveFrame()") ;
170 if (frames
.getCount() > 1) {
174 sFrame
= (XFrame
) AnyConverter
.toObject(
175 new Type(XFrame
.class),frames
.getByIndex(0));
176 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
177 log
.println("Can't convert any");
181 sFrame
= (XFrame
) AnyConverter
.toObject(
182 new Type(XFrame
.class),frames
.getByIndex(1));
183 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
184 log
.println("Can't convert any");
186 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
187 log
.println("Exception occured while calling getByIndex() method :") ;
188 e
.printStackTrace(log
) ;
190 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
191 log
.println("Exception occured while calling getByIndex() method :") ;
192 e
.printStackTrace(log
) ;
195 } else if (frames
.getCount() > 0) {
201 oObj
.setActiveFrame(sFrame
) ;
202 XFrame gFrame
= oObj
.getActiveFrame() ;
203 if (!(gFrame
== null && sFrame
== null
204 || sFrame
.equals(gFrame
))) {
206 log
.println("Active frame set is not equal frame get: FAILED");
210 tRes
.tested("setActiveFrame()", result
) ;
213 } // finished class _XFramesSupplier