xref: /aoo42x/main/qadevOOo/tests/java/mod/_fwk/Frame.java (revision 30acf5e8)
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 mod._fwk;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.frame.XFrame;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.util.XCloseable;
40 
41 /**
42 * Test for object that implements the following interfaces :
43 * <ul>
44 *  <li><code>com::sun::star::frame::XDispatchProvider</code></li>
45 *  <li><code>com::sun::star::frame::XFrame</code></li>
46 *  <li><code>com::sun::star::frame::XFramesSupplier</code></li>
47 *  <li><code>com::sun::star::task::XStatusIndicatorFactory</code></li>
48 *  <li><code>com::sun::star::lang::XComponent</code></li>
49 * </ul><p>
50 * @see com.sun.star.frame.XDispatchProvider
51 * @see com.sun.star.frame.XFrame
52 * @see com.sun.star.frame.XFramesSupplier
53 * @see com.sun.star.task.XStatusIndicatorFactory
54 * @see com.sun.star.lang.XComponent
55 * @see ifc.frame._XDispatchProvider
56 * @see ifc.frame._XFrame
57 * @see ifc.frame._XFramesSupplier
58 * @see ifc.task._XStatusIndicatorFactory
59 * @see ifc.lang._XComponent
60 */
61 public class Frame extends TestCase {
62 
63     XTextDocument xTextDoc;
64     XFrame frame = null;
65 
66 
67     /**
68     * Creates a text document and obtains a frame of current controller.
69     */
createTestEnvironment( TestParameters Param, PrintWriter log )70     public TestEnvironment createTestEnvironment( TestParameters Param,
71         PrintWriter log ) throws StatusException {
72 
73         XInterface oObj = null;
74 
75         log.println( "creating a test environment" );
76 
77         // get a soffice factory object
78         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
79 
80         try {
81             log.println( "creating a text document" );
82             xTextDoc = SOF.createTextDoc(null);
83         } catch ( com.sun.star.uno.Exception e ) {
84             // Some exception occured.FAILED
85             e.printStackTrace( log );
86             throw new StatusException( "Couldn't create document", e );
87         }
88 
89         frame = xTextDoc.getCurrentController().getFrame();
90         oObj = (XInterface)UnoRuntime.queryInterface(XInterface.class, frame);
91 
92         log.println(util.utils.getImplName(oObj));
93 
94         TestEnvironment tEnv = new TestEnvironment( oObj );
95 
96         tEnv.addObjRelation("XDispatchProvider.URL",
97             ".uno:SwitchControlDesignMode");
98 
99         return tEnv;
100     } // finish method getTestEnvironment
101 
102 
103     /**
104      * Disposes the document created and finally disposes
105      * the frame containing the document (for case when the frame
106      * contains no model after some interafce manipulations).
107      */
cleanup( TestParameters Param, PrintWriter log)108     protected void cleanup( TestParameters Param, PrintWriter log) {
109         try {
110             XCloseable xTextClose = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, xTextDoc);
111             xTextClose.close(true);
112         } catch(Exception e){}
113 
114     }
115 }
116