1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sd;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.container.XIndexAccess;
35 import com.sun.star.container.XNameAccess;
36 import com.sun.star.drawing.XLayer;
37 import com.sun.star.drawing.XLayerManager;
38 import com.sun.star.drawing.XLayerSupplier;
39 import com.sun.star.lang.XComponent;
40 import com.sun.star.lang.XMultiServiceFactory;
41 import com.sun.star.uno.AnyConverter;
42 import com.sun.star.uno.Type;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 
46 /**
47 * Test for object which is represented by service
48 * <code>com.sun.star.drawing.Layer</code>. <p>
49 * Object implements the following interfaces :
50 * <ul>
51 *  <li> <code>com::sun::star::drawing::Layer</code></li>
52 *  <li> <code>com::sun::star::beans::XPropertySet</code></li>
53 * </ul>
54 * @see com.sun.star.drawing.Layer
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.drawing._Layer
57 * @see ifc.beans._XPropertySet
58 */
59 public class SdLayer extends TestCase {
60     XComponent xDrawDoc;
61 
62     /**
63     * Creates Drawing document.
64     */
initialize(TestParameters Param, PrintWriter log)65     protected void initialize(TestParameters Param, PrintWriter log) {
66         // get a soffice factory object
67         SOfficeFactory SOF = SOfficeFactory.getFactory(
68                                         (XMultiServiceFactory)Param.getMSF());
69 
70         try {
71             log.println( "creating a draw document" );
72             xDrawDoc = SOF.createDrawDoc(null);
73          } catch (com.sun.star.uno.Exception e) {
74             e.printStackTrace( log );
75             throw new StatusException("Couldn't create document", e);
76          }
77     }
78 
79     /**
80     * Disposes Drawing document.
81     */
cleanup( TestParameters Param, PrintWriter log)82     protected void cleanup( TestParameters Param, PrintWriter log) {
83         log.println("disposing xDrawDoc");
84         util.DesktopTools.closeDoc(xDrawDoc);
85     }
86 
87     /**
88     * Creating a Testenvironment for the interfaces to be tested.
89     * Retrieves the layer manager from the document and takes one of the layer.
90     * The obtained layer is the instance of the service
91     * <code>com.sun.star.drawing.Layer</code>.
92     * @see com.sun.star.drawing.Layer
93     */
createTestEnvironment( TestParameters Param, PrintWriter log)94     protected synchronized TestEnvironment createTestEnvironment(
95                                     TestParameters Param, PrintWriter log) {
96 
97         XInterface oObj = null;
98         XLayerManager oLM = null;
99 
100         // creation of testobject here
101         // first we write what we are intend to do to log file
102         log.println( "creating a test environment" );
103 
104         // get the drawpage of drawing here
105         log.println( "getting LayerManager" );
106         XLayerSupplier oLS = (XLayerSupplier)
107             UnoRuntime.queryInterface(XLayerSupplier.class, xDrawDoc);
108         XNameAccess oNA = oLS.getLayerManager();
109         oLM = (XLayerManager)
110             UnoRuntime.queryInterface(XLayerManager.class, oNA);
111         XIndexAccess oIA = (XIndexAccess)
112             UnoRuntime.queryInterface(XIndexAccess.class,oLM);
113         log.println( "getting LayerManager" );
114         try {
115             oObj = (XLayer) AnyConverter.toObject(
116                         new Type(XLayer.class),oIA.getByIndex(0));
117         } catch (com.sun.star.lang.WrappedTargetException e) {
118             e.printStackTrace( log );
119             throw new StatusException("Couldn't get by index", e);
120         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
121             e.printStackTrace( log );
122             throw new StatusException("Couldn't get by index", e);
123         } catch (com.sun.star.lang.IllegalArgumentException e) {
124             e.printStackTrace( log );
125             throw new StatusException("Couldn't get by index", e);
126         }
127 
128         log.println( "creating a new environment for drawpage object" );
129         TestEnvironment tEnv = new TestEnvironment( oObj );
130 
131         return tEnv;
132     } // finish method createTestEnvironment
133 
134 }    // finish class SdLayer
135 
136