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.document.XDocumentInfoSupplier;
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 
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.document.DocumentInfo</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 *  <li><code>com::sun::star::beans::XFastPropertySet</code></li>
46 *  <li><code>com::sun::star::beans::XPropertySet</code></li>
47 *  <li><code>com::sun::star::document::XDocumentInfo</code></li>
48 *  <li><code>com::sun::star::document::XStandaloneDocumentInfo</code></li>
49 *  <li><code>com::sun::star::lang::XComponent</code></li>
50 * </ul><p>
51 * @see com.sun.star.beans.XFastPropertySet
52 * @see com.sun.star.beans.XPropertySet
53 * @see com.sun.star.document.XDocumentInfo
54 * @see com.sun.star.document.XStandaloneDocumentInfo
55 * @see com.sun.star.lang.XComponent
56 * @see ifc.beans._XFastPropertySet
57 * @see ifc.beans._XPropertySet
58 * @see ifc.document._XDocumentInfo
59 * @see ifc.document._XStandaloneDocumentInfo
60 * @see ifc.lang._XComponent
61 */
62 public class DocumentProperties extends TestCase {
63 
64     XTextDocument xTextDoc;
65 
66     /**
67      * Disposes the document, if exists, created in
68      * <code>createTestEnvironment</code> method.
69      */
cleanup( TestParameters Param, PrintWriter log)70     protected void cleanup( TestParameters Param, PrintWriter log) {
71 
72         log.println("disposing xTextDoc");
73 
74         if (xTextDoc != null) {
75             xTextDoc.dispose();
76         }
77     }
78 
79     /**
80     * Creates a text document.
81     * Obtains the property <code>'DocumentInfo'</code> of the created document.
82     */
createTestEnvironment( TestParameters Param, PrintWriter log )83     public TestEnvironment createTestEnvironment( TestParameters Param,
84         PrintWriter log ) throws StatusException {
85 
86         XInterface oObj = null;
87 
88         log.println( "creating a test environment" );
89 
90         if (xTextDoc != null) xTextDoc.dispose();
91 
92         // get a soffice factory object
93         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF());
94 
95         try {
96             log.println( "creating a text document" );
97             xTextDoc = SOF.createTextDoc(null);
98         } catch ( com.sun.star.uno.Exception e ) {
99             // Some exception occures.FAILED
100             e.printStackTrace( log );
101             throw new StatusException( "Couldn't create document", e );
102         }
103 
104         shortWait();
105 
106         XDocumentInfoSupplier xdis = (XDocumentInfoSupplier)
107                 UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xTextDoc);
108         //oObj = (XInterface)UnoRuntime.queryInterface(XInterface.class, docInfo);
109         oObj = xdis.getDocumentInfo();
110         TestEnvironment tEnv = new TestEnvironment( oObj );
111 
112         return tEnv;
113     } // finish method getTestEnvironment
114 
115     /**
116     * Sleeps for 0.5 sec. to allow StarOffice to react on <code>
117     * reset</code> call.
118     */
shortWait()119     private void shortWait() {
120         try {
121             Thread.sleep(500) ;
122         } catch (InterruptedException e) {
123             log.println("While waiting :" + e) ;
124         }
125     }
126 }
127