Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdPageLinkTargets.java
blob1d100d718f79a5b0613be7dbb5499c1da8759155
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.DrawTools;
28 import util.SOfficeFactory;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.document.XLinkTargetSupplier;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XShape;
34 import com.sun.star.drawing.XShapes;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.uno.UnoRuntime;
37 import com.sun.star.uno.XInterface;
39 /**
40 * Test for object which is represented by service
41 * <code>com.sun.star.document.LinkTargets</code>. <p>
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::container::XNameAccess</code></li>
45 * <li> <code>com::sun::star::container::XElementAccess</code></li>
46 * </ul>
47 * @see com.sun.star.document.LinkTargets
48 * @see com.sun.star.container.XNameAccess
49 * @see com.sun.star.container.XElementAccess
50 * @see ifc.container._XNameAccess
51 * @see ifc.container._XElementAccess
53 public class SdPageLinkTargets 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 // Some exception occurs.FAILED
70 e.printStackTrace( log );
71 throw new StatusException( "Couldn't create document", e );
75 /**
76 * Disposes Drawing document.
78 @Override
79 protected void cleanup( TestParameters Param, PrintWriter log) {
80 log.println("disposing xDrawDoc");
81 util.DesktopTools.closeDoc(xDrawDoc);
84 /**
85 * Creating a Testenvironment for the interfaces to be tested.
86 * Retrieves the collection of draw pages and take one of them.
87 * Obtains the collection of possible links using the interface
88 * <code>XLinkTargetSupplier</code>. The obtained collection is
89 * the instance of the service <code>com.sun.star.document.LinkTargets</code>.
90 * Inserts some shapes into the document.
91 * @see com.sun.star.document.XLinkTargetSupplier
92 * @see com.sun.star.document.LinkTargets
94 @Override
95 public synchronized TestEnvironment createTestEnvironment(
96 TestParameters Param, PrintWriter log) throws StatusException {
98 // creation of testobject here
99 // first we write what we are intend to do to log file
100 log.println( "creating a test environment" );
102 // create testobject here
103 XDrawPage the_page = DrawTools.getDrawPage(xDrawDoc, 0);
104 XLinkTargetSupplier oLTS = UnoRuntime.queryInterface(XLinkTargetSupplier.class, the_page);
105 XInterface oObj = oLTS.getLinks();
107 SOfficeFactory SOF = SOfficeFactory.getFactory(
108 Param.getMSF());
109 log.println( "inserting some Shapes" );
110 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class,the_page);
111 XShape oShape =
112 SOF.createShape(xDrawDoc, 15000, 13500, 5000, 5000, "OLE2");
113 oShapes.add(oShape);
115 XPropertySet shape_props = UnoRuntime.queryInterface(XPropertySet.class,oShape);
117 log.println("Inserting a Chart");
119 try {
120 shape_props.
121 setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e");
122 } catch (com.sun.star.lang.WrappedTargetException e) {
123 e.printStackTrace(log);
124 throw new StatusException("WrappedTarget: couldn't change property CLSID", e);
125 } catch (com.sun.star.lang.IllegalArgumentException e) {
126 e.printStackTrace(log);
127 throw new StatusException("IllegalArgument: couldn't change property CLSID", e);
128 } catch (com.sun.star.beans.PropertyVetoException e) {
129 e.printStackTrace(log);
130 throw new StatusException("PropertyVeto: couldn't change property CLSID", e);
131 } catch (com.sun.star.beans.UnknownPropertyException e) {
132 e.printStackTrace(log);
133 throw new StatusException("UnknownProperty: couldn't change property CLSID", e);
136 log.println( "creating a new environment for LinkTargets object" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 return tEnv;
140 } // finish method createTestEnvironment
142 } // finish class SdPageLinkTargets