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 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 ;
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
++) {
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
) ;
84 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
85 log
.println("Exception occurred while calling getByIndex() method :") ;
86 e
.printStackTrace(log
) ;
89 if (active
.equals(fr
)) {
90 hasActiveFrame
= true ;
94 if (!hasActiveFrame
) {
95 log
.println("getActiveFrame() isn't contained " +
96 "in getFrames() collection") ;
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 ;
113 frames
= oObj
.getFrames() ;
114 if (frames
!= null) {
115 cnt
= frames
.getCount() ;
116 log
.println("There are " + cnt
+ " frames.") ;
118 log
.println("getFrames() returned null !!!") ;
121 for (int i
= 0; i
< cnt
; i
++) {
123 if (frames
.getByIndex(i
) == null) {
124 log
.println("Frame(" + i
+ ") == null") ;
127 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
128 log
.println("Exception occurred while calling getByIndex() method :") ;
129 e
.printStackTrace(log
) ;
131 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
132 log
.println("Exception occurred while calling getByIndex() method :") ;
133 e
.printStackTrace(log
) ;
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 :
148 * <li> <code> getActiveFrame() </code> : gets active frame </li>
151 public void _setActiveFrame() {
152 boolean result
= true ;
153 XFrame sFrame
= null ;
155 requiredMethod("getActiveFrame()") ;
156 if (frames
.getCount() > 1) {
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");
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
) ;
176 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
177 log
.println("Exception occurred while calling getByIndex() method :") ;
178 e
.printStackTrace(log
) ;
181 } else if (frames
.getCount() > 0) {
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");
194 tRes
.tested("setActiveFrame()", result
) ;
197 } // finished class _XFramesSupplier