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