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._sd;
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.container.XNameContainer;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.lang.XSingleServiceFactory;
38 import com.sun.star.presentation.XCustomPresentationSupplier;
39 import com.sun.star.presentation.XPresentationSupplier;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
42 
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.presentation.Presentation</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 *  <li> <code>com::sun::star::presentation::Presentation</code></li>
49 *  <li> <code>com::sun::star::presentation::XPresentation</code></li>
50 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.presentation.Presentation
53 * @see com.sun.star.presentation.XPresentation
54 * @see com.sun.star.beans.XPropertySet
55 * @see ifc.presentation._Presentation
56 * @see ifc.presentation._XPresentation
57 * @see ifc.beans._XPropertySet
58 */
59 public class SdXPresentation extends TestCase {
60     XComponent xImpressDoc;
61 
62     /**
63     * Creates Impress document.
64     */
initialize(TestParameters Param, PrintWriter log)65     protected void initialize(TestParameters Param, PrintWriter log) {
66         // get a soffice factory object
67         SOfficeFactory SOF = SOfficeFactory.getFactory(
68                                     (XMultiServiceFactory)Param.getMSF());
69 
70         try {
71             log.println( "creating a draw document" );
72             xImpressDoc = SOF.createImpressDoc(null);
73         } catch (com.sun.star.uno.Exception e) {
74             e.printStackTrace( log );
75             throw new StatusException("Couldn't create document", e);
76         }
77     }
78 
79     /**
80     * Disposes Impress document.
81     */
cleanup( TestParameters Param, PrintWriter log)82     protected void cleanup( TestParameters Param, PrintWriter log) {
83         log.println("disposing xImpressDoc");
84         util.DesktopTools.closeDoc(xImpressDoc);
85     }
86 
87     /**
88     * Creating a Testenvironment for the interfaces to be tested.
89     * Retrieves the presentation from the document using the interface
90     * <code>XPresentationSupplier</code>. The retrieved presentation is the
91     * instance of the service <code>com.sun.star.presentation.Presentation</code>.
92     * Retrieves the collection of the customized presentations from the document
93     * using the interface <code>XCustomPresentationSupplier</code>.
94     * Creates and inserts two new instances of presentation to the retrieved
95     * collection.
96     * Object relations created :
97     * <ul>
98     *  <li> <code>'Presentation'</code> for
99     *      {@link ifc.presentation._Presentation}(the retrieved presentation)</li>
100     * </ul>
101     * @see com.sun.star.presentation.XCustomPresentationSupplier
102     * @see com.sun.star.presentation.Presentation
103     * @see com.sun.star.presentation.XCustomPresentationSupplier
104     */
createTestEnvironment( TestParameters Param, PrintWriter log)105     public TestEnvironment createTestEnvironment(
106         TestParameters Param, PrintWriter log) throws StatusException {
107 
108         // creation of testobject here
109         // first we write what we are intend to do to log file
110         log.println( "creating a test environment" );
111 
112         log.println( "get presentation" );
113         XPresentationSupplier oPS = (XPresentationSupplier)
114             UnoRuntime.queryInterface(XPresentationSupplier.class, xImpressDoc);
115         XInterface oObj = oPS.getPresentation();
116 
117         log.println( "get custom presentation" );
118         XCustomPresentationSupplier oCPS = (XCustomPresentationSupplier)
119             UnoRuntime.queryInterface(
120                 XCustomPresentationSupplier.class, xImpressDoc);
121         XNameContainer xCP = oCPS.getCustomPresentations();
122 
123         XInterface oInstance = null;
124         XInterface oInstance2 = null;
125 
126         XSingleServiceFactory oSingleMSF = (XSingleServiceFactory)
127             UnoRuntime.queryInterface(XSingleServiceFactory.class, xCP);
128 
129         try{
130             oInstance = (XInterface) oSingleMSF.createInstance();
131             oInstance2 = (XInterface) oSingleMSF.createInstance();
132         } catch (com.sun.star.uno.Exception e) {
133             e.printStackTrace(log);
134             throw new StatusException("Couldn't create instance", e);
135         }
136 
137         try {
138             xCP.insertByName("FirstPresentation",oInstance);
139             xCP.insertByName("SecondPresentation", oInstance2);
140         } catch (com.sun.star.lang.WrappedTargetException e) {
141             e.printStackTrace(log);
142             throw new StatusException("Could't insert Instance", e);
143         } catch (com.sun.star.container.ElementExistException e) {
144             e.printStackTrace(log);
145             throw new StatusException("Could't insert Instance", e);
146         } catch (com.sun.star.lang.IllegalArgumentException e) {
147             e.printStackTrace(log);
148             throw new StatusException("Could't insert Instance", e);
149         }
150 
151         log.println( "creating a new environment for XPresentation object" );
152         TestEnvironment tEnv = new TestEnvironment( oObj );
153 
154         tEnv.addObjRelation("Presentation",oObj);
155 
156         return tEnv;
157     } // finish method getTestEnvironment
158 
159 }    // finish class SdPresentation
160 
161