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 com
.sun
.star
.drawing
.XDrawPages
;
23 import java
.io
.PrintWriter
;
26 import lib
.TestEnvironment
;
27 import lib
.TestParameters
;
28 import util
.DesktopTools
;
29 import util
.DrawTools
;
30 import util
.SOfficeFactory
;
33 import com
.sun
.star
.awt
.XWindow
;
34 import com
.sun
.star
.frame
.XController
;
35 import com
.sun
.star
.frame
.XDesktop
;
36 import com
.sun
.star
.frame
.XDispatch
;
37 import com
.sun
.star
.frame
.XDispatchProvider
;
38 import com
.sun
.star
.frame
.XFrame
;
39 import com
.sun
.star
.frame
.XModel
;
40 import com
.sun
.star
.lang
.XComponent
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
43 import com
.sun
.star
.util
.URL
;
44 import com
.sun
.star
.util
.XURLTransformer
;
46 public class SdUnoSlideView
extends TestCase
{
48 XComponent xImpressDoc
;
49 XComponent xSecondDrawDoc
;
52 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
53 * @see com.sun.star.frame.Desktop
56 protected void initialize(TestParameters Param
, PrintWriter log
) throws Exception
{
57 xDesktop
= DesktopTools
.createDesktop(Param
.getMSF());
61 * Called while disposing a <code>TestEnvironment</code>.
62 * Disposes Impress documents.
63 * @param Param test parameters
64 * @param log writer to log information while testing
67 protected void cleanup( TestParameters Param
, PrintWriter log
) {
68 log
.println("disposing impress documents");
69 util
.DesktopTools
.closeDoc(xImpressDoc
);
70 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
74 * Creating a TestEnvironment for the interfaces to be tested.
75 * Creates two impress documents. After creating of the documents makes short
76 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
77 * from the first document and takes one of them. Inserts some shapes to the
78 * retrieved draw page. Obtains a current controller from the first document
79 * using the interface <code>XModel</code>. The obtained controller is the
80 * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
81 * Object relations created :
83 * <li> <code>'FirstModel'</code> for
84 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
85 * the first created document) </li>
86 * <li> <code>'Frame'</code> for
87 * {@link ifc.frame._XController}(the frame of the created
89 * <li> <code>'SecondModel'</code> for
90 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
91 * the second created document) </li>
92 * <li> <code>'SecondController'</code> for
93 * {@link ifc.frame._XController}(the current controller of the second
94 * created document) </li>
96 * @see com.sun.star.frame.XModel
99 protected TestEnvironment createTestEnvironment
100 (TestParameters Param
, PrintWriter log
) throws Exception
{
102 log
.println( "creating a test environment" );
104 // get a soffice factory object
105 SOfficeFactory SOF
= SOfficeFactory
.getFactory( Param
.getMSF());
106 XDrawPages xDP
= null;
107 log
.println( "creating an impress document" );
108 xImpressDoc
= SOF
.createImpressDoc(null);
109 util
.utils
.waitForEventIdle(Param
.getMSF());
110 xDP
= DrawTools
.getDrawPages(xImpressDoc
);
111 xDP
.insertNewByIndex(0);
112 xDP
.insertNewByIndex(0);
114 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xImpressDoc
);
116 XInterface oObj
= aModel
.getCurrentController();
118 //Change to Slide view
120 String aSlotID
= "slot:27011";
121 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, oObj
);
122 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
123 Param
.getMSF().createInstance("com.sun.star.util.URLTransformer"));
124 // Because it's an in/out parameter we must use an array of URL objects.
125 URL
[] aParseURL
= new URL
[1];
126 aParseURL
[0] = new URL();
127 aParseURL
[0].Complete
= aSlotID
;
128 xParser
.parseStrict(aParseURL
);
129 URL aURL
= aParseURL
[0];
130 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
131 if( xDispatcher
!= null )
132 xDispatcher
.dispatch( aURL
, null );
133 } catch (com
.sun
.star
.uno
.Exception e
) {
134 log
.println("Couldn't change to slide view");
137 log
.println( "creating a second impress document" );
138 xSecondDrawDoc
= SOF
.createImpressDoc(null);
139 util
.utils
.waitForEventIdle(Param
.getMSF());
141 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
143 XWindow anotherWindow
= UnoRuntime
.queryInterface(
144 XWindow
.class,aModel2
.getCurrentController());
146 oObj
= aModel
.getCurrentController();
148 log
.println( "creating a new environment for slide view object" );
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 if (anotherWindow
!= null) {
152 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
155 //Adding ObjRelations for XController
156 tEnv
.addObjRelation("FirstModel", aModel
);
158 XFrame the_frame
= xDesktop
.getCurrentFrame();
159 tEnv
.addObjRelation("Frame", the_frame
);
161 //Adding ObjRelations for XController
162 tEnv
.addObjRelation("SecondModel", aModel2
);
164 XController secondController
= aModel2
.getCurrentController();
165 tEnv
.addObjRelation("SecondController", secondController
);
166 tEnv
.addObjRelation("XDispatchProvider.URL",
169 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
171 //creating obj-relation for the XSelectionSupplier
173 Object
[] selections
=
174 new Object
[]{xDP
.getByIndex(0),xDP
.getByIndex(1),xDP
.getByIndex(2)};
175 tEnv
.addObjRelation("Selections", selections
);
176 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
177 e
.printStackTrace(log
);
178 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
179 e
.printStackTrace(log
);
181 log
.println("Implementation Name: " + utils
.getImplName(oObj
));
185 } // finish method getTestEnvironment
188 } // finish class SdUnoOutlineView