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
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.FormTools
;
28 import util
.InstCreator
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.container
.XIndexAccess
;
33 import com
.sun
.star
.drawing
.XControlShape
;
34 import com
.sun
.star
.drawing
.XDrawPage
;
35 import com
.sun
.star
.drawing
.XDrawPages
;
36 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
37 import com
.sun
.star
.drawing
.XMasterPagesSupplier
;
38 import com
.sun
.star
.drawing
.XShapes
;
39 import com
.sun
.star
.lang
.XComponent
;
40 import com
.sun
.star
.lang
.XMultiServiceFactory
;
41 import com
.sun
.star
.uno
.AnyConverter
;
42 import com
.sun
.star
.uno
.Type
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * Test for object which is represented by service
48 * <code>com.sun.star.drawing.DrawPage</code>. <p>
49 * Object implements the following interfaces :
51 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
52 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
53 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
54 * <li> <code>com::sun::star::drawing::XShapes</code></li>
55 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
56 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
57 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
58 * <li> <code>com::sun::star::container::XElementAccess</code></li>
59 * <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
60 * <li> <code>com::sun::star::container::XNamed</code></li>
61 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
63 * @see com.sun.star.drawing.DrawPage
64 * @see com.sun.star.drawing.GenericDrawPage
65 * @see com.sun.star.drawing.XShapeBinder
66 * @see com.sun.star.drawing.XShapeGrouper
67 * @see com.sun.star.drawing.XShapes
68 * @see com.sun.star.lang.XServiceInfo
69 * @see com.sun.star.beans.XPropertySet
70 * @see com.sun.star.container.XIndexAccess
71 * @see com.sun.star.container.XElementAccess
72 * @see com.sun.star.drawing.XMasterPageTarget
73 * @see com.sun.star.container.XNamed
74 * @see com.sun.star.drawing.XShapeCombiner
75 * @see ifc.drawing._GenericDrawPage
76 * @see ifc.drawing._XShapeBinder
77 * @see ifc.drawing._XShapeGrouper
78 * @see ifc.drawing._XShapes
79 * @see ifc.lang._XServiceInfo
80 * @see ifc.beans._XPropertySet
81 * @see ifc.container._XIndexAccess
82 * @see ifc.container._XElementAccess
83 * @see ifc.drawing._XMasterPageTarget
84 * @see ifc.container._XNamed
85 * @see ifc.drawing._XShapeCombiner
87 public class SdDrawPage
extends TestCase
{
91 * Creates Drawing document.
93 protected void initialize(TestParameters Param
, PrintWriter log
) {
94 // get a soffice factory object
95 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
96 (XMultiServiceFactory
)Param
.getMSF());
99 log
.println( "creating a draw document" );
100 xDrawDoc
= SOF
.createDrawDoc(null);
101 } catch (com
.sun
.star
.uno
.Exception e
) {
102 // Some exception occurs.FAILED
103 e
.printStackTrace( log
);
104 throw new StatusException( "Couldn't create document", e
);
109 * Disposes Drawing document.
111 protected void cleanup( TestParameters Param
, PrintWriter log
) {
112 log
.println("disposing xDrawDoc");
113 util
.DesktopTools
.closeDoc(xDrawDoc
);
117 * Creating a Testenvironment for the interfaces to be tested.
118 * Retrieves the collection of the draw pages from the drawing document using
119 * the interface <code>XDrawPagesSupplier</code> and take one of them.
120 * The retrieved draw page is the instance of the service
121 * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
122 * into the draw page. Obtains the MasterPages collection. Creates
123 * the rectangle shape.
124 * Object relations created :
126 * <li> <code>'Shape'</code> for
127 * {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
128 * <li> <code>'DrawPage'</code> for
129 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
130 * {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
131 * <li> <code>'MasterPageSupplier'</code> for
132 * {@link ifc.drawing._XMasterPageTarget}(the obtained master pages
135 * @see com.sun.star.drawing.DrawPage
136 * @see com.sun.star.drawing.XDrawPagesSupplier
138 protected synchronized TestEnvironment
createTestEnvironment(
139 TestParameters Param
, PrintWriter log
) {
141 XInterface oObj
= null;
143 // creation of testobject here
144 // first we write what we are intend to do to log file
145 log
.println( "creating a test environment" );
147 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
148 (XMultiServiceFactory
)Param
.getMSF());
150 // get the drawpage of drawing here
151 log
.println( "getting Drawpage" );
152 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xDrawDoc
);
153 XDrawPages oDPn
= oDPS
.getDrawPages();
154 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,oDPn
);
156 oObj
= (XDrawPage
) AnyConverter
.toObject(
157 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
158 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
159 e
.printStackTrace( log
);
160 throw new StatusException( "Couldn't get DrawPage", e
);
161 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
162 e
.printStackTrace( log
);
163 throw new StatusException( "Couldn't get DrawPage", e
);
164 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
165 e
.printStackTrace( log
);
166 throw new StatusException( "Couldn't get DrawPage", e
);
169 //put something on the drawpage
170 log
.println( "inserting some Shapes" );
171 XShapes oShapes
= UnoRuntime
.queryInterface
172 (XShapes
.class,oObj
);
173 oShapes
.add(SOF
.createShape
174 (xDrawDoc
, 2000, 1500, 1000, 1000, "Line"));
175 oShapes
.add(SOF
.createShape
176 (xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse"));
177 oShapes
.add(SOF
.createShape
178 (xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle"));
180 //get the XMasterPagesSupplier
181 log
.println("get XMasterPagesSupplier");
182 XMasterPagesSupplier oMPS
= UnoRuntime
.queryInterface(XMasterPagesSupplier
.class, xDrawDoc
);
183 XDrawPages oGroup
= oMPS
.getMasterPages();
185 log
.println( "creating a new environment for drawpage object" );
186 TestEnvironment tEnv
= new TestEnvironment( oObj
);
188 XControlShape aShape
= FormTools
.createControlShape(
189 xDrawDoc
,3000,4500,15000,10000,"CommandButton");
193 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
194 log
.println( "adding Shape as mod relation to environment" );
195 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
196 tEnv
.addObjRelation("DrawPage", oObj
);
197 tEnv
.addObjRelation("MasterPageSupplier",oGroup
);
200 } // finish method createTestEnvironment
202 } // finish class SdDrawPage