1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 import lib
.MultiMethodTest
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.frame
.XFrame
;
34 import com
.sun
.star
.frame
.XFramesSupplier
;
35 import com
.sun
.star
.uno
.AnyConverter
;
36 import com
.sun
.star
.uno
.Type
;
39 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
42 * <li><code> getActiveFrame() </code></li>
43 * <li><code> getFrames() </code></li>
44 * <li><code> setActiveFrame() </code></li>
46 * Test is <b> NOT </b> multithread compilant. <p>
47 * @see com.sun.star.frame.XFramesSupplier
49 public class _XFramesSupplier
extends MultiMethodTest
{
50 public static XFramesSupplier oObj
= null;
51 protected XIndexAccess frames
= null ;
52 protected XFrame active
= null ;
53 protected int activeIdx
= -1 ;
56 * Test calls the method, then result is checked. Also active frame index
57 * is saved in activeIdx variable.<p>
59 * Has <b> OK </b> status if the method does not return null and the object
60 * contains returned frame. Or if no frames available and the method
63 * The following method tests are to be completed successfully before :
65 * <li> <code> getFrames() </code> : obtains frames from the object </li>
68 public void _getActiveFrame() {
69 boolean result
= true ;
71 requiredMethod("getFrames()") ;
72 active
= oObj
.getActiveFrame() ;
74 // if no child frames then no active frame could be
75 result
= oObj
.getFrames().getCount() == 0;
76 log
.println("getActiveFrame() returned null") ;
79 boolean hasActiveFrame
= false ;
80 for (int i
= 0; i
< frames
.getCount(); i
++) {
85 fr
= (XFrame
) AnyConverter
.toObject(
86 new Type(XFrame
.class),frames
.getByIndex(i
));
87 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
88 log
.println("Can't convert any");
90 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
91 log
.println("Exception occurred while calling getByIndex() method :") ;
92 e
.printStackTrace(log
) ;
94 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
95 log
.println("Exception occurred while calling getByIndex() method :") ;
96 e
.printStackTrace(log
) ;
99 if (active
.equals(fr
)) {
100 hasActiveFrame
= true ;
104 if (!hasActiveFrame
) {
105 log
.println("getActiveFrame() isn't contained " +
106 "in getFrames() collection") ;
111 tRes
.tested("getActiveFrame()", result
) ;
115 * Test calls the method, then result is checked. <p>
116 * Has <b> OK </b> status if the method does not return null,
117 * number of returned frames is not zero and each of them is not null too.
119 public void _getFrames() {
120 boolean result
= true ;
123 frames
= oObj
.getFrames() ;
124 if (frames
!= null) {
125 cnt
= frames
.getCount() ;
126 // if (cnt == 0) result = false ;
127 log
.println("There are " + cnt
+ " frames.") ;
129 log
.println("getFrames() returned null !!!") ;
132 for (int i
= 0; i
< cnt
; i
++) {
134 if (frames
.getByIndex(i
) == null) {
135 log
.println("Frame(" + i
+ ") == null") ;
138 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
139 log
.println("Exception occurred while calling getByIndex() method :") ;
140 e
.printStackTrace(log
) ;
142 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
143 log
.println("Exception occurred while calling getByIndex() method :") ;
144 e
.printStackTrace(log
) ;
149 tRes
.tested("getFrames()", result
) ;
153 * After selecting frame to be activated, test calls the method. <p>
155 * Has <b> OK </b> status if set and gotten active frames are equal.<p>
157 * The following method tests are to be completed successfully before :
159 * <li> <code> getActiveFrame() </code> : gets active frame </li>
162 public void _setActiveFrame() {
163 boolean result
= true ;
164 XFrame sFrame
= null ;
166 requiredMethod("getActiveFrame()") ;
167 if (frames
.getCount() > 1) {
171 sFrame
= (XFrame
) AnyConverter
.toObject(
172 new Type(XFrame
.class),frames
.getByIndex(0));
173 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
174 log
.println("Can't convert any");
178 sFrame
= (XFrame
) AnyConverter
.toObject(
179 new Type(XFrame
.class),frames
.getByIndex(1));
180 } catch (com
.sun
.star
.lang
.IllegalArgumentException iae
) {
181 log
.println("Can't convert any");
183 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
184 log
.println("Exception occurred while calling getByIndex() method :") ;
185 e
.printStackTrace(log
) ;
187 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
188 log
.println("Exception occurred while calling getByIndex() method :") ;
189 e
.printStackTrace(log
) ;
192 } else if (frames
.getCount() > 0) {
198 oObj
.setActiveFrame(sFrame
) ;
199 XFrame gFrame
= oObj
.getActiveFrame() ;
200 if (!(gFrame
== null && sFrame
== null
201 || sFrame
.equals(gFrame
))) {
203 log
.println("Active frame set is not equal frame get: FAILED");
207 tRes
.tested("setActiveFrame()", result
) ;
210 } // finished class _XFramesSupplier