1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SdGenericDrawPage.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.InstCreator
;
40 import util
.SOfficeFactory
;
43 import com
.sun
.star
.container
.XIndexAccess
;
44 import com
.sun
.star
.drawing
.XDrawPage
;
45 import com
.sun
.star
.drawing
.XDrawPages
;
46 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
47 import com
.sun
.star
.drawing
.XShapes
;
48 import com
.sun
.star
.lang
.XComponent
;
49 import com
.sun
.star
.lang
.XMultiServiceFactory
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.drawing.GenericDrawPage</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
61 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
62 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
63 * <li> <code>com::sun::star::drawing::XShapes</code></li>
64 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
65 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
66 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
67 * <li> <code>com::sun::star::container::XElementAccess</code></li>
68 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
69 * <li> <code>com::sun::star::container::XNamed</code></li>
71 * @see com.sun.star.drawing.GenericDrawPage
72 * @see com.sun.star.drawing.XShapeBinder
73 * @see com.sun.star.drawing.XShapeGrouper
74 * @see com.sun.star.drawing.XShapes
75 * @see com.sun.star.lang.XServiceInfo
76 * @see com.sun.star.beans.XPropertySet
77 * @see com.sun.star.container.XIndexAccess
78 * @see com.sun.star.container.XElementAccess
79 * @see com.sun.star.drawing.XShapeCombiner
80 * @see com.sun.star.container.XNamed
81 * @see ifc.drawing._GenericDrawPage
82 * @see ifc.drawing._XShapeBinder
83 * @see ifc.drawing._XShapeGrouper
84 * @see ifc.drawing._XShapes
85 * @see ifc.lang._XServiceInfo
86 * @see ifc.beans._XPropertySet
87 * @see ifc.container._XIndexAccess
88 * @see ifc.container._XElementAccess
89 * @see ifc.drawing._XShapeCombiner
90 * @see ifc.container._XNamed
92 public class SdGenericDrawPage
extends TestCase
{
96 * Creates Drawing document.
98 protected void initialize(TestParameters Param
, PrintWriter log
) {
99 // get a soffice factory object
100 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
101 (XMultiServiceFactory
)Param
.getMSF());
104 log
.println( "creating a draw document" );
105 xDrawDoc
= SOF
.createDrawDoc(null);
106 } catch (com
.sun
.star
.uno
.Exception e
) {
107 // Some exception occures.FAILED
108 e
.printStackTrace(log
);
109 throw new StatusException("Couldn't create document", e
);
114 * Disposes Drawing document.
116 protected void cleanup( TestParameters Param
, PrintWriter log
) {
117 log
.println("disposing xDrawDoc");
118 util
.DesktopTools
.closeDoc(xDrawDoc
);;
122 * Creating a Testenvironment for the interfaces to be tested.
123 * Retrieves the collection of the draw pages from the drawing document using
124 * the interface <code>XDrawPagesSupplier</code> and take one of them.
125 * The retrieved draw page is the instance of the service
126 * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
127 * into the draw page. Creates the rectangle shape.
128 * Object relations created :
130 * <li> <code>'Shape'</code> for
131 * {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
132 * <li> <code>'DrawPage'</code> for
133 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
134 * {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
136 * @see com.sun.star.drawing.DrawPage
137 * @see com.sun.star.drawing.XDrawPagesSupplier
139 protected synchronized TestEnvironment
createTestEnvironment(
140 TestParameters Param
, PrintWriter log
) {
142 XInterface oObj
= null;
143 XShapes oShapes
= null;
145 // creation of testobject here
146 // first we write what we are intend to do to log file
147 log
.println( "creating a test environment" );
148 // get a soffice factory object
149 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
150 (XMultiServiceFactory
)Param
.getMSF());
152 // get the drawpage of drawing here
153 log
.println( "getting Drawpage" );
154 XDrawPagesSupplier oDPS
= (XDrawPagesSupplier
)
155 UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
156 XDrawPages oDPn
= oDPS
.getDrawPages();
157 XIndexAccess oDPi
= (XIndexAccess
) UnoRuntime
.queryInterface
158 (XIndexAccess
.class,oDPn
);
160 oObj
= (XDrawPage
) AnyConverter
.toObject(
161 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
162 } catch(com
.sun
.star
.uno
.Exception e
) {
163 e
.printStackTrace( log
);
164 throw new StatusException("Couldn't get DrawPage", e
);
167 //put something on the drawpage
168 log
.println( "inserting some Shapes" );
169 oShapes
= (XShapes
) UnoRuntime
.queryInterface(XShapes
.class,oObj
);
170 oShapes
.add(SOF
.createShape
171 (xDrawDoc
, 2000, 1500, 1000, 1000, "Line"));
172 oShapes
.add(SOF
.createShape
173 (xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse"));
174 oShapes
.add(SOF
.createShape
175 (xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle"));
177 log
.println( "creating a new environment for drawpage object" );
178 TestEnvironment tEnv
= new TestEnvironment( oObj
);
180 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
181 log
.println( "adding Shape as mod relation to environment" );
182 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
184 // adding relation for XShapeGrouper
185 tEnv
.addObjRelation("DrawPage", oObj
);
188 } // finish method createTestEnvironment
191 } // finish class SdGenericDrawPage