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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.container
.XNameContainer
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.lang
.XSingleServiceFactory
;
31 import com
.sun
.star
.presentation
.XCustomPresentationSupplier
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.presentation.CustomPresentationAccess</code>. <p>
38 * Object implements the following interfaces :
40 * <li> <code>com::sun::star::container::XNameAccess</code></li>
41 * <li> <code>com::sun::star::container::XElementAccess</code></li>
42 * <li> <code>com::sun::star::container::XNameReplace</code></li>
43 * <li> <code>com::sun::star::lang::XSingleServiceFactory</code></li>
44 * <li> <code>com::sun::star::container::XNameContainer</code></li>
46 * @see com.sun.star.presentation.CustomPresentationAccess
47 * @see com.sun.star.container.XNameAccess
48 * @see com.sun.star.container.XElementAccess
49 * @see com.sun.star.container.XNameReplace
50 * @see com.sun.star.lang.XSingleServiceFactory
51 * @see com.sun.star.container.XNameContainer
52 * @see ifc.container._XNameAccess
53 * @see ifc.container._XElementAccess
54 * @see ifc.container._XNameReplace
55 * @see ifc.lang._XSingleServiceFactory
56 * @see ifc.container._XNameContainer
58 public class SdXCustomPresentationAccess
extends TestCase
{
59 XComponent xImpressDoc
;
62 * Creates Impress document.
65 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
66 // get a soffice factory object
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
69 log
.println( "creating a draw document" );
70 xImpressDoc
= SOF
.createImpressDoc(null);
74 * Disposes Impress document.
77 protected void cleanup( TestParameters Param
, PrintWriter log
) {
78 log
.println("disposing xImpressDoc");
79 util
.DesktopTools
.closeDoc(xImpressDoc
);
83 * Creating a TestEnvironment for the interfaces to be tested.
84 * Retrieves the collection of the CustomPresentation from the document
85 * using the interface <code>XCustomPresentationSupplier</code>.
86 * The retrieved collection is the instance of the service
87 * <code>com.sun.star.presentation.CustomPresentationAccess</code>.
88 * Creates two new instances of the custom presentation using the interface
89 * <code>XSingleServiceFactory</code>. Inserts one of them to the
90 * retrieved collection. Creates and inserts several instances of
92 * Object relations created :
94 * <li> <code>'SecondInstance'</code> for
95 * {@link ifc.container._XNameContainer}(the second created instance
96 * of the custom presentation)</li>
97 * <li> <code>'XNameContainerINDEX'</code> for
98 * {@link ifc.container._XNameContainer}(the number of current running
100 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
101 * {@link ifc.container._XNameReplace},
102 * {@link ifc.container._XNameContainer}(the created instances of
103 * the presentation)</li>
105 * @see com.sun.star.presentation.XCustomPresentationSupplier
106 * @see com.sun.star.lang.XSingleServiceFactory
107 * @see com.sun.star.presentation.CustomPresentationAccess
110 public TestEnvironment
createTestEnvironment(
111 TestParameters Param
, PrintWriter log
) throws Exception
{
114 log
.println( "creating a test environment" );
116 log
.println( "get presentation" );
117 XCustomPresentationSupplier oPS
= UnoRuntime
.queryInterface(
118 XCustomPresentationSupplier
.class, xImpressDoc
);
119 XInterface oObj
= oPS
.getCustomPresentations();
122 XSingleServiceFactory oSingleMSF
= UnoRuntime
.queryInterface(XSingleServiceFactory
.class, oObj
);
124 XInterface oInstance
= null;
125 XInterface oSecondInstance
= null;
126 oInstance
= (XInterface
) oSingleMSF
.createInstance();
127 oSecondInstance
= (XInterface
) oSingleMSF
.createInstance();
129 XNameContainer aContainer
= UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
131 if (aContainer
.hasByName("FirstPresentation")) {
132 aContainer
.removeByName("FirstPresentation");
135 aContainer
.insertByName("FirstPresentation",oInstance
);
137 log
.println( "creating a new environment for XPresentation object" );
138 TestEnvironment tEnv
= new TestEnvironment( oObj
);
140 // adding an instance for insertByName ('XNameContainer')
141 tEnv
.addObjRelation("SecondInstance", oSecondInstance
);
144 if ((String
)Param
.get("THRCNT") != null) {
145 THRCNT
= Integer
.parseInt((String
)Param
.get("THRCNT"));
148 // INDEX : _XNameContainer
149 log
.println( "adding XNameContainerINDEX as mod relation to environment" );
150 tEnv
.addObjRelation("XNameContainerINDEX", Integer
.valueOf(THRCNT
).toString());
152 // INSTANCEn : _XNameContainer; _XNameReplace
153 log
.println( "adding INSTANCEn as mod relation to environment" );
155 for (int n
= 1; n
< (2*THRCNT
+1) ;n
++ ) {
156 log
.println( "adding INSTANCE" + n
157 +" as mod relation to environment" );
158 oInstance
= (XInterface
) oSingleMSF
.createInstance();
159 tEnv
.addObjRelation("INSTANCE" + n
, oInstance
);
161 } catch (com
.sun
.star
.uno
.Exception e
) {
162 log
.println("Couldn't adding INSTANCEn: " + e
);
166 } // finish method getTestEnvironment
168 } // finish class SdXCustomPresentationAccess