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
.lang
.XMultiServiceFactory
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.drawing.LayerManager</code>. <p>
47 * Object implements the following interfaces :
49 * <li> <code>com::sun::star::drawing::XLayerManager</code></li>
50 * <li> <code>com::sun::star::container::XNameAccess</code></li>
51 * <li> <code>com::sun::star::container::XIndexAccess</code></li>
52 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * @see com.sun.star.drawing.LayerManager
55 * @see com.sun.star.drawing.XLayerManager
56 * @see com.sun.star.container.XNameAccess
57 * @see com.sun.star.container.XIndexAccess
58 * @see com.sun.star.container.XElementAccess
59 * @see ifc.drawing._XLayerManager
60 * @see ifc.container._XNameAccess
61 * @see ifc.container._XIndexAccess
62 * @see ifc.container._XElementAccess
64 public class SdLayerManager
extends TestCase
{
68 * Creates Drawing document.
70 protected void initialize(TestParameters Param
, PrintWriter log
) {
71 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory(
73 (XMultiServiceFactory
)Param
.getMSF());
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.
88 protected void cleanup( TestParameters Param
, PrintWriter log
) {
89 log
.println("disposing xDrawDoc");
90 util
.DesktopTools
.closeDoc(xDrawDoc
);
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Retrieves the layer manager using the interface <code>XLayerSupplier</code>.
96 * The manager is the instance of the service
97 * <code>com.sun.star.drawing.LayerManager</code>. Creates a rectangle shape.
98 * Retrieves the collection of the draw pages and take one of them.
100 * <li> <code>'Shape'</code> for
101 * {@link ifc.drawing._XLayerManager}(the created shape)</li>
102 * <li> <code>'Shapes'</code> for
103 * {@link ifc.drawing._XLayerManager}(the shape collection of
104 * the retrived draw page)</li>
106 * @see com.sun.star.drawing.XLayerSupplier
107 * @see com.sun.star.drawing.LayerManager
109 protected synchronized TestEnvironment
createTestEnvironment(
110 TestParameters Param
, PrintWriter log
) {
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log
.println( "creating a test environment" );
116 // create testobject here
117 XLayerSupplier oLS
= UnoRuntime
.queryInterface(XLayerSupplier
.class, xDrawDoc
);
118 XInterface oObj
= oLS
.getLayerManager();
120 log
.println( "creating a new environment for XLayerManager object" );
121 TestEnvironment tEnv
= new TestEnvironment( oObj
);
123 ShapeDsc sDsc
= new ShapeDsc(5000, 3500, 7500, 10000, "Rectangle");
124 log
.println( "adding Shape as mod relation to environment" );
125 tEnv
.addObjRelation("Shape", new InstCreator(xDrawDoc
, sDsc
));
128 // get the drawpage of drawing here
129 log
.println( "getting Drawpage" );
130 XDrawPagesSupplier oDPS
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class,xDrawDoc
);
131 XDrawPages oDPn
= oDPS
.getDrawPages();
132 XIndexAccess oDPi
= UnoRuntime
.queryInterface(XIndexAccess
.class,oDPn
);
134 XDrawPage oDP
= null;
136 oDP
= (XDrawPage
) AnyConverter
.toObject(
137 new Type(XDrawPage
.class),oDPi
.getByIndex(0));
138 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
139 e
.printStackTrace( log
);
140 throw new StatusException("Couldn't get by index", e
);
141 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
142 e
.printStackTrace( log
);
143 throw new StatusException("Couldn't get by index", e
);
144 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
145 e
.printStackTrace( log
);
146 throw new StatusException("Couldn't get by index", e
);
149 XShapes oShapes
= UnoRuntime
.queryInterface(XShapes
.class, oDP
);
151 log
.println( "adding Shapes as mod relation to environment" );
152 tEnv
.addObjRelation("Shapes", oShapes
);
155 } // finish method getTestEnvironment
157 } // finish class SdLayerManager