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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.InstCreator
;
28 import util
.SOfficeFactory
;
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
.uno
.AnyConverter
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.drawing.MasterPage</code>. <p>
45 * Object implements the following interfaces :
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>
58 * @see com.sun.star.drawing.MasterPage
59 * @see com.sun.star.drawing.GenericDrawPage
60 * @see com.sun.star.drawing.XShapeBinder
61 * @see com.sun.star.drawing.XShapeGrouper
62 * @see com.sun.star.drawing.XShapes
63 * @see com.sun.star.lang.XServiceInfo
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.container.XIndexAccess
66 * @see com.sun.star.container.XElementAccess
67 * @see com.sun.star.drawing.XShapeCombiner
68 * @see com.sun.star.container.XNamed
69 * @see ifc.drawing._GenericDrawPage
70 * @see ifc.drawing._XShapeBinder
71 * @see ifc.drawing._XShapeGrouper
72 * @see ifc.drawing._XShapes
73 * @see ifc.lang._XServiceInfo
74 * @see ifc.beans._XPropertySet
75 * @see ifc.container._XIndexAccess
76 * @see ifc.container._XElementAccess
77 * @see ifc.drawing._XShapeCombiner
78 * @see ifc.container._XNamed
80 public class SdMasterPage
extends TestCase
{
84 * Creates Drawing document.
87 protected void initialize(TestParameters Param
, PrintWriter log
) {
88 // get a soffice factory object
89 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
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.
106 protected void cleanup( TestParameters Param
, PrintWriter log
) {
107 log
.println("disposing xDrawDoc");
108 util
.DesktopTools
.closeDoc(xDrawDoc
);
112 * Creating a Testenvironment for the interfaces to be tested.
113 * Retrieves the collection of the master pages from the document using the
114 * interface <code>XMasterPagesSupplier</code> and takes
115 * one of them. Inserts some shapes into the document. Creates a rectangle
116 * shape. The retrieved master page is the instance of the service
117 * <code>com.sun.star.drawing.MasterPage</code>.
118 * Object relations created :
120 * <li> <code>'DrawPage'</code> for
121 * {@link ifc.drawing._XShapeBinder}, {@link ifc.drawing._XShapeGrouper},
122 * {@link ifc.drawing._XShapeCombiner}( the draw page of the retrieved
124 * <li> <code>'Shape'</code> for
125 * {@link ifc.drawing._XShapes}(the created rectangle shape)</li>
127 * @see com.sun.star.drawing.XMasterPagesSupplier
130 protected TestEnvironment
createTestEnvironment(
131 TestParameters Param
, PrintWriter log
) {
133 log
.println( "creating a test environment" );
135 // get the MasterPages here
136 log
.println( "getting MasterPages" );
137 XMasterPagesSupplier oMPS
= UnoRuntime
.queryInterface(XMasterPagesSupplier
.class, xDrawDoc
);
138 XDrawPages oMPn
= oMPS
.getMasterPages();
139 XIndexAccess oMPi
= UnoRuntime
.queryInterface(XIndexAccess
.class, oMPn
);
141 log
.println( "getting MasterPage" );
142 XInterface oObj
= null;
144 oObj
= (XDrawPage
) AnyConverter
.toObject(
145 new Type(XDrawPage
.class),oMPi
.getByIndex(0));
146 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
147 e
.printStackTrace( log
);
148 throw new StatusException("Couldn't get MasterPage by index", e
);
149 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
150 e
.printStackTrace( log
);
151 throw new StatusException("Couldn't get MasterPage by index", e
);
152 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
153 e
.printStackTrace( log
);
154 throw new StatusException("Couldn't get MasterPage by index", e
);
157 // get a soffice factory object
158 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
161 //put something on the masterpage
162 log
.println( "inserting some Shapes" );
163 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oObj
);
164 oShapes
.add(SOF
.createShape(xDrawDoc
, 2000, 1500, 1000, 1000, "Line"));
165 oShapes
.add(SOF
.createShape
166 (xDrawDoc
, 3000, 4500, 15000, 1000, "Ellipse"));
167 oShapes
.add(SOF
.createShape
168 (xDrawDoc
, 5000, 3500, 7500, 5000, "Rectangle"));
170 log
.println( "creating a new environment for MasterPage object" );
171 TestEnvironment tEnv
= new TestEnvironment( oObj
);
173 log
.println( "adding DrawPage as mod relation to environment" );
174 tEnv
.addObjRelation("DrawPage", oObj
);
176 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
177 log
.println( "adding Shape as mod relation to environment" );
178 tEnv
.addObjRelation("Shape", new InstCreator( xDrawDoc
, sDsc
));
181 } // finish method createTestEnvironment
183 } // finish class SdMasterPage