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.NoSuchElementException;
29 import com.sun.star.container.XEnumeration;
30 import com.sun.star.container.XEnumerationAccess;
31 import com.sun.star.frame.XDesktop;
32 import com.sun.star.lang.WrappedTargetException;
33 import com.sun.star.uno.AnyConverter;
34 import com.sun.star.uno.Type;
35 import com.sun.star.uno.XInterface;
36 
37 /**
38 * Testing <code>com.sun.star.frame.XDesktop</code>
39 * interface methods:
40 * <ul>
41 *  <li><code> getComponents() </code></li>
42 *  <li><code> terminate() </code></li>
43 *  <li><code> addTerminateListener() </code></li>
44 *  <li><code> removeTerminateListener() </code></li>
45 *  <li><code> getCurrentComponent() </code></li>
46 *  <li><code> getCurrentFrame() </code></li>
47 * </ul><p>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.frame.XDesktop
50 */
51 public class _XDesktop extends MultiMethodTest {
52     public XDesktop oObj = null; // oObj filled by MultiMethodTest
53 
54     /**
55     * Test calls the method. Then elements enumeration is created and tested.<p>
56     * Has <b> OK </b> status if no exceptions were thrown.
57     */
_getComponents()58     public void _getComponents() {
59         XEnumerationAccess xComps = oObj.getComponents();
60         XEnumeration xEnum = xComps.createEnumeration();
61         boolean result = false;
62 
63         try {
64             for (; xEnum.hasMoreElements();) {
65                 XInterface xInt = null;
66                 try {
67                     xInt = (XInterface) AnyConverter.toObject(
68                             new Type(XInterface.class), xEnum.nextElement());
69                 } catch (com.sun.star.lang.IllegalArgumentException iae) {
70                     log.println("Can't convert any");
71                 }
72             }
73             result = true;
74         } catch (WrappedTargetException e) {
75             log.println("Couldn't get a component : " + e.getMessage());
76             e.printStackTrace();
77         } catch (NoSuchElementException e) {
78             log.println("Couldn't get a component : " + e.getMessage());
79             e.printStackTrace();
80         }
81         tRes.tested("getComponents()", result);
82     }
83 
84     /**
85     * Cannot test the method because it requires
86     * terminating StarOffice. Will add real test later.
87     */
_terminate()88     public void _terminate() {
89         tRes.tested("terminate()", true);
90     }
91 
92     /**
93     * Cannot test the method because of terminate().
94     * Will add real test later.
95     */
_addTerminateListener()96     public void _addTerminateListener() {
97         tRes.tested("addTerminateListener()", true);
98     }
99 
100     /**
101     * Cannot test the method because of terminate().
102     * Will add real test later.
103     */
_removeTerminateListener()104     public void _removeTerminateListener() {
105         tRes.tested("removeTerminateListener()", true);
106     }
107 
108     /**
109     * Test calls the method. <p>
110     * Has <b> OK </b> status if the method does not return null.
111     */
_getCurrentComponent()112     public void _getCurrentComponent() {
113         tRes.tested("getCurrentComponent()",
114             oObj.getCurrentComponent() != null);
115     }
116 
117     /**
118     * Test calls the method. <p>
119     * Has <b> OK </b> status if the method does not return null.
120     */
_getCurrentFrame()121     public void _getCurrentFrame() {
122         tRes.tested("getCurrentFrame()", oObj.getCurrentFrame() != null);
123     }
124 
125 }
126 
127