Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxDrawPage.java
blob26cb0bcf291e450e8c7c4ac8c8de252845e742ec
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.sheet.XSpreadsheetDocument;
26 import com.sun.star.uno.AnyConverter;
27 import com.sun.star.uno.Type;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
31 import java.io.PrintWriter;
33 import lib.StatusException;
34 import lib.TestCase;
35 import lib.TestEnvironment;
36 import lib.TestParameters;
38 import util.DrawTools;
39 import util.FormTools;
40 import util.InstCreator;
41 import util.SOfficeFactory;
42 import util.ShapeDsc;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.drawing.DrawPage</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
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>
62 * </ul> <p>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
67 * @see com.sun.star.drawing.GenericDrawPage
68 * @see com.sun.star.drawing.XShapeBinder
69 * @see com.sun.star.drawing.XShapeGrouper
70 * @see com.sun.star.drawing.XShapes
71 * @see com.sun.star.lang.XServiceInfo
72 * @see com.sun.star.beans.XPropertySet
73 * @see com.sun.star.container.XIndexAccess
74 * @see com.sun.star.container.XElementAccess
75 * @see com.sun.star.drawing.XMasterPageTarget
76 * @see com.sun.star.container.XNamed
77 * @see com.sun.star.drawing.XShapeCombiner
78 * @see ifc.drawing._GenericDrawPage
79 * @see ifc.drawing._XShapeBinder
80 * @see ifc.drawing._XShapeGrouper
81 * @see ifc.drawing._XShapes
82 * @see ifc.lang._XServiceInfo
83 * @see ifc.beans._XPropertySet
84 * @see ifc.container._XIndexAccess
85 * @see ifc.container._XElementAccess
86 * @see ifc.drawing._XMasterPageTarget
87 * @see ifc.container._XNamed
88 * @see ifc.drawing._XShapeCombiner
90 public class SvxDrawPage extends TestCase {
91 static XSpreadsheetDocument xDoc = null;
93 /**
94 * Creates a new Draw document.
96 @Override
97 protected void initialize(TestParameters tParam, PrintWriter log) {
98 // get a soffice factory object
99 SOfficeFactory SOF = SOfficeFactory.getFactory(
100 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 @Override
116 protected void cleanup(TestParameters tParam, PrintWriter log) {
117 log.println(" disposing xSheetDoc ");
118 util.DesktopTools.closeDoc(xDoc);
122 * Creating a Testenvironment for the interfaces to be tested.
123 * From the Draw document created a collection of its draw
124 * pages is obtained. Two new pages are inserted. And one
125 * page is obtained as a testing component. A shape is added
126 * to this page. <p>
128 * Object relations created :
129 * <ul>
130 * <li> <code>'DrawPage'</code> for
131 * {@link ifc.drawing._XShapeGrouper} :
132 * the draw page tested. </li>
133 * <li> <code>'Shape'</code> for
134 * {@link ifc.drawing._XShapes} :
135 * the creator which can create instances of
136 * <code>com.sun.star.drawing.Line</code> service </li>
137 * </ul>
139 @Override
140 protected TestEnvironment createTestEnvironment(TestParameters tParam,
141 PrintWriter log) {
142 XInterface oObj = null;
143 XShape oShape = null;
144 XDrawPages oDP = null;
146 XComponent xComp = UnoRuntime.queryInterface(
147 XComponent.class, xDoc);
150 // creation of testobject here
151 // first we write what we are intend to do to log file
152 log.println("creating a test environment");
154 try {
155 log.println("getting Drawpages");
157 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(
158 XDrawPagesSupplier.class, xDoc);
159 oDP = oDPS.getDrawPages();
160 oDP.insertNewByIndex(1);
161 oDP.insertNewByIndex(2);
162 oObj = (XDrawPage) AnyConverter.toObject(new Type(XDrawPage.class),
163 oDP.getByIndex(0));
165 SOfficeFactory SOF = SOfficeFactory.getFactory(
166 tParam.getMSF());
168 oShape = SOF.createShape(xComp, 5000, 3500, 7500, 5000,
169 "Rectangle");
170 DrawTools.getShapes((XDrawPage) oObj).add(oShape);
172 XShape oShape1 = SOF.createShape(xComp, 5000, 5500, 5000, 5000,
173 "Rectangle");
174 DrawTools.getShapes((XDrawPage) oObj).add(oShape1);
175 } catch (com.sun.star.lang.WrappedTargetException e) {
176 log.println("Couldn't create insance");
177 e.printStackTrace(log);
178 throw new StatusException("Can't create environment", e);
179 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
180 log.println("Couldn't create insance");
181 e.printStackTrace(log);
182 throw new StatusException("Can't create environment", e);
183 } catch (com.sun.star.lang.IllegalArgumentException e) {
184 log.println("Couldn't create insance");
185 e.printStackTrace(log);
186 throw new StatusException("Can't create environment", e);
189 // create test environment here
190 TestEnvironment tEnv = new TestEnvironment(oObj);
193 //adding a controlButton to have a Form
194 FormTools.insertControlShape(
195 UnoRuntime.queryInterface(XComponent.class, xDoc),
196 3000, 4500, 15000, 1000, "CommandButton");
198 // relation for XShapes interface
199 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Line");
200 tEnv.addObjRelation("Shape", new InstCreator(xDoc, sDsc));
202 log.println("ImplementationName: " + util.utils.getImplName(oObj));
205 // adding relation for XShapeGrouper
206 tEnv.addObjRelation("DrawPage", oObj);
208 // adding relation for XMasterPageTarget
210 return tEnv;
211 } // finish method getTestEnvironment
212 } // finish class SvxDrawPage