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
.XIndexAccess
;
29 import com
.sun
.star
.container
.XIndexContainer
;
30 import com
.sun
.star
.container
.XNameContainer
;
31 import com
.sun
.star
.drawing
.XDrawPage
;
32 import com
.sun
.star
.drawing
.XDrawPages
;
33 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XSingleServiceFactory
;
36 import com
.sun
.star
.presentation
.XCustomPresentationSupplier
;
37 import com
.sun
.star
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.presentation.CustomPresentation</code>. <p>
45 * Object implements the following interfaces :
47 * <li> <code>com::sun::star::container::XNamed</code></li>
48 * <li> <code>com::sun::star::container::XIndexContainer</code></li>
49 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
50 * <li> <code>com::sun::star::container::XElementAccess</code></li>
51 * <li> <code>com::sun::star::container::XIndexReplace</code></li>
53 * @see com.sun.star.presentation.CustomPresentation
54 * @see com.sun.star.container.XNamed
55 * @see com.sun.star.container.XIndexContainer
56 * @see com.sun.star.container.XIndexAccess
57 * @see com.sun.star.container.XElementAccess
58 * @see com.sun.star.container.XIndexReplace
59 * @see ifc.container._XNamed
60 * @see ifc.container._XIndexContainer
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XElementAccess
63 * @see ifc.container._XIndexReplace
65 public class SdXCustomPresentation
extends TestCase
{
66 XComponent xImpressDoc
;
69 * Creates Impress document.
72 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
73 // get a soffice factory object
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
76 log
.println( "creating a draw document" );
77 xImpressDoc
= SOF
.createImpressDoc(null);
81 * Disposes Impress document.
84 protected void cleanup( TestParameters Param
, PrintWriter log
) {
85 log
.println("disposing xImpressDoc");
86 util
.DesktopTools
.closeDoc(xImpressDoc
);
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Retrieves the collection of the CustomPresentation from the document
92 * using the interface <code>XCustomPresentationSupplier</code>. Creates and
93 * inserts new instance of the presentation to the collection. The created
94 * instance is the instance of the service
95 * <code>com.sun.star.presentation.CustomPresentation</code>. Obtains
96 * the collection of draw pages from the document and takes one of them.
97 * Inserts the obtained draw page to the created instance. Inserts some new
99 * Object relations created :
101 * <li> <code>'XIndexContainerINDEX'</code> for
102 * {@link ifc.container._XIndexContainer}(the string representation of
104 * <li> <code>'INSTANCE1', ..., 'INSTANCEN'</code> for
105 * {@link ifc.container._XIndexContainer}(the new inserted draw pages)</li>
107 * @see com.sun.star.presentation.XCustomPresentationSupplier
108 * @see com.sun.star.presentation.CustomPresentation
111 protected TestEnvironment
createTestEnvironment(
112 TestParameters Param
, PrintWriter log
) throws Exception
{
115 log
.println( "creating a test environment" );
117 log
.println( "get presentation" );
118 XCustomPresentationSupplier oPS
= UnoRuntime
.queryInterface(
119 XCustomPresentationSupplier
.class, xImpressDoc
);
120 XInterface oObj
= oPS
.getCustomPresentations();
122 XSingleServiceFactory oSingleMSF
= UnoRuntime
.queryInterface(XSingleServiceFactory
.class, oObj
);
124 XInterface oInstance
= (XInterface
) oSingleMSF
.createInstance();
126 XNameContainer aContainer
= UnoRuntime
.queryInterface(XNameContainer
.class, oObj
);
128 aContainer
.insertByName("FirstPresentation", oInstance
);
130 // get the drawpage of drawing here
131 log
.println( "getting Drawpage" );
132 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xImpressDoc
);
133 XDrawPages oDPn
= oDPS
.getDrawPages();
134 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class, oDPn
);
136 XDrawPage oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
137 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
139 XIndexContainer aIContainer
= UnoRuntime
.queryInterface(XIndexContainer
.class,oInstance
);
141 aIContainer
.insertByIndex(0, oDrawPage
);
143 log
.println( "creating a new environment for XPresentation object" );
144 TestEnvironment tEnv
= new TestEnvironment( oInstance
);
147 if ((String
)Param
.get("THRCNT") != null) {
148 THRCNT
= Integer
.parseInt((String
)Param
.get("THRCNT"));
151 // INDEX : _XNameContainer
152 log
.println( "adding XIndexContainerINDEX as mod relation to environment" );
153 tEnv
.addObjRelation("XIndexContainerINDEX", "0");
155 // INSTANCEn : _XNameContainer; _XNameReplace
156 log
.println( "adding INSTANCEn as mod relation to environment" );
157 for (int n
= 1; n
< (2*THRCNT
+1) ;n
++ ) {
158 log
.println( "adding INSTANCE" + n
159 +" as mod relation to environment" );
160 oDPn
.insertNewByIndex(0);
161 oDrawPage
= (XDrawPage
) AnyConverter
.toObject(
162 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
163 tEnv
.addObjRelation("INSTANCE" + n
, oDrawPage
);
168 } // finish method getTestEnvironment
170 } // finish class SdXCustomPresentation