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 mod._fwk;
29 
30 import java.io.PrintWriter;
31 
32 import lib.Status;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
37 import util.SOfficeFactory;
38 
39 import com.sun.star.frame.XDesktop;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
44 
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.frame.Desktop</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 *  <li><code>com::sun::star::beans::XPropertySet</code></li>
51 *  <li><code>com::sun::star::frame::XComponentLoader</code></li>
52 *  <li><code>com::sun::star::frame::XDesktop</code></li>
53 *  <li><code>com::sun::star::frame::XDispatchProvider</code></li>
54 *  <li><code>com::sun::star::frame::XFrame</code></li>
55 *  <li><code>com::sun::star::frame::XFramesSupplier</code></li>
56 *  <li><code>com::sun::star::frame::XTasksSupplier</code></li>
57 *  <li><code>com::sun::star::lang::XComponent</code></li>
58 *  <li><code>com::sun::star::task::XStatusIndicatorFactory</code></li>
59 * </ul><p>
60 * @see com.sun.star.beans.XPropertySet
61 * @see com.sun.star.frame.XComponentLoader
62 * @see com.sun.star.frame.XDesktop
63 * @see com.sun.star.frame.XDispatchProvider
64 * @see com.sun.star.frame.XFrame
65 * @see com.sun.star.frame.XFramesSupplier
66 * @see com.sun.star.frame.XTasksSupplier
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.task.XStatusIndicatorFactory
69 * @see ifc.beans._XPropertySet
70 * @see ifc.frame._XComponentLoader
71 * @see ifc.frame._XDesktop
72 * @see ifc.frame._XDispatchProvider
73 * @see ifc.frame._XFrame
74 * @see ifc.frame._XFramesSupplier
75 * @see ifc.frame._XTasksSupplier
76 * @see ifc.lang._XComponent
77 * @see ifc.task._XStatusIndicatorFactory
78 */
79 public class Desktop extends TestCase {
80 
81     XTextDocument xTextDoc;
82 
83     /**
84      * Disposes the document, if exists, created in
85      * <code>createTestEnvironment</code> method.
86      */
87     protected void cleanup( TestParameters Param, PrintWriter log) {
88 
89         log.println("disposing xTextDoc");
90 
91         if (xTextDoc != null) {
92             try {
93                 xTextDoc.dispose();
94             } catch (com.sun.star.lang.DisposedException de) {}
95         }
96     }
97 
98     /**
99     * Creating a Testenvironment for the interfaces to be tested.
100     * Creates service <code>com.sun.star.frame.Desktop</code>.
101     */
102     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
103 
104         // get a soffice factory object
105         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
106 
107         try {
108             log.println( "creating a text document" );
109             xTextDoc = SOF.createTextDoc(null);
110         } catch ( com.sun.star.uno.Exception e ) {
111             // Some exception occures.FAILED
112             e.printStackTrace( log );
113             throw new StatusException( "Couldn't create document", e );
114         }
115 
116         XInterface oObj = null;
117 
118         try {
119             oObj = (XInterface)((XMultiServiceFactory)Param.getMSF()).createInstance(
120                 "com.sun.star.comp.framework.Desktop");
121         } catch(com.sun.star.uno.Exception e) {
122             e.printStackTrace(log);
123             throw new StatusException(
124                 Status.failed("Couldn't create instance"));
125         }
126 
127         TestEnvironment tEnv = new TestEnvironment( oObj );
128 
129         tEnv.addObjRelation("XDispatchProvider.URL", ".uno:Open");
130 
131         tEnv.addObjRelation("Desktop",(XDesktop)
132                                 UnoRuntime.queryInterface(XDesktop.class,oObj));
133 
134         return tEnv;
135     } // finish method getTestEnvironment
136 
137 }
138