bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdXPresentation.java
blob9b630a11d159d773d9a09e5182a240171e6c4219
1 /*
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 .
19 package mod._sd;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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.XMultiServiceFactory;
32 import com.sun.star.lang.XSingleServiceFactory;
33 import com.sun.star.presentation.XCustomPresentationSupplier;
34 import com.sun.star.presentation.XPresentationSupplier;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.presentation.Presentation</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::presentation::Presentation</code></li>
44 * <li> <code>com::sun::star::presentation::XPresentation</code></li>
45 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
46 * </ul>
47 * @see com.sun.star.presentation.Presentation
48 * @see com.sun.star.presentation.XPresentation
49 * @see com.sun.star.beans.XPropertySet
50 * @see ifc.presentation._Presentation
51 * @see ifc.presentation._XPresentation
52 * @see ifc.beans._XPropertySet
54 public class SdXPresentation extends TestCase {
55 XComponent xImpressDoc;
57 /**
58 * Creates Impress document.
60 protected void initialize(TestParameters Param, PrintWriter log) {
61 // get a soffice factory object
62 SOfficeFactory SOF = SOfficeFactory.getFactory(
63 (XMultiServiceFactory)Param.getMSF());
65 try {
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);
74 /**
75 * Disposes Impress document.
77 protected void cleanup( TestParameters Param, PrintWriter log) {
78 log.println("disposing xImpressDoc");
79 util.DesktopTools.closeDoc(xImpressDoc);
82 /**
83 * Creating a Testenvironment for the interfaces to be tested.
84 * Retrieves the presentation from the document using the interface
85 * <code>XPresentationSupplier</code>. The retrieved presentation is the
86 * instance of the service <code>com.sun.star.presentation.Presentation</code>.
87 * Retrieves the collection of the customized presentations from the document
88 * using the interface <code>XCustomPresentationSupplier</code>.
89 * Creates and inserts two new instances of presentation to the retrieved
90 * collection.
91 * Object relations created :
92 * <ul>
93 * <li> <code>'Presentation'</code> for
94 * {@link ifc.presentation._Presentation}(the retrieved presentation)</li>
95 * </ul>
96 * @see com.sun.star.presentation.XCustomPresentationSupplier
97 * @see com.sun.star.presentation.Presentation
98 * @see com.sun.star.presentation.XCustomPresentationSupplier
100 public TestEnvironment createTestEnvironment(
101 TestParameters Param, PrintWriter log) throws StatusException {
103 // creation of testobject here
104 // first we write what we are intend to do to log file
105 log.println( "creating a test environment" );
107 log.println( "get presentation" );
108 XPresentationSupplier oPS = UnoRuntime.queryInterface(XPresentationSupplier.class, xImpressDoc);
109 XInterface oObj = oPS.getPresentation();
111 log.println( "get custom presentation" );
112 XCustomPresentationSupplier oCPS = UnoRuntime.queryInterface(
113 XCustomPresentationSupplier.class, xImpressDoc);
114 XNameContainer xCP = oCPS.getCustomPresentations();
116 XInterface oInstance = null;
117 XInterface oInstance2 = null;
119 XSingleServiceFactory oSingleMSF = UnoRuntime.queryInterface(XSingleServiceFactory.class, xCP);
121 try{
122 oInstance = (XInterface) oSingleMSF.createInstance();
123 oInstance2 = (XInterface) oSingleMSF.createInstance();
124 } catch (com.sun.star.uno.Exception e) {
125 e.printStackTrace(log);
126 throw new StatusException("Couldn't create instance", e);
129 try {
130 xCP.insertByName("FirstPresentation",oInstance);
131 xCP.insertByName("SecondPresentation", oInstance2);
132 } catch (com.sun.star.lang.WrappedTargetException e) {
133 e.printStackTrace(log);
134 throw new StatusException("Could't insert Instance", e);
135 } catch (com.sun.star.container.ElementExistException e) {
136 e.printStackTrace(log);
137 throw new StatusException("Could't insert Instance", e);
138 } catch (com.sun.star.lang.IllegalArgumentException e) {
139 e.printStackTrace(log);
140 throw new StatusException("Could't insert Instance", e);
143 log.println( "creating a new environment for XPresentation object" );
144 TestEnvironment tEnv = new TestEnvironment( oObj );
146 tEnv.addObjRelation("Presentation",oObj);
148 return tEnv;
149 } // finish method getTestEnvironment
151 } // finish class SdPresentation