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._sfx;
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.utils;
33 
34 import com.sun.star.document.XStandaloneDocumentInfo;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 
39 /**
40  * Test for object which is represented by service
41  * <code>com.sun.star.document.StandaloneDocumentInfo</code>. <p>
42  * Object implements the following interfaces :
43  * <ul>
44  *  <li> <code>com::sun::star::lang::XComponent</code></li>
45  *  <li> <code>com::sun::star::document::DocumentInfo</code></li>
46  *  <li> <code>com::sun::star::document::XDocumentInfo</code></li>
47  *  <li> <code>com::sun::star::document::XStandaloneDocumentInfo</code></li>
48  *  <li> <code>com::sun::star::beans::XFastPropertySet</code></li>
49  *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
50  * </ul> <p>
51  * The following files used by this test :
52  * <ul>
53  *  <li><b> SfxStandaloneDocInfoObject.sdw </b> : is copied
54  *   to SOffice temporary directory and is used to load and
55  *   save its info. </li>
56  * </ul> <p>
57  * This object test <b> is NOT </b> designed to be run in several
58  * threads concurently.
59  *
60  * @see com.sun.star.lang.XComponent
61  * @see com.sun.star.document.DocumentInfo
62  * @see com.sun.star.document.XDocumentInfo
63  * @see com.sun.star.document.XStandaloneDocumentInfo
64  * @see com.sun.star.beans.XFastPropertySet
65  * @see com.sun.star.beans.XPropertySet
66  * @see ifc.lang._XComponent
67  * @see ifc.document._DocumentInfo
68  * @see ifc.document._XDocumentInfo
69  * @see ifc.document._XStandaloneDocumentInfo
70  * @see ifc.beans._XFastPropertySet
71  * @see ifc.beans._XPropertySet
72  */
73 public class StandaloneDocumentInfo extends TestCase {
74 
75     String destUrl = null ;
76 
77     /**
78      * Copies file 'SfxStandaloneDocInfoObject.sdw' to tempopary
79      * location (overwriting the old file if exists).
80      */
initialize( TestParameters tParam, PrintWriter log )81     protected void initialize( TestParameters tParam, PrintWriter log ) {
82         String srcUrl = utils.getFullTestURL("SfxStandaloneDocInfoObject.sdw") ;
83         destUrl = utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) +
84             "SfxStandaloneDocInfoObject.sdw";
85 
86         utils.doOverwriteFile((XMultiServiceFactory)tParam.getMSF(), srcUrl, destUrl) ;
87     }
88 
89     /**
90      * Creating a Testenvironment for the interfaces to be tested.
91      * Creates an instance of the service
92      * <code>com.sun.star.document.StandaloneDocumentInfo</code>.
93      *     Object relations created :
94      * <ul>
95      *  <li> <code>'DOCURL'</code> for
96      *      {@link ifc.document._XStandaloneDocumentInfo} :
97      *      the Writer file URL in temporary location. </li>
98      * </ul>
99      */
createTestEnvironment(TestParameters tParam, PrintWriter log)100     protected TestEnvironment createTestEnvironment
101             (TestParameters tParam, PrintWriter log) {
102         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
103         XInterface oObj = null;
104 
105         try {
106             oObj = (XInterface)xMSF.createInstance
107                 ("com.sun.star.document.StandaloneDocumentInfo");
108         } catch (com.sun.star.uno.Exception e) {
109             e.printStackTrace(log);
110             throw new StatusException("Unexpected exception", e);
111         }
112 
113         String Iname = util.utils.getImplName(oObj);
114         log.println("Implementation Name: "+Iname);
115         TestEnvironment tEnv = new TestEnvironment(oObj);
116         XStandaloneDocumentInfo the_info = (XStandaloneDocumentInfo)
117                 UnoRuntime.queryInterface(XStandaloneDocumentInfo.class, oObj);
118         try {
119             the_info.loadFromURL(destUrl);
120         } catch (com.sun.star.io.IOException e) {
121             e.printStackTrace(log);
122             throw new StatusException("Couldn't load document: " + destUrl,e);
123         }
124         tEnv.addObjRelation("DOCURL",destUrl);
125         return tEnv;
126     }
127 
128 }    // finish class TestCase
129 
130