1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sd;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.container.XNameContainer;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.lang.XSingleServiceFactory;
42 import com.sun.star.presentation.XCustomPresentationSupplier;
43 import com.sun.star.presentation.XPresentationSupplier;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.presentation.Presentation</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 *  <li> <code>com::sun::star::presentation::Presentation</code></li>
53 *  <li> <code>com::sun::star::presentation::XPresentation</code></li>
54 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
55 * </ul>
56 * @see com.sun.star.presentation.Presentation
57 * @see com.sun.star.presentation.XPresentation
58 * @see com.sun.star.beans.XPropertySet
59 * @see ifc.presentation._Presentation
60 * @see ifc.presentation._XPresentation
61 * @see ifc.beans._XPropertySet
62 */
63 public class SdXPresentation extends TestCase {
64     XComponent xImpressDoc;
65 
66     /**
67     * Creates Impress document.
68     */
69     protected void initialize(TestParameters Param, PrintWriter log) {
70         // get a soffice factory object
71         SOfficeFactory SOF = SOfficeFactory.getFactory(
72                                     (XMultiServiceFactory)Param.getMSF());
73 
74         try {
75             log.println( "creating a draw document" );
76             xImpressDoc = SOF.createImpressDoc(null);;
77         } catch (com.sun.star.uno.Exception e) {
78             e.printStackTrace( log );
79             throw new StatusException("Couldn't create document", e);
80         }
81     }
82 
83     /**
84     * Disposes Impress document.
85     */
86     protected void cleanup( TestParameters Param, PrintWriter log) {
87         log.println("disposing xImpressDoc");
88         util.DesktopTools.closeDoc(xImpressDoc);;
89     }
90 
91     /**
92     * Creating a Testenvironment for the interfaces to be tested.
93     * Retrieves the presentation from the document using the interface
94     * <code>XPresentationSupplier</code>. The retrieved presentation is the
95     * instance of the service <code>com.sun.star.presentation.Presentation</code>.
96     * Retrieves the collection of the customized presentations from the document
97     * using the interface <code>XCustomPresentationSupplier</code>.
98     * Creates and inserts two new instances of presentation to the retrieved
99     * collection.
100     * Object relations created :
101     * <ul>
102     *  <li> <code>'Presentation'</code> for
103     *      {@link ifc.presentation._Presentation}(the retrieved presentation)</li>
104     * </ul>
105     * @see com.sun.star.presentation.XCustomPresentationSupplier
106     * @see com.sun.star.presentation.Presentation
107     * @see com.sun.star.presentation.XCustomPresentationSupplier
108     */
109     public TestEnvironment createTestEnvironment(
110         TestParameters Param, PrintWriter log) throws StatusException {
111 
112         // creation of testobject here
113         // first we write what we are intend to do to log file
114         log.println( "creating a test environment" );
115 
116         log.println( "get presentation" );
117         XPresentationSupplier oPS = (XPresentationSupplier)
118             UnoRuntime.queryInterface(XPresentationSupplier.class, xImpressDoc);
119         XInterface oObj = oPS.getPresentation();
120 
121         log.println( "get custom presentation" );
122         XCustomPresentationSupplier oCPS = (XCustomPresentationSupplier)
123             UnoRuntime.queryInterface(
124                 XCustomPresentationSupplier.class, xImpressDoc);
125         XNameContainer xCP = oCPS.getCustomPresentations();
126 
127         XInterface oInstance = null;
128         XInterface oInstance2 = null;
129 
130         XSingleServiceFactory oSingleMSF = (XSingleServiceFactory)
131             UnoRuntime.queryInterface(XSingleServiceFactory.class, xCP);
132 
133         try{
134             oInstance = (XInterface) oSingleMSF.createInstance();
135             oInstance2 = (XInterface) oSingleMSF.createInstance();
136         } catch (com.sun.star.uno.Exception e) {
137             e.printStackTrace(log);
138             throw new StatusException("Couldn't create instance", e);
139         }
140 
141         try {
142             xCP.insertByName("FirstPresentation",oInstance);
143             xCP.insertByName("SecondPresentation", oInstance2);
144         } catch (com.sun.star.lang.WrappedTargetException e) {
145             e.printStackTrace(log);
146             throw new StatusException("Could't insert Instance", e);
147         } catch (com.sun.star.container.ElementExistException e) {
148             e.printStackTrace(log);
149             throw new StatusException("Could't insert Instance", e);
150         } catch (com.sun.star.lang.IllegalArgumentException e) {
151             e.printStackTrace(log);
152             throw new StatusException("Could't insert Instance", e);
153         }
154 
155         log.println( "creating a new environment for XPresentation object" );
156         TestEnvironment tEnv = new TestEnvironment( oObj );
157 
158         tEnv.addObjRelation("Presentation",oObj);
159 
160         return tEnv;
161     } // finish method getTestEnvironment
162 
163 }    // finish class SdPresentation
164 
165