2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XNameContainer
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XSingleServiceFactory
;
32 import com
.sun
.star
.presentation
.XCustomPresentationSupplier
;
33 import com
.sun
.star
.presentation
.XPresentationSupplier
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.presentation.Presentation</code>. <p>
40 * Object implements the following interfaces :
42 * <li> <code>com::sun::star::presentation::Presentation</code></li>
43 * <li> <code>com::sun::star::presentation::XPresentation</code></li>
44 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
46 * @see com.sun.star.presentation.Presentation
47 * @see com.sun.star.presentation.XPresentation
48 * @see com.sun.star.beans.XPropertySet
49 * @see ifc.presentation._Presentation
50 * @see ifc.presentation._XPresentation
51 * @see ifc.beans._XPropertySet
53 public class SdXPresentation
extends TestCase
{
54 XComponent xImpressDoc
;
57 * Creates Impress document.
60 protected void initialize(TestParameters Param
, PrintWriter log
) {
61 // get a soffice factory object
62 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
66 log
.println( "creating a draw document" );
67 xImpressDoc
= SOF
.createImpressDoc(null);
68 } catch (com
.sun
.star
.uno
.Exception e
) {
69 e
.printStackTrace( log
);
70 throw new StatusException("Couldn't create document", e
);
75 * Disposes Impress document.
78 protected void cleanup( TestParameters Param
, PrintWriter log
) {
79 log
.println("disposing xImpressDoc");
80 util
.DesktopTools
.closeDoc(xImpressDoc
);
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Retrieves the presentation from the document using the interface
86 * <code>XPresentationSupplier</code>. The retrieved presentation is the
87 * instance of the service <code>com.sun.star.presentation.Presentation</code>.
88 * Retrieves the collection of the customized presentations from the document
89 * using the interface <code>XCustomPresentationSupplier</code>.
90 * Creates and inserts two new instances of presentation to the retrieved
92 * Object relations created :
94 * <li> <code>'Presentation'</code> for
95 * {@link ifc.presentation._Presentation}(the retrieved presentation)</li>
97 * @see com.sun.star.presentation.XCustomPresentationSupplier
98 * @see com.sun.star.presentation.Presentation
99 * @see com.sun.star.presentation.XCustomPresentationSupplier
102 public TestEnvironment
createTestEnvironment(
103 TestParameters Param
, PrintWriter log
) throws StatusException
{
105 // creation of testobject here
106 // first we write what we are intend to do to log file
107 log
.println( "creating a test environment" );
109 log
.println( "get presentation" );
110 XPresentationSupplier oPS
= UnoRuntime
.queryInterface(XPresentationSupplier
.class, xImpressDoc
);
111 XInterface oObj
= oPS
.getPresentation();
113 log
.println( "get custom presentation" );
114 XCustomPresentationSupplier oCPS
= UnoRuntime
.queryInterface(
115 XCustomPresentationSupplier
.class, xImpressDoc
);
116 XNameContainer xCP
= oCPS
.getCustomPresentations();
118 XInterface oInstance
= null;
119 XInterface oInstance2
= null;
121 XSingleServiceFactory oSingleMSF
= UnoRuntime
.queryInterface(XSingleServiceFactory
.class, xCP
);
124 oInstance
= (XInterface
) oSingleMSF
.createInstance();
125 oInstance2
= (XInterface
) oSingleMSF
.createInstance();
126 } catch (com
.sun
.star
.uno
.Exception e
) {
127 e
.printStackTrace(log
);
128 throw new StatusException("Couldn't create instance", e
);
132 xCP
.insertByName("FirstPresentation",oInstance
);
133 xCP
.insertByName("SecondPresentation", oInstance2
);
134 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
135 e
.printStackTrace(log
);
136 throw new StatusException("Could't insert Instance", e
);
137 } catch (com
.sun
.star
.container
.ElementExistException e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException("Could't insert Instance", e
);
140 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
141 e
.printStackTrace(log
);
142 throw new StatusException("Could't insert Instance", e
);
145 log
.println( "creating a new environment for XPresentation object" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("Presentation",oObj
);
151 } // finish method getTestEnvironment
153 } // finish class SdPresentation