Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdDrawPage.java
blobe40efd57048d3672dafb481e862ea6fadaf82ad5
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 .
19 package mod._sd;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.FormTools;
28 import util.InstCreator;
29 import util.SOfficeFactory;
30 import util.ShapeDsc;
32 import com.sun.star.container.XIndexAccess;
33 import com.sun.star.drawing.XControlShape;
34 import com.sun.star.drawing.XDrawPage;
35 import com.sun.star.drawing.XDrawPages;
36 import com.sun.star.drawing.XDrawPagesSupplier;
37 import com.sun.star.drawing.XMasterPagesSupplier;
38 import com.sun.star.drawing.XShapes;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.uno.AnyConverter;
41 import com.sun.star.uno.Type;
42 import com.sun.star.uno.UnoRuntime;
43 import com.sun.star.uno.XInterface;
45 /**
46 * Test for object which is represented by service
47 * <code>com.sun.star.drawing.DrawPage</code>. <p>
48 * Object implements the following interfaces :
49 * <ul>
50 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
51 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
52 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
53 * <li> <code>com::sun::star::drawing::XShapes</code></li>
54 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
55 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
56 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
57 * <li> <code>com::sun::star::container::XElementAccess</code></li>
58 * <li> <code>com::sun::star::drawing::XMasterPageTarget</code></li>
59 * <li> <code>com::sun::star::container::XNamed</code></li>
60 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
61 * </ul>
62 * @see com.sun.star.drawing.DrawPage
63 * @see com.sun.star.drawing.GenericDrawPage
64 * @see com.sun.star.drawing.XShapeBinder
65 * @see com.sun.star.drawing.XShapeGrouper
66 * @see com.sun.star.drawing.XShapes
67 * @see com.sun.star.lang.XServiceInfo
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.container.XIndexAccess
70 * @see com.sun.star.container.XElementAccess
71 * @see com.sun.star.drawing.XMasterPageTarget
72 * @see com.sun.star.container.XNamed
73 * @see com.sun.star.drawing.XShapeCombiner
74 * @see ifc.drawing._GenericDrawPage
75 * @see ifc.drawing._XShapeBinder
76 * @see ifc.drawing._XShapeGrouper
77 * @see ifc.drawing._XShapes
78 * @see ifc.lang._XServiceInfo
79 * @see ifc.beans._XPropertySet
80 * @see ifc.container._XIndexAccess
81 * @see ifc.container._XElementAccess
82 * @see ifc.drawing._XMasterPageTarget
83 * @see ifc.container._XNamed
84 * @see ifc.drawing._XShapeCombiner
86 public class SdDrawPage extends TestCase {
87 XComponent xDrawDoc;
89 /**
90 * Creates Drawing document.
92 @Override
93 protected void initialize(TestParameters Param, PrintWriter log) {
94 // get a soffice factory object
95 SOfficeFactory SOF = SOfficeFactory.getFactory(
96 Param.getMSF());
98 try {
99 log.println( "creating a draw document" );
100 xDrawDoc = SOF.createDrawDoc(null);
101 } catch (com.sun.star.uno.Exception e) {
102 // Some exception occurs.FAILED
103 e.printStackTrace( log );
104 throw new StatusException( "Couldn't create document", e );
109 * Disposes Drawing document.
111 @Override
112 protected void cleanup( TestParameters Param, PrintWriter log) {
113 log.println("disposing xDrawDoc");
114 util.DesktopTools.closeDoc(xDrawDoc);
118 * Creating a Testenvironment for the interfaces to be tested.
119 * Retrieves the collection of the draw pages from the drawing document using
120 * the interface <code>XDrawPagesSupplier</code> and take one of them.
121 * The retrieved draw page is the instance of the service
122 * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
123 * into the draw page. Obtains the MasterPages collection. Creates
124 * the rectangle shape.
125 * Object relations created :
126 * <ul>
127 * <li> <code>'Shape'</code> for
128 * {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
129 * <li> <code>'DrawPage'</code> for
130 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
131 * {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
132 * <li> <code>'MasterPageSupplier'</code> for
133 * {@link ifc.drawing._XMasterPageTarget}(the obtained master pages
134 * collection)</li>
135 * </ul>
136 * @see com.sun.star.drawing.DrawPage
137 * @see com.sun.star.drawing.XDrawPagesSupplier
139 @Override
140 protected synchronized TestEnvironment createTestEnvironment(
141 TestParameters Param, PrintWriter log) {
143 XInterface oObj = 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" );
149 SOfficeFactory SOF = SOfficeFactory.getFactory(
150 Param.getMSF());
152 // get the drawpage of drawing here
153 log.println( "getting Drawpage" );
154 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
155 XDrawPages oDPn = oDPS.getDrawPages();
156 XIndexAccess oDPi = UnoRuntime.queryInterface(XIndexAccess.class,oDPn);
157 try {
158 oObj = (XDrawPage) AnyConverter.toObject(
159 new Type(XDrawPage.class),oDPi.getByIndex(0));
160 } catch (com.sun.star.lang.WrappedTargetException e) {
161 e.printStackTrace( log );
162 throw new StatusException( "Couldn't get DrawPage", e );
163 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
164 e.printStackTrace( log );
165 throw new StatusException( "Couldn't get DrawPage", e );
166 } catch (com.sun.star.lang.IllegalArgumentException e) {
167 e.printStackTrace( log );
168 throw new StatusException( "Couldn't get DrawPage", e );
171 //put something on the drawpage
172 log.println( "inserting some Shapes" );
173 XShapes oShapes = UnoRuntime.queryInterface
174 (XShapes.class,oObj);
175 oShapes.add(SOF.createShape
176 (xDrawDoc, 2000, 1500, 1000, 1000, "Line"));
177 oShapes.add(SOF.createShape
178 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"));
179 oShapes.add(SOF.createShape
180 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"));
182 //get the XMasterPagesSupplier
183 log.println("get XMasterPagesSupplier");
184 XMasterPagesSupplier oMPS = UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDrawDoc);
185 XDrawPages oGroup = oMPS.getMasterPages();
187 log.println( "creating a new environment for drawpage object" );
188 TestEnvironment tEnv = new TestEnvironment( oObj );
190 XControlShape aShape = FormTools.createControlShape(
191 xDrawDoc,3000,4500,15000,10000,"CommandButton");
193 oShapes.add(aShape);
195 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
196 log.println( "adding Shape as mod relation to environment" );
197 tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc));
198 tEnv.addObjRelation("DrawPage", oObj);
199 tEnv.addObjRelation("MasterPageSupplier",oGroup);
201 return tEnv;
202 } // finish method createTestEnvironment
204 } // finish class SdDrawPage