bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdLayer.java
blob866eac2359f0d5d3902dd4127895a7295a9f464f
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.SOfficeFactory;
29 import com.sun.star.container.XIndexAccess;
30 import com.sun.star.container.XNameAccess;
31 import com.sun.star.drawing.XLayer;
32 import com.sun.star.drawing.XLayerManager;
33 import com.sun.star.drawing.XLayerSupplier;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Test for object which is represented by service
42 * <code>com.sun.star.drawing.Layer</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::drawing::Layer</code></li>
46 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
47 * </ul>
48 * @see com.sun.star.drawing.Layer
49 * @see com.sun.star.beans.XPropertySet
50 * @see ifc.drawing._Layer
51 * @see ifc.beans._XPropertySet
53 public class SdLayer extends TestCase {
54 XComponent xDrawDoc;
56 /**
57 * Creates Drawing document.
59 @Override
60 protected void initialize(TestParameters Param, PrintWriter log) {
61 // get a soffice factory object
62 SOfficeFactory SOF = SOfficeFactory.getFactory(
63 Param.getMSF());
65 try {
66 log.println( "creating a draw document" );
67 xDrawDoc = SOF.createDrawDoc(null);
68 } catch (com.sun.star.uno.Exception e) {
69 e.printStackTrace( log );
70 throw new StatusException("Couldn't create document", e);
74 /**
75 * Disposes Drawing document.
77 @Override
78 protected void cleanup( TestParameters Param, PrintWriter log) {
79 log.println("disposing xDrawDoc");
80 util.DesktopTools.closeDoc(xDrawDoc);
83 /**
84 * Creating a Testenvironment for the interfaces to be tested.
85 * Retrieves the layer manager from the document and takes one of the layer.
86 * The obtained layer is the instance of the service
87 * <code>com.sun.star.drawing.Layer</code>.
88 * @see com.sun.star.drawing.Layer
90 @Override
91 protected synchronized TestEnvironment createTestEnvironment(
92 TestParameters Param, PrintWriter log) {
94 XInterface oObj = null;
95 XLayerManager oLM = null;
97 // creation of testobject here
98 // first we write what we are intend to do to log file
99 log.println( "creating a test environment" );
101 // get the drawpage of drawing here
102 log.println( "getting LayerManager" );
103 XLayerSupplier oLS = UnoRuntime.queryInterface(XLayerSupplier.class, xDrawDoc);
104 XNameAccess oNA = oLS.getLayerManager();
105 oLM = UnoRuntime.queryInterface(XLayerManager.class, oNA);
106 XIndexAccess oIA = UnoRuntime.queryInterface(XIndexAccess.class,oLM);
107 log.println( "getting LayerManager" );
108 try {
109 oObj = (XLayer) AnyConverter.toObject(
110 new Type(XLayer.class),oIA.getByIndex(0));
111 } catch (com.sun.star.lang.WrappedTargetException e) {
112 e.printStackTrace( log );
113 throw new StatusException("Couldn't get by index", e);
114 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
115 e.printStackTrace( log );
116 throw new StatusException("Couldn't get by index", e);
117 } catch (com.sun.star.lang.IllegalArgumentException e) {
118 e.printStackTrace( log );
119 throw new StatusException("Couldn't get by index", e);
122 log.println( "creating a new environment for drawpage object" );
123 TestEnvironment tEnv = new TestEnvironment( oObj );
125 return tEnv;
126 } // finish method createTestEnvironment
128 } // finish class SdLayer