bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdMasterPage.java
blob861ad43fa60df6c8e21b6f626641f97b2e99963f
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.XMasterPagesSupplier;
35 import com.sun.star.drawing.XShapes;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.uno.AnyConverter;
39 import com.sun.star.uno.Type;
40 import com.sun.star.uno.UnoRuntime;
41 import com.sun.star.uno.XInterface;
43 /**
44 * Test for object which is represented by service
45 * <code>com.sun.star.drawing.MasterPage</code>. <p>
46 * Object implements the following interfaces :
47 * <ul>
48 * <li> <code>com::sun::star::drawing::GenericDrawPage</code></li>
49 * <li> <code>com::sun::star::drawing::XShapeBinder</code></li>
50 * <li> <code>com::sun::star::drawing::XShapeGrouper</code></li>
51 * <li> <code>com::sun::star::drawing::XShapes</code></li>
52 * <li> <code>com::sun::star::lang::XServiceInfo</code></li>
53 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
54 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
55 * <li> <code>com::sun::star::container::XElementAccess</code></li>
56 * <li> <code>com::sun::star::drawing::XShapeCombiner</code></li>
57 * <li> <code>com::sun::star::container::XNamed</code></li>
58 * </ul>
59 * @see com.sun.star.drawing.MasterPage
60 * @see com.sun.star.drawing.GenericDrawPage
61 * @see com.sun.star.drawing.XShapeBinder
62 * @see com.sun.star.drawing.XShapeGrouper
63 * @see com.sun.star.drawing.XShapes
64 * @see com.sun.star.lang.XServiceInfo
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.container.XIndexAccess
67 * @see com.sun.star.container.XElementAccess
68 * @see com.sun.star.drawing.XShapeCombiner
69 * @see com.sun.star.container.XNamed
70 * @see ifc.drawing._GenericDrawPage
71 * @see ifc.drawing._XShapeBinder
72 * @see ifc.drawing._XShapeGrouper
73 * @see ifc.drawing._XShapes
74 * @see ifc.lang._XServiceInfo
75 * @see ifc.beans._XPropertySet
76 * @see ifc.container._XIndexAccess
77 * @see ifc.container._XElementAccess
78 * @see ifc.drawing._XShapeCombiner
79 * @see ifc.container._XNamed
81 public class SdMasterPage extends TestCase {
82 XComponent xDrawDoc;
84 /**
85 * Creates Drawing document.
87 protected void initialize(TestParameters Param, PrintWriter log) {
88 // get a soffice factory object
89 SOfficeFactory SOF = SOfficeFactory.getFactory(
90 (XMultiServiceFactory)Param.getMSF());
92 try {
93 log.println( "creating a draw document" );
94 xDrawDoc = SOF.createDrawDoc(null);
95 } catch (com.sun.star.uno.Exception e) {
96 // Some exception occurs.FAILED
97 e.printStackTrace( log );
98 throw new StatusException("Couldn't create document", e);
103 * Disposes Drawing document.
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 master pages from the document using the
113 * interface <code>XMasterPagesSupplier</code> and takes
114 * one of them. Inserts some shapes into the document. Creates a rectangle
115 * shape. The retrieved master page is the instance of the service
116 * <code>com.sun.star.drawing.MasterPage</code>.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'DrawPage'</code> for
120 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
121 * {@link ifc.drawing._XShapeCombiner}( the draw page of the retrieved
122 * master page)</li>
123 * <li> <code>'Shape'</code> for
124 * {@link ifc.drawing._XShapes}(the created rectangle shape)</li>
125 * </ul>
126 * @see com.sun.star.drawing.XMasterPagesSupplier
128 protected TestEnvironment createTestEnvironment(
129 TestParameters Param, PrintWriter log) {
131 log.println( "creating a test environment" );
133 // get the MasterPages here
134 log.println( "getting MasterPages" );
135 XMasterPagesSupplier oMPS = UnoRuntime.queryInterface(XMasterPagesSupplier.class, xDrawDoc);
136 XDrawPages oMPn = oMPS.getMasterPages();
137 XIndexAccess oMPi = UnoRuntime.queryInterface(XIndexAccess.class, oMPn);
139 log.println( "getting MasterPage" );
140 XInterface oObj = null;
141 try {
142 oObj = (XDrawPage) AnyConverter.toObject(
143 new Type(XDrawPage.class),oMPi.getByIndex(0));
144 } catch (com.sun.star.lang.WrappedTargetException e) {
145 e.printStackTrace( log );
146 throw new StatusException("Couldn't get MasterPage by index", e);
147 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
148 e.printStackTrace( log );
149 throw new StatusException("Couldn't get MasterPage by index", e);
150 } catch (com.sun.star.lang.IllegalArgumentException e) {
151 e.printStackTrace( log );
152 throw new StatusException("Couldn't get MasterPage by index", e);
155 // get a soffice factory object
156 SOfficeFactory SOF = SOfficeFactory.getFactory(
157 (XMultiServiceFactory)Param.getMSF());
159 //put something on the masterpage
160 log.println( "inserting some Shapes" );
161 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class, oObj);
162 oShapes.add(SOF.createShape(xDrawDoc, 2000, 1500, 1000, 1000, "Line"));
163 oShapes.add(SOF.createShape
164 (xDrawDoc, 3000, 4500, 15000, 1000, "Ellipse"));
165 oShapes.add(SOF.createShape
166 (xDrawDoc, 5000, 3500, 7500, 5000, "Rectangle"));
168 log.println( "creating a new environment for MasterPage object" );
169 TestEnvironment tEnv = new TestEnvironment( oObj );
171 log.println( "adding DrawPage as mod relation to environment" );
172 tEnv.addObjRelation("DrawPage", oObj);
174 ShapeDsc sDsc = new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
175 log.println( "adding Shape as mod relation to environment" );
176 tEnv.addObjRelation("Shape", new InstCreator( xDrawDoc, sDsc));
178 return tEnv;
179 } // finish method createTestEnvironment
181 } // finish class SdMasterPage