Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxShapeDimensioning.java
blob7cccfe0694fd543a4ba399df0a34b2ee05d309e6
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._svx;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.DefaultDsc;
27 import util.DrawTools;
28 import util.InstCreator;
29 import util.SOfficeFactory;
31 import com.sun.star.beans.XPropertySet;
32 import com.sun.star.drawing.XShape;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.style.XStyle;
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 public class SvxShapeDimensioning extends TestCase {
42 static XComponent xDrawDoc;
44 /**
45 * in general this method creates a testdocument
47 * @param tParam class which contains additional test parameters
48 * @param log class to log the test state and result
51 * @see TestParameters
52 * @see PrintWriter
55 @Override
56 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
57 log.println( "creating a drawdoc" );
58 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
61 /**
62 * in general this method disposes the testenvironment and document
64 * @param tParam class which contains additional test parameters
65 * @param log class to log the test state and result
68 * @see TestParameters
69 * @see PrintWriter
72 @Override
73 protected void cleanup( TestParameters tParam, PrintWriter log ) {
74 log.println( " disposing xDrawDoc " );
75 util.DesktopTools.closeDoc(xDrawDoc);
79 /**
80 * creating a TestEnvironment for the interfaces to be tested
82 * @param tParam class which contains additional test parameters
83 * @param log class to log the test state and result
85 * @return Status class
87 * @see TestParameters
88 * @see PrintWriter
90 @Override
91 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
93 XInterface oObj = null;
94 XShape oShape = null;
96 // creation of testobject here
97 // first we write what we are intend to do to log file
98 log.println( "creating a test environment" );
100 try {
102 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
103 oShape = SOF.createShape(xDrawDoc,4000,4000,3000,3000,"Measure");
105 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
107 for (int i=0;i<10;i++) {
108 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(
109 SOF.createShape(xDrawDoc,
110 3000,4500,7510+10*i,5010+10*i,"Rectangle"));
113 oObj = oShape ;
115 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Line");
116 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
118 catch (Exception e) {
119 log.println("Couldn't create instance");
120 e.printStackTrace(log);
123 // test environment creation
125 TestEnvironment tEnv = new TestEnvironment(oObj);
127 log.println( "adding two styles as ObjRelation for ShapeDescriptor" );
128 XPropertySet oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oObj);
129 XStyle aStyle = null;
130 try {
131 aStyle = (XStyle) AnyConverter.toObject(
132 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
133 } catch (Exception e) {
134 System.out.println("caught exception: " + e);
136 tEnv.addObjRelation("Style1",aStyle);
137 oShapeProps = UnoRuntime.queryInterface(XPropertySet.class,oShape);
138 try {
139 aStyle = (XStyle) AnyConverter.toObject(
140 new Type(XStyle.class),oShapeProps.getPropertyValue("Style"));
141 } catch (Exception e) {
142 System.out.println("caught exception: " + e);
144 tEnv.addObjRelation("Style2",aStyle);
146 DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent",
147 "com.sun.star.text.TextField.URL");
148 log.println( " adding InstCreator object" );
149 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xDrawDoc, tDsc ) );
151 return tEnv;
152 } // finish method getTestEnvironment
154 } // finish class SvxShapeDimensioning