Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdGenericDrawPage.java
blob5c3d4163943313d762d0da31ec8a64a906783316
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.InstCreator;
28 import util.SOfficeFactory;
29 import util.ShapeDsc;
31 import com.sun.star.container.XIndexAccess;
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.XShapes;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.uno.AnyConverter;
38 import com.sun.star.uno.Type;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
42 /**
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.GenericDrawPage</code>. <p>
45 * Object implements the following interfaces :
46 * <ul>
47 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
48 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
49 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
50 * <li> <code>com::sun::star::drawing::XShapes</code></li>
51 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
52 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
54 * <li> <code>com::sun::star::container::XElementAccess</code></li>
55 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
56 * <li> <code>com::sun::star::container::XNamed</code></li>
57 * </ul>
58 * @see com.sun.star.drawing.GenericDrawPage
59 * @see com.sun.star.drawing.XShapeBinder
60 * @see com.sun.star.drawing.XShapeGrouper
61 * @see com.sun.star.drawing.XShapes
62 * @see com.sun.star.lang.XServiceInfo
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.container.XIndexAccess
65 * @see com.sun.star.container.XElementAccess
66 * @see com.sun.star.drawing.XShapeCombiner
67 * @see com.sun.star.container.XNamed
68 * @see ifc.drawing._GenericDrawPage
69 * @see ifc.drawing._XShapeBinder
70 * @see ifc.drawing._XShapeGrouper
71 * @see ifc.drawing._XShapes
72 * @see ifc.lang._XServiceInfo
73 * @see ifc.beans._XPropertySet
74 * @see ifc.container._XIndexAccess
75 * @see ifc.container._XElementAccess
76 * @see ifc.drawing._XShapeCombiner
77 * @see ifc.container._XNamed
79 public class SdGenericDrawPage extends TestCase {
80 XComponent xDrawDoc;
82 /**
83 * Creates Drawing document.
85 @Override
86 protected void initialize(TestParameters Param, PrintWriter log) {
87 // get a soffice factory object
88 SOfficeFactory SOF = SOfficeFactory.getFactory(
89 Param.getMSF());
91 try {
92 log.println( "creating a draw document" );
93 xDrawDoc = SOF.createDrawDoc(null);
94 } catch (com.sun.star.uno.Exception e) {
95 // Some exception occurs.FAILED
96 e.printStackTrace(log);
97 throw new StatusException("Couldn't create document", e);
102 * Disposes Drawing document.
104 @Override
105 protected void cleanup( TestParameters Param, PrintWriter log) {
106 log.println("disposing xDrawDoc");
107 util.DesktopTools.closeDoc(xDrawDoc);
111 * Creating a Testenvironment for the interfaces to be tested.
112 * Retrieves the collection of the draw pages from the drawing document using
113 * the interface <code>XDrawPagesSupplier</code> and take one of them.
114 * The retrieved draw page is the instance of the service
115 * <code>com.sun.star.drawing.DrawPage</code>. Inserts some shapes
116 * into the draw page. Creates the rectangle shape.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'Shape'</code> for
120 * {@link ifc.drawing._XShapes}( the created rectangle shape )</li>
121 * <li> <code>'DrawPage'</code> for
122 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
123 * {@link ifc.drawing._XShapeCombiner}( the retrieved draw page )</li>
124 * </ul>
125 * @see com.sun.star.drawing.DrawPage
126 * @see com.sun.star.drawing.XDrawPagesSupplier
128 @Override
129 protected synchronized TestEnvironment createTestEnvironment(
130 TestParameters Param, PrintWriter log) {
132 XInterface oObj = null;
133 XShapes oShapes = null;
135 // creation of testobject here
136 // first we write what we are intend to do to log file
137 log.println( "creating a test environment" );
138 // get a soffice factory object
139 SOfficeFactory SOF = SOfficeFactory.getFactory(
140 Param.getMSF());
142 // get the drawpage of drawing here
143 log.println( "getting Drawpage" );
144 XDrawPagesSupplier oDPS = UnoRuntime.queryInterface(XDrawPagesSupplier.class,xDrawDoc);
145 XDrawPages oDPn = oDPS.getDrawPages();
146 XIndexAccess oDPi = UnoRuntime.queryInterface
147 (XIndexAccess.class,oDPn);
148 try {
149 oObj = (XDrawPage) AnyConverter.toObject(
150 new Type(XDrawPage.class),oDPi.getByIndex(0));
151 } catch(com.sun.star.uno.Exception e) {
152 e.printStackTrace( log );
153 throw new StatusException("Couldn't get DrawPage", e);
156 //put something on the drawpage
157 log.println( "inserting some Shapes" );
158 oShapes = UnoRuntime.queryInterface(XShapes.class,oObj);
159 oShapes.add(SOF.createShape
160 (xDrawDoc, 2000, 1500, 1000, 1000, "Line"));
161 oShapes.add(SOF.createShape
162 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"));
163 oShapes.add(SOF.createShape
164 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"));
166 log.println( "creating a new environment for drawpage object" );
167 TestEnvironment tEnv = new TestEnvironment( oObj );
169 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
170 log.println( "adding Shape as mod relation to environment" );
171 tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc));
173 // adding relation for XShapeGrouper
174 tEnv.addObjRelation("DrawPage", oObj);
176 return tEnv;
177 } // finish method createTestEnvironment
180 } // finish class SdGenericDrawPage