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
.InstCreator
;
28 import util
.SOfficeFactory
;
31 import com
.sun
.star
.container
.XIndexAccess
;
32 import com
.sun
.star
.drawing
.XDrawPage
;
33 import com
.sun
.star
.drawing
.XDrawPages
;
34 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
35 import com
.sun
.star
.drawing
.XShapes
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.uno
.AnyConverter
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.drawing.GenericDrawPage</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
49 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
50 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
51 * <li> <code>com::sun::star::drawing::XShapes</code></li>
52 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
55 * <li> <code>com::sun::star::container::XElementAccess</code></li>
56 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
57 * <li> <code>com::sun::star::container::XNamed</code></li>
59 * @see com.sun.star.drawing.GenericDrawPage
60 * @see com.sun.star.drawing.XShapeBinder
61 * @see com.sun.star.drawing.XShapeGrouper
62 * @see com.sun.star.drawing.XShapes
63 * @see com.sun.star.lang.XServiceInfo
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.container.XIndexAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.drawing.XShapeCombiner
68 * @see com.sun.star.container.XNamed
69 * @see ifc.drawing._GenericDrawPage
70 * @see ifc.drawing._XShapeBinder
71 * @see ifc.drawing._XShapeGrouper
72 * @see ifc.drawing._XShapes
73 * @see ifc.lang._XServiceInfo
74 * @see ifc.beans._XPropertySet
75 * @see ifc.container._XIndexAccess
76 * @see ifc.container._XElementAccess
77 * @see ifc.drawing._XShapeCombiner
78 * @see ifc.container._XNamed
80 public class SdGenericDrawPage
extends TestCase
{
84 * Creates Drawing document.
86 protected void initialize(TestParameters Param
, PrintWriter log
) {
87 // get a soffice factory object
88 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
89 (XMultiServiceFactory
)Param
.getMSF());
92 log
.println( "creating a draw document" );
93 xDrawDoc
= SOF
.createDrawDoc(null);
94 } catch (com
.sun
.star
.uno
.Exception e
) {
95 // Some exception occurs.FAILED
96 e
.printStackTrace(log
);
97 throw new StatusException("Couldn't create document", e
);
102 * Disposes Drawing document.
104 protected void cleanup( TestParameters Param
, PrintWriter log
) {
105 log
.println("disposing xDrawDoc");
106 util
.DesktopTools
.closeDoc(xDrawDoc
);
110 * Creating a Testenvironment for the interfaces to be tested.
111 * Retrieves the collection of the draw pages from the drawing document using
112 * the interface <code>XDrawPagesSupplier</code> and take one of them.
113 * The retrieved draw page is the instance of the service
114 * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
115 * into the draw page. Creates the rectangle shape.
116 * Object relations created :
118 * <li> <code>'Shape'</code> for
119 * {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
120 * <li> <code>'DrawPage'</code> for
121 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
122 * {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
124 * @see com.sun.star.drawing.DrawPage
125 * @see com.sun.star.drawing.XDrawPagesSupplier
127 protected synchronized TestEnvironment
createTestEnvironment(
128 TestParameters Param
, PrintWriter log
) {
130 XInterface oObj
= null;
131 XShapes oShapes
= null;
133 // creation of testobject here
134 // first we write what we are intend to do to log file
135 log
.println( "creating a test environment" );
136 // get a soffice factory object
137 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
138 (XMultiServiceFactory
)Param
.getMSF());
140 // get the drawpage of drawing here
141 log
.println( "getting Drawpage" );
142 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
143 XDrawPages oDPn
= oDPS
.getDrawPages();
144 XIndexAccess oDPi
= UnoRuntime
.queryInterface
145 (XIndexAccess
.class,oDPn
);
147 oObj
= (XDrawPage
) AnyConverter
.toObject(
148 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
149 } catch(com
.sun
.star
.uno
.Exception e
) {
150 e
.printStackTrace( log
);
151 throw new StatusException("Couldn't get DrawPage", e
);
154 //put something on the drawpage
155 log
.println( "inserting some Shapes" );
156 oShapes
= UnoRuntime
.queryInterface(XShapes
.class,oObj
);
157 oShapes
.add(SOF
.createShape
158 (xDrawDoc
, 2000, 1500, 1000, 1000, "Line"));
159 oShapes
.add(SOF
.createShape
160 (xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse"));
161 oShapes
.add(SOF
.createShape
162 (xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle"));
164 log
.println( "creating a new environment for drawpage object" );
165 TestEnvironment tEnv
= new TestEnvironment( oObj
);
167 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
168 log
.println( "adding Shape as mod relation to environment" );
169 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
171 // adding relation for XShapeGrouper
172 tEnv
.addObjRelation("DrawPage", oObj
);
175 } // finish method createTestEnvironment
178 } // finish class SdGenericDrawPage