Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / frame / _XFramesSupplier.java
blobd463a5f53a096148e283a7bd60fa8ba78ef77447
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XFramesSupplier.java,v $
10 * $Revision: 1.5 $
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 ************************************************************************/
31 package ifc.frame;
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;
41 /**
42 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
43 * interface methods:
44 * <ul>
45 * <li><code> getActiveFrame() </code></li>
46 * <li><code> getFrames() </code></li>
47 * <li><code> setActiveFrame() </code></li>
48 * </ul><p>
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 ;
58 /**
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
64 * returns null.<p>
66 * The following method tests are to be completed successfully before :
67 * <ul>
68 * <li> <code> getFrames() </code> : obtains frames from the object </li>
69 * </ul>
71 public void _getActiveFrame() {
72 boolean result = true ;
74 requiredMethod("getFrames()") ;
75 active = oObj.getActiveFrame() ;
76 if (active == null) {
77 // if no child frames then no active frame could be
78 result = oObj.getFrames().getCount() == 0;
79 log.println("getActiveFrame() returned null") ;
81 else {
82 boolean hasActiveFrame = false ;
83 for (int i = 0; i < frames.getCount(); i++) {
84 XFrame fr = null ;
85 try {
86 fr = null;
87 try {
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) ;
96 return;
97 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
98 log.println("Exception occured while calling getByIndex() method :") ;
99 e.printStackTrace(log) ;
100 return;
102 if (active.equals(fr)) {
103 hasActiveFrame = true ;
104 activeIdx = i ;
107 if (!hasActiveFrame) {
108 log.println("getActiveFrame() isn't contained " +
109 "in getFrames() collection") ;
110 result = false ;
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 ;
124 int cnt = 0;
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.") ;
131 } else {
132 log.println("getFrames() returned null !!!") ;
133 result = false ;
135 for (int i = 0; i < cnt; i++) {
136 try {
137 if (frames.getByIndex(i) == null) {
138 log.println("Frame(" + i + ") == null") ;
139 result = false ;
141 } catch (com.sun.star.lang.WrappedTargetException e) {
142 log.println("Exception occured while calling getByIndex() method :") ;
143 e.printStackTrace(log) ;
144 return;
145 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
146 log.println("Exception occured while calling getByIndex() method :") ;
147 e.printStackTrace(log) ;
148 return;
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 :
161 * <ul>
162 * <li> <code> getActiveFrame() </code> : gets active frame </li>
163 * </ul>
165 public void _setActiveFrame() {
166 boolean result = true ;
167 XFrame sFrame = null ;
169 requiredMethod("getActiveFrame()") ;
170 if (frames.getCount() > 1) {
171 try {
172 if (activeIdx != 0)
173 try {
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");
179 else
180 try {
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) ;
189 return;
190 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
191 log.println("Exception occured while calling getByIndex() method :") ;
192 e.printStackTrace(log) ;
193 return;
195 } else if (frames.getCount() > 0) {
196 sFrame = active ;
197 } else {
198 sFrame = null;
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");
207 result = false ;
210 tRes.tested("setActiveFrame()", result) ;
213 } // finished class _XFramesSupplier