1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.frame;
29 
30 import lib.MultiMethodTest;
31 
32 import com.sun.star.container.NoSuchElementException;
33 import com.sun.star.container.XEnumeration;
34 import com.sun.star.container.XEnumerationAccess;
35 import com.sun.star.frame.XDesktop;
36 import com.sun.star.lang.WrappedTargetException;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.XInterface;
40 
41 /**
42 * Testing <code>com.sun.star.frame.XDesktop</code>
43 * interface methods:
44 * <ul>
45 *  <li><code> getComponents() </code></li>
46 *  <li><code> terminate() </code></li>
47 *  <li><code> addTerminateListener() </code></li>
48 *  <li><code> removeTerminateListener() </code></li>
49 *  <li><code> getCurrentComponent() </code></li>
50 *  <li><code> getCurrentFrame() </code></li>
51 * </ul><p>
52 * Test is <b> NOT </b> multithread compilant. <p>
53 * @see com.sun.star.frame.XDesktop
54 */
55 public class _XDesktop extends MultiMethodTest {
56     public XDesktop oObj = null; // oObj filled by MultiMethodTest
57 
58     /**
59     * Test calls the method. Then elements enumeration is created and tested.<p>
60     * Has <b> OK </b> status if no exceptions were thrown.
61     */
62     public void _getComponents() {
63         XEnumerationAccess xComps = oObj.getComponents();
64         XEnumeration xEnum = xComps.createEnumeration();
65         boolean result = false;
66 
67         try {
68             for (; xEnum.hasMoreElements();) {
69                 XInterface xInt = null;
70                 try {
71                     xInt = (XInterface) AnyConverter.toObject(
72                             new Type(XInterface.class), xEnum.nextElement());
73                 } catch (com.sun.star.lang.IllegalArgumentException iae) {
74                     log.println("Can't convert any");
75                 }
76             }
77             result = true;
78         } catch (WrappedTargetException e) {
79             log.println("Couldn't get a component : " + e.getMessage());
80             e.printStackTrace();
81         } catch (NoSuchElementException e) {
82             log.println("Couldn't get a component : " + e.getMessage());
83             e.printStackTrace();
84         }
85         tRes.tested("getComponents()", result);
86     }
87 
88     /**
89     * Cannot test the method because it requires
90     * terminating StarOffice. Will add real test later.
91     */
92     public void _terminate() {
93         tRes.tested("terminate()", true);
94     }
95 
96     /**
97     * Cannot test the method because of terminate().
98     * Will add real test later.
99     */
100     public void _addTerminateListener() {
101         tRes.tested("addTerminateListener()", true);
102     }
103 
104     /**
105     * Cannot test the method because of terminate().
106     * Will add real test later.
107     */
108     public void _removeTerminateListener() {
109         tRes.tested("removeTerminateListener()", true);
110     }
111 
112     /**
113     * Test calls the method. <p>
114     * Has <b> OK </b> status if the method does not return null.
115     */
116     public void _getCurrentComponent() {
117         tRes.tested("getCurrentComponent()",
118             oObj.getCurrentComponent() != null);
119     }
120 
121     /**
122     * Test calls the method. <p>
123     * Has <b> OK </b> status if the method does not return null.
124     */
125     public void _getCurrentFrame() {
126         tRes.tested("getCurrentFrame()", oObj.getCurrentFrame() != null);
127     }
128 
129 }
130 
131