Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _sd / SdPageLinkTargets.java
blob7d314645ee39f5a9978fb6f8817eb954e1f48cde
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.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DrawTools;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.document.XLinkTargetSupplier;
31 import com.sun.star.drawing.XDrawPage;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.drawing.XShapes;
34 import com.sun.star.lang.XComponent;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.document.LinkTargets</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::container::XNameAccess</code></li>
44 * <li> <code>com::sun::star::container::XElementAccess</code></li>
45 * </ul>
46 * @see com.sun.star.document.LinkTargets
47 * @see com.sun.star.container.XNameAccess
48 * @see com.sun.star.container.XElementAccess
49 * @see ifc.container._XNameAccess
50 * @see ifc.container._XElementAccess
52 public class SdPageLinkTargets extends TestCase {
53 XComponent xDrawDoc;
55 /**
56 * Creates Drawing document.
58 @Override
59 protected void initialize(TestParameters Param, PrintWriter log) throws Exception {
60 // get a soffice factory object
61 SOfficeFactory SOF = SOfficeFactory.getFactory(
62 Param.getMSF());
63 log.println( "creating a draw document" );
64 xDrawDoc = SOF.createDrawDoc(null);
67 /**
68 * Disposes Drawing document.
70 @Override
71 protected void cleanup( TestParameters Param, PrintWriter log) {
72 log.println("disposing xDrawDoc");
73 util.DesktopTools.closeDoc(xDrawDoc);
76 /**
77 * Creating a TestEnvironment for the interfaces to be tested.
78 * Retrieves the collection of draw pages and take one of them.
79 * Obtains the collection of possible links using the interface
80 * <code>XLinkTargetSupplier</code>. The obtained collection is
81 * the instance of the service <code>com.sun.star.document.LinkTargets</code>.
82 * Inserts some shapes into the document.
83 * @see com.sun.star.document.XLinkTargetSupplier
84 * @see com.sun.star.document.LinkTargets
86 @Override
87 public TestEnvironment createTestEnvironment(
88 TestParameters Param, PrintWriter log) throws Exception {
90 // creation of testobject here
91 // first we write what we are intend to do to log file
92 log.println( "creating a test environment" );
94 // create testobject here
95 XDrawPage the_page = DrawTools.getDrawPage(xDrawDoc, 0);
96 XLinkTargetSupplier oLTS = UnoRuntime.queryInterface(XLinkTargetSupplier.class, the_page);
97 XInterface oObj = oLTS.getLinks();
99 SOfficeFactory SOF = SOfficeFactory.getFactory(
100 Param.getMSF());
101 log.println( "inserting some Shapes" );
102 XShapes oShapes = UnoRuntime.queryInterface(XShapes.class,the_page);
103 XShape oShape =
104 SOF.createShape(xDrawDoc, 15000, 13500, 5000, 5000, "OLE2");
105 oShapes.add(oShape);
107 XPropertySet shape_props = UnoRuntime.queryInterface(XPropertySet.class,oShape);
109 log.println("Inserting a Chart");
111 shape_props.
112 setPropertyValue("CLSID","12DCAE26-281F-416F-a234-c3086127382e");
114 log.println( "creating a new environment for LinkTargets object" );
115 TestEnvironment tEnv = new TestEnvironment( oObj );
117 return tEnv;
118 } // finish method createTestEnvironment
120 } // finish class SdPageLinkTargets