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 .
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
;
30 * Testing <code>com.sun.star.frame.XFramesSupplier</code>
33 * <li><code> getActiveFrame() </code></li>
34 * <li><code> getFrames() </code></li>
35 * <li><code> setActiveFrame() </code></li>
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 ;
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
54 * The following method tests are to be completed successfully before :
56 * <li> <code> getFrames() </code> : obtains frames from the object </li>
59 public void _getActiveFrame() {
60 boolean result
= true ;
62 requiredMethod("getFrames()") ;
63 active
= oObj
.getActiveFrame() ;
65 // if no child frames then no active frame could be
66 result
= oObj
.getFrames().getCount() == 0;
67 log
.println("getActiveFrame() returned null") ;
70 boolean hasActiveFrame
= false ;
71 for (int i
= 0; i
< frames
.getCount(); i
++) {
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
) ;
85 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
86 log
.println("Exception occurred while calling getByIndex() method :") ;
87 e
.printStackTrace(log
) ;
90 if (active
.equals(fr
)) {
91 hasActiveFrame
= true ;
95 if (!hasActiveFrame
) {
96 log
.println("getActiveFrame() isn't contained " +
97 "in getFrames() collection") ;
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 ;
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.") ;
120 log
.println("getFrames() returned null !!!") ;
123 for (int i
= 0; i
< cnt
; i
++) {
125 if (frames
.getByIndex(i
) == null) {
126 log
.println("Frame(" + i
+ ") == null") ;
129 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
130 log
.println("Exception occurred while calling getByIndex() method :") ;
131 e
.printStackTrace(log
) ;
133 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
134 log
.println("Exception occurred while calling getByIndex() method :") ;
135 e
.printStackTrace(log
) ;
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 :
150 * <li> <code> getActiveFrame() </code> : gets active frame </li>
153 public void _setActiveFrame() {
154 boolean result
= true ;
155 XFrame sFrame
= null ;
157 requiredMethod("getActiveFrame()") ;
158 if (frames
.getCount() > 1) {
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");
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
) ;
178 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
179 log
.println("Exception occurred while calling getByIndex() method :") ;
180 e
.printStackTrace(log
) ;
183 } else if (frames
.getCount() > 0) {
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");
198 tRes
.tested("setActiveFrame()", result
) ;
201 } // finished class _XFramesSupplier