bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxDrawPage.java
blob8439e531441a9199a27765067fb83a5eba9bbd91
1 /*
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 .
18 package mod._svx;
20 import com.sun.star.drawing.XDrawPage;
21 import com.sun.star.drawing.XDrawPages;
22 import com.sun.star.drawing.XDrawPagesSupplier;
23 import com.sun.star.drawing.XShape;
24 import com.sun.star.lang.XComponent;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.sheet.XSpreadsheetDocument;
27 import com.sun.star.uno.AnyConverter;
28 import com.sun.star.uno.Type;
29 import com.sun.star.uno.UnoRuntime;
30 import com.sun.star.uno.XInterface;
32 import java.io.PrintWriter;
34 import lib.StatusException;
35 import lib.TestCase;
36 import lib.TestEnvironment;
37 import lib.TestParameters;
39 import util.DrawTools;
40 import util.FormTools;
41 import util.InstCreator;
42 import util.SOfficeFactory;
43 import util.ShapeDsc;
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.drawing.DrawPage</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
53 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
54 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
55 * <li> <code>com::sun::star::drawing::XShapes</code></li>
56 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
57 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
58 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
59 * <li> <code>com::sun::star::container::XElementAccess</code></li>
60 * <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
61 * <li> <code>com::sun::star::container::XNamed</code></li>
62 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
63 * </ul> <p>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
68 * @see com.sun.star.drawing.GenericDrawPage
69 * @see com.sun.star.drawing.XShapeBinder
70 * @see com.sun.star.drawing.XShapeGrouper
71 * @see com.sun.star.drawing.XShapes
72 * @see com.sun.star.lang.XServiceInfo
73 * @see com.sun.star.beans.XPropertySet
74 * @see com.sun.star.container.XIndexAccess
75 * @see com.sun.star.container.XElementAccess
76 * @see com.sun.star.drawing.XMasterPageTarget
77 * @see com.sun.star.container.XNamed
78 * @see com.sun.star.drawing.XShapeCombiner
79 * @see ifc.drawing._GenericDrawPage
80 * @see ifc.drawing._XShapeBinder
81 * @see ifc.drawing._XShapeGrouper
82 * @see ifc.drawing._XShapes
83 * @see ifc.lang._XServiceInfo
84 * @see ifc.beans._XPropertySet
85 * @see ifc.container._XIndexAccess
86 * @see ifc.container._XElementAccess
87 * @see ifc.drawing._XMasterPageTarget
88 * @see ifc.container._XNamed
89 * @see ifc.drawing._XShapeCombiner
91 public class SvxDrawPage extends TestCase {
92 static XSpreadsheetDocument xDoc = null;
94 /**
95 * Creates a new Draw document.
97 protected void initialize(TestParameters tParam, PrintWriter log) {
98 // get a soffice factory object
99 SOfficeFactory SOF = SOfficeFactory.getFactory(
100 (XMultiServiceFactory) tParam.getMSF());
102 try {
103 log.println("creating a sheetdocument");
104 xDoc = SOF.createCalcDoc(null);
105 } catch (com.sun.star.uno.Exception e) {
106 // Some exception occurs.FAILED
107 e.printStackTrace(log);
108 throw new StatusException("Couldn't create document", e);
113 * Disposes the Draw document created before
115 protected void cleanup(TestParameters tParam, PrintWriter log) {
116 log.println(" disposing xSheetDoc ");
117 util.DesktopTools.closeDoc(xDoc);
121 * Creating a Testenvironment for the interfaces to be tested.
122 * From the Draw document created a collection of its draw
123 * pages is obtained. Two new pages are inserted. And one
124 * page is obtained as a testing component. A shape is added
125 * to this page. <p>
127 * Object relations created :
128 * <ul>
129 * <li> <code>'DrawPage'</code> for
130 * {@link ifc.drawing._XShapeGrouper} :
131 * the draw page tested. </li>
132 * <li> <code>'Shape'</code> for
133 * {@link ifc.drawing._XShapes} :
134 * the creator which can create instances of
135 * <code>com.sun.star.drawing.Line</code> service </li>
136 * </ul>
138 protected TestEnvironment createTestEnvironment(TestParameters tParam,
139 PrintWriter log) {
140 XInterface oObj = null;
141 XShape oShape = null;
142 XDrawPages oDP = null;
144 XComponent xComp = UnoRuntime.queryInterface(
145 XComponent.class, xDoc);
148 // creation of testobject here
149 // first we write what we are intend to do to log file
150 log.println("creating a test environment");
152 try {
153 log.println("getting Drawpages");
155 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(
156 XDrawPagesSupplier.class, xDoc);
157 oDP = oDPS.getDrawPages();
158 oDP.insertNewByIndex(1);
159 oDP.insertNewByIndex(2);
160 oObj = (XDrawPage) AnyConverter.toObject(new Type(XDrawPage.class),
161 oDP.getByIndex(0));
163 SOfficeFactory SOF = SOfficeFactory.getFactory(
164 (XMultiServiceFactory) tParam.getMSF());
166 oShape = SOF.createShape(xComp, 5000, 3500, 7500, 5000,
167 "Rectangle");
168 DrawTools.getShapes((XDrawPage) oObj).add(oShape);
170 XShape oShape1 = SOF.createShape(xComp, 5000, 5500, 5000, 5000,
171 "Rectangle");
172 DrawTools.getShapes((XDrawPage) oObj).add(oShape1);
173 } catch (com.sun.star.lang.WrappedTargetException e) {
174 log.println("Couldn't create insance");
175 e.printStackTrace(log);
176 throw new StatusException("Can't create enviroment", e);
177 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
178 log.println("Couldn't create insance");
179 e.printStackTrace(log);
180 throw new StatusException("Can't create enviroment", e);
181 } catch (com.sun.star.lang.IllegalArgumentException e) {
182 log.println("Couldn't create insance");
183 e.printStackTrace(log);
184 throw new StatusException("Can't create enviroment", e);
187 // create test environment here
188 TestEnvironment tEnv = new TestEnvironment(oObj);
191 //adding a controlButton to have a Form
192 FormTools.insertControlShape(
193 UnoRuntime.queryInterface(XComponent.class, xDoc),
194 3000, 4500, 15000, 1000, "CommandButton");
196 // relation for XShapes interface
197 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Line");
198 tEnv.addObjRelation("Shape", new InstCreator(xDoc, sDsc));
200 log.println("ImplementationName: " + util.utils.getImplName(oObj));
203 // adding relation for XShapeGrouper
204 tEnv.addObjRelation("DrawPage", oObj);
206 // adding relation for XMasterPageTarget
208 /*XMasterPagesSupplier oMPS = (XMasterPagesSupplier)
209 UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDoc);
210 XDrawPages oGroup = oMPS.getMasterPages();
211 tEnv.addObjRelation("MasterPageSupplier",oGroup); */
212 return tEnv;
213 } // finish method getTestEnvironment
214 } // finish class SvxDrawPage