bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFramesSupplier.java
blob56c336b45a0e177037bceff2d961d0c0d3f27c61
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.frame;
21 import lib.MultiMethodTest;
23 import com.sun.star.container.XIndexAccess;
24 import com.sun.star.frame.XFrame;
25 import com.sun.star.frame.XFramesSupplier;
26 import com.sun.star.uno.AnyConverter;
27 import com.sun.star.uno.Type;
29 /**
30 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
31 * interface methods:
32 * <ul>
33 * <li><code> getActiveFrame() </code></li>
34 * <li><code> getFrames() </code></li>
35 * <li><code> setActiveFrame() </code></li>
36 * </ul><p>
37 * Test is <b> NOT </b> multithread compilant. <p>
38 * @see com.sun.star.frame.XFramesSupplier
40 public class _XFramesSupplier extends MultiMethodTest {
41 public static XFramesSupplier oObj = null;
42 protected XIndexAccess frames = null ;
43 protected XFrame active = null ;
44 protected int activeIdx = -1 ;
46 /**
47 * Test calls the method, then result is checked. Also active frame index
48 * is saved in activeIdx variable.<p>
50 * Has <b> OK </b> status if the method does not return null and the object
51 * contains returned frame. Or if no frames available and the method
52 * returns null.<p>
54 * The following method tests are to be completed successfully before :
55 * <ul>
56 * <li> <code> getFrames() </code> : obtains frames from the object </li>
57 * </ul>
59 public void _getActiveFrame() {
60 boolean result = true ;
62 requiredMethod("getFrames()") ;
63 active = oObj.getActiveFrame() ;
64 if (active == null) {
65 // if no child frames then no active frame could be
66 result = oObj.getFrames().getCount() == 0;
67 log.println("getActiveFrame() returned null") ;
69 else {
70 boolean hasActiveFrame = false ;
71 for (int i = 0; i < frames.getCount(); i++) {
72 XFrame fr = null ;
73 try {
74 fr = null;
75 try {
76 fr = (XFrame) AnyConverter.toObject(
77 new Type(XFrame.class),frames.getByIndex(i));
78 } catch (com.sun.star.lang.IllegalArgumentException iae) {
79 log.println("Can't convert any");
81 } catch (com.sun.star.lang.WrappedTargetException e) {
82 log.println("Exception occurred while calling getByIndex() method :") ;
83 e.printStackTrace(log) ;
84 return;
85 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
86 log.println("Exception occurred while calling getByIndex() method :") ;
87 e.printStackTrace(log) ;
88 return;
90 if (active.equals(fr)) {
91 hasActiveFrame = true ;
92 activeIdx = i ;
95 if (!hasActiveFrame) {
96 log.println("getActiveFrame() isn't contained " +
97 "in getFrames() collection") ;
98 result = false ;
102 tRes.tested("getActiveFrame()", result) ;
106 * Test calls the method, then result is checked. <p>
107 * Has <b> OK </b> status if the method does not return null,
108 * number of returned frames is not zero and each of them is not null too.
110 public void _getFrames() {
111 boolean result = true ;
112 int cnt = 0;
114 frames = oObj.getFrames() ;
115 if (frames != null) {
116 cnt = frames.getCount() ;
117 // if (cnt == 0) result = false ;
118 log.println("There are " + cnt + " frames.") ;
119 } else {
120 log.println("getFrames() returned null !!!") ;
121 result = false ;
123 for (int i = 0; i < cnt; i++) {
124 try {
125 if (frames.getByIndex(i) == null) {
126 log.println("Frame(" + i + ") == null") ;
127 result = false ;
129 } catch (com.sun.star.lang.WrappedTargetException e) {
130 log.println("Exception occurred while calling getByIndex() method :") ;
131 e.printStackTrace(log) ;
132 return;
133 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
134 log.println("Exception occurred while calling getByIndex() method :") ;
135 e.printStackTrace(log) ;
136 return;
140 tRes.tested("getFrames()", result) ;
144 * After selecting frame to be activated, test calls the method. <p>
146 * Has <b> OK </b> status if set and gotten active frames are equal.<p>
148 * The following method tests are to be completed successfully before :
149 * <ul>
150 * <li> <code> getActiveFrame() </code> : gets active frame </li>
151 * </ul>
153 public void _setActiveFrame() {
154 boolean result = true ;
155 XFrame sFrame = null ;
157 requiredMethod("getActiveFrame()") ;
158 if (frames.getCount() > 1) {
159 try {
160 if (activeIdx != 0)
161 try {
162 sFrame = (XFrame) AnyConverter.toObject(
163 new Type(XFrame.class),frames.getByIndex(0));
164 } catch (com.sun.star.lang.IllegalArgumentException iae) {
165 log.println("Can't convert any");
167 else
168 try {
169 sFrame = (XFrame) AnyConverter.toObject(
170 new Type(XFrame.class),frames.getByIndex(1));
171 } catch (com.sun.star.lang.IllegalArgumentException iae) {
172 log.println("Can't convert any");
174 } catch (com.sun.star.lang.WrappedTargetException e) {
175 log.println("Exception occurred while calling getByIndex() method :") ;
176 e.printStackTrace(log) ;
177 return;
178 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
179 log.println("Exception occurred while calling getByIndex() method :") ;
180 e.printStackTrace(log) ;
181 return;
183 } else if (frames.getCount() > 0) {
184 sFrame = active ;
185 } else {
186 sFrame = null;
189 oObj.setActiveFrame(sFrame) ;
190 XFrame gFrame = oObj.getActiveFrame() ;
191 if (!(gFrame == null && sFrame == null
192 || sFrame.equals(gFrame))) {
194 log.println("Active frame set is not equal frame get: FAILED");
195 result = false ;
198 tRes.tested("setActiveFrame()", result) ;
201 } // finished class _XFramesSupplier