Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFramesSupplier.java
bloba54718b704c42353be58e3b549fbbbeaf0571b1e
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 compliant. <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 try {
75 fr = (XFrame) AnyConverter.toObject(
76 new Type(XFrame.class),frames.getByIndex(i));
77 } catch (com.sun.star.lang.IllegalArgumentException iae) {
78 log.println("Can't convert any");
80 } catch (com.sun.star.lang.WrappedTargetException e) {
81 log.println("Exception occurred while calling getByIndex() method :") ;
82 e.printStackTrace(log) ;
83 return;
84 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
85 log.println("Exception occurred while calling getByIndex() method :") ;
86 e.printStackTrace(log) ;
87 return;
89 if (active.equals(fr)) {
90 hasActiveFrame = true ;
91 activeIdx = i ;
94 if (!hasActiveFrame) {
95 log.println("getActiveFrame() isn't contained " +
96 "in getFrames() collection") ;
97 result = false ;
101 tRes.tested("getActiveFrame()", result) ;
105 * Test calls the method, then result is checked. <p>
106 * Has <b> OK </b> status if the method does not return null,
107 * number of returned frames is not zero and each of them is not null too.
109 public void _getFrames() {
110 boolean result = true ;
111 int cnt = 0;
113 frames = oObj.getFrames() ;
114 if (frames != null) {
115 cnt = frames.getCount() ;
116 log.println("There are " + cnt + " frames.") ;
117 } else {
118 log.println("getFrames() returned null !!!") ;
119 result = false ;
121 for (int i = 0; i < cnt; i++) {
122 try {
123 if (frames.getByIndex(i) == null) {
124 log.println("Frame(" + i + ") == null") ;
125 result = false ;
127 } catch (com.sun.star.lang.WrappedTargetException e) {
128 log.println("Exception occurred while calling getByIndex() method :") ;
129 e.printStackTrace(log) ;
130 return;
131 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
132 log.println("Exception occurred while calling getByIndex() method :") ;
133 e.printStackTrace(log) ;
134 return;
138 tRes.tested("getFrames()", result) ;
142 * After selecting frame to be activated, test calls the method. <p>
144 * Has <b> OK </b> status if set and gotten active frames are equal.<p>
146 * The following method tests are to be completed successfully before :
147 * <ul>
148 * <li> <code> getActiveFrame() </code> : gets active frame </li>
149 * </ul>
151 public void _setActiveFrame() {
152 XFrame sFrame = null ;
154 requiredMethod("getActiveFrame()") ;
155 if (frames.getCount() > 1) {
156 try {
157 if (activeIdx != 0)
158 try {
159 sFrame = (XFrame) AnyConverter.toObject(
160 new Type(XFrame.class),frames.getByIndex(0));
161 } catch (com.sun.star.lang.IllegalArgumentException iae) {
162 log.println("Can't convert any");
164 else
165 try {
166 sFrame = (XFrame) AnyConverter.toObject(
167 new Type(XFrame.class),frames.getByIndex(1));
168 } catch (com.sun.star.lang.IllegalArgumentException iae) {
169 log.println("Can't convert any");
171 } catch (com.sun.star.lang.WrappedTargetException e) {
172 log.println("Exception occurred while calling getByIndex() method :") ;
173 e.printStackTrace(log) ;
174 return;
175 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
176 log.println("Exception occurred while calling getByIndex() method :") ;
177 e.printStackTrace(log) ;
178 return;
180 } else if (frames.getCount() > 0) {
181 sFrame = active ;
184 oObj.setActiveFrame(sFrame) ;
185 XFrame gFrame = oObj.getActiveFrame() ;
187 boolean result;
188 if (gFrame == null && sFrame == null)
189 result = true;
190 else if (gFrame != null && sFrame != null)
191 result = sFrame.equals(gFrame);
192 else
193 result = false;
195 if (!result) {
196 log.println("Active frame set is not equal frame get: FAILED");
197 result = false ;
200 tRes.tested("setActiveFrame()", result) ;
203 } // finished class _XFramesSupplier