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: SvxDrawPage.java,v $
10 * $Revision: 1.8.8.1 $
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 ************************************************************************/
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
.XShape
;
36 import com
.sun
.star
.lang
.XComponent
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
44 import java
.io
.PrintWriter
;
46 import lib
.StatusException
;
48 import lib
.TestEnvironment
;
49 import lib
.TestParameters
;
51 import util
.DrawTools
;
52 import util
.FormTools
;
53 import util
.InstCreator
;
54 import util
.SOfficeFactory
;
59 * Test for object which is represented by service
60 * <code>com.sun.star.drawing.DrawPage</code>. <p>
62 * Object implements the following interfaces :
64 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
65 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
66 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
67 * <li> <code>com::sun::star::drawing::XShapes</code></li>
68 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
69 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
70 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
71 * <li> <code>com::sun::star::container::XElementAccess</code></li>
72 * <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
73 * <li> <code>com::sun::star::container::XNamed</code></li>
74 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
77 * This object test <b> is NOT </b> designed to be run in several
78 * threads concurently.
80 * @see com.sun.star.drawing.GenericDrawPage
81 * @see com.sun.star.drawing.XShapeBinder
82 * @see com.sun.star.drawing.XShapeGrouper
83 * @see com.sun.star.drawing.XShapes
84 * @see com.sun.star.lang.XServiceInfo
85 * @see com.sun.star.beans.XPropertySet
86 * @see com.sun.star.container.XIndexAccess
87 * @see com.sun.star.container.XElementAccess
88 * @see com.sun.star.drawing.XMasterPageTarget
89 * @see com.sun.star.container.XNamed
90 * @see com.sun.star.drawing.XShapeCombiner
91 * @see ifc.drawing._GenericDrawPage
92 * @see ifc.drawing._XShapeBinder
93 * @see ifc.drawing._XShapeGrouper
94 * @see ifc.drawing._XShapes
95 * @see ifc.lang._XServiceInfo
96 * @see ifc.beans._XPropertySet
97 * @see ifc.container._XIndexAccess
98 * @see ifc.container._XElementAccess
99 * @see ifc.drawing._XMasterPageTarget
100 * @see ifc.container._XNamed
101 * @see ifc.drawing._XShapeCombiner
103 public class SvxDrawPage
extends TestCase
{
104 static XSpreadsheetDocument xDoc
= null;
107 * Creates a new Draw document.
109 protected void initialize(TestParameters tParam
, PrintWriter log
) {
110 // get a soffice factory object
111 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
112 (XMultiServiceFactory
) tParam
.getMSF());
115 log
.println("creating a sheetdocument");
116 xDoc
= SOF
.createCalcDoc(null);
117 } catch (com
.sun
.star
.uno
.Exception e
) {
118 // Some exception occures.FAILED
119 e
.printStackTrace(log
);
120 throw new StatusException("Couldn't create document", e
);
125 * Disposes the Draw document created before
127 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
128 log
.println(" disposing xSheetDoc ");
129 util
.DesktopTools
.closeDoc(xDoc
);
134 * Creating a Testenvironment for the interfaces to be tested.
135 * From the Draw document created a collection of its draw
136 * pages is obtained. Two new pages are inserted. And one
137 * page is obtained as a testing component. A shape is added
140 * Object relations created :
142 * <li> <code>'DrawPage'</code> for
143 * {@link ifc.drawing._XShapeGrouper} :
144 * the draw page tested. </li>
145 * <li> <code>'Shape'</code> for
146 * {@link ifc.drawing._XShapes} :
147 * the creator which can create instances of
148 * <code>com.sun.star.drawing.Line</code> service </li>
151 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
153 XInterface oObj
= null;
154 XShape oShape
= null;
155 XDrawPages oDP
= null;
157 XComponent xComp
= (XComponent
) UnoRuntime
.queryInterface(
158 XComponent
.class, xDoc
);
161 // creation of testobject here
162 // first we write what we are intend to do to log file
163 log
.println("creating a test environment");
166 log
.println("getting Drawpages");
168 XDrawPagesSupplier oDPS
= (XDrawPagesSupplier
) UnoRuntime
.queryInterface(
169 XDrawPagesSupplier
.class, xDoc
);
170 oDP
= (XDrawPages
) oDPS
.getDrawPages();
171 oDP
.insertNewByIndex(1);
172 oDP
.insertNewByIndex(2);
173 oObj
= (XDrawPage
) AnyConverter
.toObject(new Type(XDrawPage
.class),
176 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
177 (XMultiServiceFactory
) tParam
.getMSF());
179 oShape
= SOF
.createShape(xComp
, 5000, 3500, 7500, 5000,
181 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape
);
183 XShape oShape1
= SOF
.createShape(xComp
, 5000, 5500, 5000, 5000,
185 DrawTools
.getShapes((XDrawPage
) oObj
).add(oShape1
);
186 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
187 log
.println("Couldn't create insance");
188 e
.printStackTrace(log
);
189 throw new StatusException("Can't create enviroment", e
);
190 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
191 log
.println("Couldn't create insance");
192 e
.printStackTrace(log
);
193 throw new StatusException("Can't create enviroment", e
);
194 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
195 log
.println("Couldn't create insance");
196 e
.printStackTrace(log
);
197 throw new StatusException("Can't create enviroment", e
);
200 // create test environment here
201 TestEnvironment tEnv
= new TestEnvironment(oObj
);
204 //adding a controlButton to have a Form
205 FormTools
.insertControlShape(
206 (XComponent
) UnoRuntime
.queryInterface(XComponent
.class, xDoc
),
207 3000, 4500, 15000, 1000, "CommandButton");
209 // relation for XShapes interface
210 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Line");
211 tEnv
.addObjRelation("Shape", new InstCreator(xDoc
, sDsc
));
213 log
.println("ImplementationName: " + util
.utils
.getImplName(oObj
));
216 // adding relation for XShapeGrouper
217 tEnv
.addObjRelation("DrawPage", oObj
);
219 // adding relation for XMasterPageTarget
221 /*XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
222 UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDoc);
223 XDrawPages oGroup = oMPS.getMasterPages();
224 tEnv.addObjRelation("MasterPageSupplier",oGroup); */
226 } // finish method getTestEnvironment
227 } // finish class SvxDrawPage