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
;
22 import java
.io
.PrintWriter
;
24 import lib
.StatusException
;
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
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.uno
.UnoRuntime
;
43 import com
.sun
.star
.uno
.XInterface
;
44 import com
.sun
.star
.util
.URL
;
45 import com
.sun
.star
.util
.XURLTransformer
;
47 public class SdUnoSlideView
extends TestCase
{
49 XComponent xImpressDoc
;
50 XComponent xSecondDrawDoc
;
53 * Creates the instance of the service <code>com.sun.star.frame.Desktop</code>.
54 * @see com.sun.star.frame.Desktop
56 protected void initialize(TestParameters Param
, PrintWriter log
) {
57 the_Desk
= UnoRuntime
.queryInterface(
58 XDesktop
.class, DesktopTools
.createDesktop(
59 (XMultiServiceFactory
)Param
.getMSF()) );
63 * Called while disposing a <code>TestEnvironment</code>.
64 * Disposes Impress documents.
65 * @param Param test parameters
66 * @param log writer to log information while testing
68 protected void cleanup( TestParameters Param
, PrintWriter log
) {
69 log
.println("disposing impress documents");
70 util
.DesktopTools
.closeDoc(xImpressDoc
);
71 util
.DesktopTools
.closeDoc(xSecondDrawDoc
);
75 * Creating a Testenvironment for the interfaces to be tested.
76 * Creates two impress documents. After creating of the documents makes short
77 * wait to allow frames to be loaded. Retrieves the collection of the draw pages
78 * from the first document and takes one of them. Inserts some shapes to the
79 * retrieved draw page. Obtains a current controller from the first document
80 * using the interface <code>XModel</code>. The obtained controller is the
81 * instance of the service <code>com.sun.star.presentation.OutlineView</code>.
82 * Object relations created :
84 * <li> <code>'FirstModel'</code> for
85 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
86 * the first created document) </li>
87 * <li> <code>'Frame'</code> for
88 * {@link ifc.frame._XController}(the frame of the created
90 * <li> <code>'SecondModel'</code> for
91 * {@link ifc.frame._XController}(the interface <code>XModel</code> of
92 * the second created document) </li>
93 * <li> <code>'SecondController'</code> for
94 * {@link ifc.frame._XController}(the current controller of the second
95 * created document) </li>
97 * @see com.sun.star.frame.XModel
99 protected synchronized TestEnvironment createTestEnvironment
100 (TestParameters Param
, PrintWriter log
) {
102 log
.println( "creating a test environment" );
104 // get a soffice factory object
105 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)Param
.getMSF());
106 XDrawPages xDP
= null;
108 log
.println( "creating a impress document" );
109 xImpressDoc
= SOF
.createImpressDoc(null);
111 xDP
= DrawTools
.getDrawPages(xImpressDoc
);
112 xDP
.insertNewByIndex(0);
113 xDP
.insertNewByIndex(0);
114 } catch (com
.sun
.star
.uno
.Exception e
) {
115 e
.printStackTrace( log
);
116 throw new StatusException("Couldn't create document", e
);
119 XModel aModel
= UnoRuntime
.queryInterface(XModel
.class, xImpressDoc
);
121 XInterface oObj
= aModel
.getCurrentController();
123 //Change to Slide view
125 String aSlotID
= "slot:27011";
126 XDispatchProvider xDispProv
= UnoRuntime
.queryInterface( XDispatchProvider
.class, oObj
);
127 XURLTransformer xParser
= UnoRuntime
.queryInterface(XURLTransformer
.class,
128 ((XMultiServiceFactory
)Param
.getMSF()).createInstance("com.sun.star.util.URLTransformer"));
129 // Because it's an in/out parameter we must use an array of URL objects.
130 URL
[] aParseURL
= new URL
[1];
131 aParseURL
[0] = new URL();
132 aParseURL
[0].Complete
= aSlotID
;
133 xParser
.parseStrict(aParseURL
);
134 URL aURL
= aParseURL
[0];
135 XDispatch xDispatcher
= xDispProv
.queryDispatch( aURL
,"",0);
136 if( xDispatcher
!= null )
137 xDispatcher
.dispatch( aURL
, null );
138 } catch (com
.sun
.star
.uno
.Exception e
) {
139 log
.println("Couldn't change to slide view");
143 log
.println( "creating a second impress document" );
144 xSecondDrawDoc
= SOF
.createImpressDoc(null);
146 } catch (com
.sun
.star
.uno
.Exception e
) {
147 e
.printStackTrace( log
);
148 throw new StatusException("Couldn't create document", e
);
151 XModel aModel2
= UnoRuntime
.queryInterface(XModel
.class, xSecondDrawDoc
);
153 XWindow anotherWindow
= UnoRuntime
.queryInterface(
154 XWindow
.class,aModel2
.getCurrentController());
156 oObj
= aModel
.getCurrentController();
158 log
.println( "creating a new environment for slide view object" );
159 TestEnvironment tEnv
= new TestEnvironment( oObj
);
161 if (anotherWindow
!= null) {
162 tEnv
.addObjRelation("XWindow.AnotherWindow", anotherWindow
);
165 //Adding ObjRelations for XController
166 tEnv
.addObjRelation("FirstModel", aModel
);
168 XFrame the_frame
= the_Desk
.getCurrentFrame();
169 tEnv
.addObjRelation("Frame", the_frame
);
171 //Adding ObjRelations for XController
172 tEnv
.addObjRelation("SecondModel", aModel2
);
174 XController secondController
= aModel2
.getCurrentController();
175 tEnv
.addObjRelation("SecondController", secondController
);
176 tEnv
.addObjRelation("XDispatchProvider.URL",
179 tEnv
.addObjRelation("XUserInputInterception.XModel", aModel
);
181 //creating obj-relation for the XSelectionSupplier
183 Object
[] selections
=
184 new Object
[]{xDP
.getByIndex(0),xDP
.getByIndex(1),xDP
.getByIndex(2)};
185 tEnv
.addObjRelation("Selections", selections
);
186 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
187 e
.printStackTrace(log
);
188 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
189 e
.printStackTrace(log
);
191 log
.println("Implementation Name: " + utils
.getImplName(oObj
));
195 } // finish method getTestEnvironment
197 private void shortWait() {
200 } catch (InterruptedException e
) {
201 System
.out
.println("While waiting :" + e
) ;
206 } // finish class SdUnoOutlineView