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
.XDrawPagesSupplier
;
35 import com
.sun
.star
.drawing
.XLayerSupplier
;
36 import com
.sun
.star
.drawing
.XShapes
;
37 import com
.sun
.star
.lang
.XComponent
;
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
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.drawing.LayerManager</code>. <p>
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::drawing::XLayerManager</code></li>
49 * <li> <code>com::sun::star::container::XNameAccess</code></li>
50 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
51 * <li> <code>com::sun::star::container::XElementAccess</code></li>
53 * @see com.sun.star.drawing.LayerManager
54 * @see com.sun.star.drawing.XLayerManager
55 * @see com.sun.star.container.XNameAccess
56 * @see com.sun.star.container.XIndexAccess
57 * @see com.sun.star.container.XElementAccess
58 * @see ifc.drawing._XLayerManager
59 * @see ifc.container._XNameAccess
60 * @see ifc.container._XIndexAccess
61 * @see ifc.container._XElementAccess
63 public class SdLayerManager
extends TestCase
{
67 * Creates Drawing document.
70 protected void initialize(TestParameters Param
, PrintWriter log
) {
71 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
76 log
.println("creating a draw document");
77 xDrawDoc
= SOF
.createDrawDoc(null);
78 } catch (com
.sun
.star
.uno
.Exception e
) {
79 // Some exception occurs.FAILED
80 e
.printStackTrace( log
);
81 throw new StatusException( "Couldn't create document", e
);
86 * Disposes Drawing document.
89 protected void cleanup( TestParameters Param
, PrintWriter log
) {
90 log
.println("disposing xDrawDoc");
91 util
.DesktopTools
.closeDoc(xDrawDoc
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Retrieves the layer manager using the interface <code>XLayerSupplier</code>.
97 * The manager is the instance of the service
98 * <code>com.sun.star.drawing.LayerManager</code>. Creates a rectangle shape.
99 * Retrieves the collection of the draw pages and take one of them.
101 * <li> <code>'Shape'</code> for
102 * {@link ifc.drawing._XLayerManager}(the created shape)</li>
103 * <li> <code>'Shapes'</code> for
104 * {@link ifc.drawing._XLayerManager}(the shape collection of
105 * the retrieved draw page)</li>
107 * @see com.sun.star.drawing.XLayerSupplier
108 * @see com.sun.star.drawing.LayerManager
111 protected synchronized TestEnvironment
createTestEnvironment(
112 TestParameters Param
, PrintWriter log
) {
114 // creation of testobject here
115 // first we write what we are intend to do to log file
116 log
.println( "creating a test environment" );
118 // create testobject here
119 XLayerSupplier oLS
= UnoRuntime
.queryInterface(XLayerSupplier
.class, xDrawDoc
);
120 XInterface oObj
= oLS
.getLayerManager();
122 log
.println( "creating a new environment for XLayerManager object" );
123 TestEnvironment tEnv
= new TestEnvironment( oObj
);
125 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
126 log
.println( "adding Shape as mod relation to environment" );
127 tEnv
.addObjRelation("Shape", new InstCreator(xDrawDoc
, sDsc
));
130 // get the drawpage of drawing here
131 log
.println( "getting Drawpage" );
132 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
133 XDrawPages oDPn
= oDPS
.getDrawPages();
134 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,oDPn
);
136 XDrawPage oDP
= null;
138 oDP
= (XDrawPage
) AnyConverter
.toObject(
139 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
140 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
141 e
.printStackTrace( log
);
142 throw new StatusException("Couldn't get by index", e
);
143 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
144 e
.printStackTrace( log
);
145 throw new StatusException("Couldn't get by index", e
);
146 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
147 e
.printStackTrace( log
);
148 throw new StatusException("Couldn't get by index", e
);
151 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDP
);
153 log
.println( "adding Shapes as mod relation to environment" );
154 tEnv
.addObjRelation("Shapes", oShapes
);
157 } // finish method getTestEnvironment
159 } // finish class SdLayerManager