Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFramesSupplier.java
blobb7fb16815e1ada83b5084125d1a9b4cc14c58a0e
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 ************************************************************************/
28 package ifc.frame;
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;
38 /**
39 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
40 * interface methods:
41 * <ul>
42 * <li><code> getActiveFrame() </code></li>
43 * <li><code> getFrames() </code></li>
44 * <li><code> setActiveFrame() </code></li>
45 * </ul><p>
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 ;
55 /**
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
61 * returns null.<p>
63 * The following method tests are to be completed successfully before :
64 * <ul>
65 * <li> <code> getFrames() </code> : obtains frames from the object </li>
66 * </ul>
68 public void _getActiveFrame() {
69 boolean result = true ;
71 requiredMethod("getFrames()") ;
72 active = oObj.getActiveFrame() ;
73 if (active == null) {
74 // if no child frames then no active frame could be
75 result = oObj.getFrames().getCount() == 0;
76 log.println("getActiveFrame() returned null") ;
78 else {
79 boolean hasActiveFrame = false ;
80 for (int i = 0; i < frames.getCount(); i++) {
81 XFrame fr = null ;
82 try {
83 fr = null;
84 try {
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) ;
93 return;
94 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
95 log.println("Exception occurred while calling getByIndex() method :") ;
96 e.printStackTrace(log) ;
97 return;
99 if (active.equals(fr)) {
100 hasActiveFrame = true ;
101 activeIdx = i ;
104 if (!hasActiveFrame) {
105 log.println("getActiveFrame() isn't contained " +
106 "in getFrames() collection") ;
107 result = false ;
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 ;
121 int cnt = 0;
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.") ;
128 } else {
129 log.println("getFrames() returned null !!!") ;
130 result = false ;
132 for (int i = 0; i < cnt; i++) {
133 try {
134 if (frames.getByIndex(i) == null) {
135 log.println("Frame(" + i + ") == null") ;
136 result = false ;
138 } catch (com.sun.star.lang.WrappedTargetException e) {
139 log.println("Exception occurred while calling getByIndex() method :") ;
140 e.printStackTrace(log) ;
141 return;
142 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
143 log.println("Exception occurred while calling getByIndex() method :") ;
144 e.printStackTrace(log) ;
145 return;
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 :
158 * <ul>
159 * <li> <code> getActiveFrame() </code> : gets active frame </li>
160 * </ul>
162 public void _setActiveFrame() {
163 boolean result = true ;
164 XFrame sFrame = null ;
166 requiredMethod("getActiveFrame()") ;
167 if (frames.getCount() > 1) {
168 try {
169 if (activeIdx != 0)
170 try {
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");
176 else
177 try {
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) ;
186 return;
187 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
188 log.println("Exception occurred while calling getByIndex() method :") ;
189 e.printStackTrace(log) ;
190 return;
192 } else if (frames.getCount() > 0) {
193 sFrame = active ;
194 } else {
195 sFrame = null;
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");
204 result = false ;
207 tRes.tested("setActiveFrame()", result) ;
210 } // finished class _XFramesSupplier