Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XFramesSupplier.java
blob64997de99028b069242292cd66c80458d2bbcc17
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 boolean result = true ;
153 XFrame sFrame = null ;
155 requiredMethod("getActiveFrame()") ;
156 if (frames.getCount() > 1) {
157 try {
158 if (activeIdx != 0)
159 try {
160 sFrame = (XFrame) AnyConverter.toObject(
161 new Type(XFrame.class),frames.getByIndex(0));
162 } catch (com.sun.star.lang.IllegalArgumentException iae) {
163 log.println("Can't convert any");
165 else
166 try {
167 sFrame = (XFrame) AnyConverter.toObject(
168 new Type(XFrame.class),frames.getByIndex(1));
169 } catch (com.sun.star.lang.IllegalArgumentException iae) {
170 log.println("Can't convert any");
172 } catch (com.sun.star.lang.WrappedTargetException e) {
173 log.println("Exception occurred while calling getByIndex() method :") ;
174 e.printStackTrace(log) ;
175 return;
176 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
177 log.println("Exception occurred while calling getByIndex() method :") ;
178 e.printStackTrace(log) ;
179 return;
181 } else if (frames.getCount() > 0) {
182 sFrame = active ;
185 oObj.setActiveFrame(sFrame) ;
186 XFrame gFrame = oObj.getActiveFrame() ;
187 if (!(gFrame == null && sFrame == null
188 || sFrame.equals(gFrame))) {
190 log.println("Active frame set is not equal frame get: FAILED");
191 result = false ;
194 tRes.tested("setActiveFrame()", result) ;
197 } // finished class _XFramesSupplier