1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.frame;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir import com.sun.star.container.XIndexAccess;
29cdf0e10cSrcweir import com.sun.star.frame.XFrame;
30cdf0e10cSrcweir import com.sun.star.frame.XFramesSupplier;
31cdf0e10cSrcweir import com.sun.star.uno.AnyConverter;
32cdf0e10cSrcweir import com.sun.star.uno.Type;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /**
35cdf0e10cSrcweir * Testing <code>com.sun.star.frame.XFramesSupplier</code>
36cdf0e10cSrcweir * interface methods:
37cdf0e10cSrcweir * <ul>
38cdf0e10cSrcweir *  <li><code> getActiveFrame() </code></li>
39cdf0e10cSrcweir *  <li><code> getFrames() </code></li>
40cdf0e10cSrcweir *  <li><code> setActiveFrame() </code></li>
41cdf0e10cSrcweir * </ul><p>
42cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
43cdf0e10cSrcweir * @see com.sun.star.frame.XFramesSupplier
44cdf0e10cSrcweir */
45cdf0e10cSrcweir public class _XFramesSupplier extends MultiMethodTest {
46cdf0e10cSrcweir     public static XFramesSupplier oObj = null;
47cdf0e10cSrcweir     protected XIndexAccess frames = null ;
48cdf0e10cSrcweir     protected XFrame active = null ;
49cdf0e10cSrcweir     protected int activeIdx = -1 ;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     /**
52cdf0e10cSrcweir     * Test calls the method, then result is checked. Also active frame index
53cdf0e10cSrcweir     * is saved in activeIdx variable.<p>
54cdf0e10cSrcweir     *
55cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null and the object
56cdf0e10cSrcweir     * contains returned frame. Or if no frames available and the method
57cdf0e10cSrcweir     * returns null.<p>
58cdf0e10cSrcweir     *
59cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
60cdf0e10cSrcweir     * <ul>
61cdf0e10cSrcweir     *  <li> <code> getFrames() </code> : obtains frames from the object </li>
62cdf0e10cSrcweir     * </ul>
63cdf0e10cSrcweir     */
_getActiveFrame()64cdf0e10cSrcweir     public void _getActiveFrame() {
65cdf0e10cSrcweir         boolean result = true ;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir         requiredMethod("getFrames()") ;
68cdf0e10cSrcweir         active = oObj.getActiveFrame() ;
69cdf0e10cSrcweir         if (active == null) {
70cdf0e10cSrcweir             // if no child frames then no active frame could be
71cdf0e10cSrcweir             result =  oObj.getFrames().getCount() == 0;
72cdf0e10cSrcweir             log.println("getActiveFrame() returned null") ;
73cdf0e10cSrcweir         }
74cdf0e10cSrcweir         else {
75cdf0e10cSrcweir             boolean hasActiveFrame = false ;
76cdf0e10cSrcweir             for (int i = 0; i < frames.getCount(); i++) {
77cdf0e10cSrcweir                 XFrame fr = null ;
78cdf0e10cSrcweir                 try {
79cdf0e10cSrcweir                    fr = null;
80cdf0e10cSrcweir                    try {
81cdf0e10cSrcweir                        fr = (XFrame) AnyConverter.toObject(
82cdf0e10cSrcweir                                 new Type(XFrame.class),frames.getByIndex(i));
83cdf0e10cSrcweir                    } catch (com.sun.star.lang.IllegalArgumentException iae) {
84cdf0e10cSrcweir                        log.println("Can't convert any");
85cdf0e10cSrcweir                    }
86cdf0e10cSrcweir                 } catch (com.sun.star.lang.WrappedTargetException e) {
87cdf0e10cSrcweir                    log.println("Exception occured while calling getByIndex() method :") ;
88cdf0e10cSrcweir                    e.printStackTrace(log) ;
89cdf0e10cSrcweir                    return;
90cdf0e10cSrcweir                 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
91cdf0e10cSrcweir                    log.println("Exception occured while calling getByIndex() method :") ;
92cdf0e10cSrcweir                    e.printStackTrace(log) ;
93cdf0e10cSrcweir                    return;
94cdf0e10cSrcweir                 }
95cdf0e10cSrcweir                 if (active.equals(fr)) {
96cdf0e10cSrcweir                     hasActiveFrame = true ;
97cdf0e10cSrcweir                     activeIdx = i ;
98cdf0e10cSrcweir                 }
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir             if (!hasActiveFrame) {
101cdf0e10cSrcweir                 log.println("getActiveFrame() isn't contained " +
102cdf0e10cSrcweir                     "in getFrames() collection") ;
103cdf0e10cSrcweir                 result = false ;
104cdf0e10cSrcweir             }
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir         tRes.tested("getActiveFrame()", result) ;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     /**
111cdf0e10cSrcweir     * Test calls the method, then result is checked. <p>
112cdf0e10cSrcweir     * Has <b> OK </b> status if the method does not return null,
113cdf0e10cSrcweir     * number of returned frames is not zero and each of them is not null too.
114cdf0e10cSrcweir     */
_getFrames()115cdf0e10cSrcweir     public void _getFrames() {
116cdf0e10cSrcweir         boolean result = true ;
117cdf0e10cSrcweir         int cnt = 0;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         frames = oObj.getFrames() ;
120cdf0e10cSrcweir         if (frames != null) {
121cdf0e10cSrcweir             cnt = frames.getCount() ;
122cdf0e10cSrcweir //            if (cnt == 0) result = false ;
123cdf0e10cSrcweir             log.println("There are " + cnt + " frames.") ;
124cdf0e10cSrcweir         } else {
125cdf0e10cSrcweir             log.println("getFrames() returned null !!!") ;
126cdf0e10cSrcweir             result = false ;
127cdf0e10cSrcweir         }
128cdf0e10cSrcweir         for (int i = 0; i < cnt; i++) {
129cdf0e10cSrcweir             try {
130cdf0e10cSrcweir                 if (frames.getByIndex(i) == null) {
131cdf0e10cSrcweir                     log.println("Frame(" + i + ") == null") ;
132cdf0e10cSrcweir                     result = false ;
133cdf0e10cSrcweir                 }
134cdf0e10cSrcweir             } catch (com.sun.star.lang.WrappedTargetException e) {
135cdf0e10cSrcweir                     log.println("Exception occured while calling getByIndex() method :") ;
136cdf0e10cSrcweir                     e.printStackTrace(log) ;
137cdf0e10cSrcweir                     return;
138cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
139cdf0e10cSrcweir                     log.println("Exception occured while calling getByIndex() method :") ;
140cdf0e10cSrcweir                     e.printStackTrace(log) ;
141cdf0e10cSrcweir                     return;
142cdf0e10cSrcweir             }
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir         tRes.tested("getFrames()", result) ;
146cdf0e10cSrcweir     }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     /**
149cdf0e10cSrcweir     * After selecting frame to be activated, test calls the method. <p>
150cdf0e10cSrcweir     *
151cdf0e10cSrcweir     * Has <b> OK </b> status if set and gotten active frames are equal.<p>
152cdf0e10cSrcweir     *
153cdf0e10cSrcweir     * The following method tests are to be completed successfully before :
154cdf0e10cSrcweir     * <ul>
155cdf0e10cSrcweir     *  <li> <code> getActiveFrame() </code> : gets active frame </li>
156cdf0e10cSrcweir     * </ul>
157cdf0e10cSrcweir     */
_setActiveFrame()158cdf0e10cSrcweir     public void _setActiveFrame() {
159cdf0e10cSrcweir         boolean result = true ;
160cdf0e10cSrcweir         XFrame sFrame = null ;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         requiredMethod("getActiveFrame()") ;
163cdf0e10cSrcweir         if (frames.getCount() > 1) {
164cdf0e10cSrcweir             try {
165cdf0e10cSrcweir                 if (activeIdx != 0)
166cdf0e10cSrcweir                    try {
167cdf0e10cSrcweir                        sFrame = (XFrame) AnyConverter.toObject(
168cdf0e10cSrcweir                                 new Type(XFrame.class),frames.getByIndex(0));
169cdf0e10cSrcweir                    } catch (com.sun.star.lang.IllegalArgumentException iae) {
170cdf0e10cSrcweir                        log.println("Can't convert any");
171cdf0e10cSrcweir                    }
172cdf0e10cSrcweir                 else
173cdf0e10cSrcweir                    try {
174cdf0e10cSrcweir                        sFrame = (XFrame) AnyConverter.toObject(
175cdf0e10cSrcweir                                 new Type(XFrame.class),frames.getByIndex(1));
176cdf0e10cSrcweir                    } catch (com.sun.star.lang.IllegalArgumentException iae) {
177cdf0e10cSrcweir                        log.println("Can't convert any");
178cdf0e10cSrcweir                    }
179cdf0e10cSrcweir             } catch (com.sun.star.lang.WrappedTargetException e) {
180cdf0e10cSrcweir                     log.println("Exception occured while calling getByIndex() method :") ;
181cdf0e10cSrcweir                     e.printStackTrace(log) ;
182cdf0e10cSrcweir                     return;
183cdf0e10cSrcweir             } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
184cdf0e10cSrcweir                     log.println("Exception occured while calling getByIndex() method :") ;
185cdf0e10cSrcweir                     e.printStackTrace(log) ;
186cdf0e10cSrcweir                     return;
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir         } else if (frames.getCount() > 0) {
189cdf0e10cSrcweir             sFrame = active ;
190cdf0e10cSrcweir         } else {
191cdf0e10cSrcweir             sFrame = null;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         oObj.setActiveFrame(sFrame) ;
195cdf0e10cSrcweir         XFrame gFrame = oObj.getActiveFrame() ;
196cdf0e10cSrcweir         if (!(gFrame == null && sFrame == null
197cdf0e10cSrcweir               || sFrame.equals(gFrame))) {
198cdf0e10cSrcweir 
199cdf0e10cSrcweir             log.println("Active frame set is not equal frame get: FAILED");
200cdf0e10cSrcweir             result = false ;
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         tRes.tested("setActiveFrame()", result) ;
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir } // finished class _XFramesSupplier
207cdf0e10cSrcweir 
208