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._sw;
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.lang.XMultiServiceFactory;
35 import com.sun.star.text.XTextDocument;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
38 import com.sun.star.view.XPrintSettingsSupplier;
39 
40 /**
41  * Test for object which is represented by service
42  * <code>com.sun.star.text.PrintSettings</code>. <p>
43  * Object implements the following interfaces :
44  * <ul>
45  *  <li> <code>com::sun::star::text::PrintSettings</code></li>
46  * </ul> <p>
47  * This object test <b> is NOT </b> designed to be run in several
48  * threads concurently.
49  * @see com.sun.star.text.PrintSettings
50  * @see ifc.text._PrintSettings
51  */
52 public class SwXPrintSettings extends TestCase {
53     XTextDocument xTextDoc;
54 
55     /**
56     * Creates text document.
57     */
initialize( TestParameters tParam, PrintWriter log )58     protected void initialize( TestParameters tParam, PrintWriter log ) {
59         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
60         try {
61             log.println( "creating a textdocument" );
62             xTextDoc = SOF.createTextDoc( null );
63         } catch ( com.sun.star.uno.Exception e ) {
64             e.printStackTrace( log );
65             throw new StatusException( "Couldn't create document", e );
66         }
67     }
68 
69     /**
70     * Disposes text document.
71     */
cleanup( TestParameters tParam, PrintWriter log )72     protected void cleanup( TestParameters tParam, PrintWriter log ) {
73         log.println( "    disposing xTextDoc " );
74         util.DesktopTools.closeDoc(xTextDoc);
75     }
76 
77     /**
78     * Creating a Testenvironment for the interfaces to be tested.
79     * Creates an instance of the service
80     * <code>com.sun.star.text.GlobalSettings</code>, then print settings are
81     * gotten using <code>XPrintSettingsSupplier</code> interface.
82     */
createTestEnvironment( TestParameters tParam, PrintWriter log )83     public TestEnvironment createTestEnvironment(
84             TestParameters tParam, PrintWriter log ) throws StatusException {
85         XInterface oObj = null;
86         Object oInst = null;
87 
88         log.println( "creating a test environment" );
89         try {
90             XMultiServiceFactory myMSF = (XMultiServiceFactory)tParam.getMSF();
91             oInst = myMSF.createInstance("com.sun.star.text.GlobalSettings");
92         } catch ( com.sun.star.uno.Exception e ){
93             log.println("Couldn't create instance!" + e);
94             e.printStackTrace( log );
95             throw new StatusException( "Couldn't create instance!", e );
96         }
97         XPrintSettingsSupplier xPSS = (XPrintSettingsSupplier)
98             UnoRuntime.queryInterface(XPrintSettingsSupplier.class, oInst);
99         oObj = xPSS.getPrintSettings();
100 
101         TestEnvironment tEnv = new TestEnvironment(oObj);
102         return tEnv;
103     } // finish method getTestEnvironment
104 
105 }    // finish class SwXPrintSettings
106 
107