Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextField.java
blobf9ffe6726b7be0ba3262fb9d37a7a72dc2c77610
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.DrawTools;
27 import util.SOfficeFactory;
29 import com.sun.star.drawing.XShape;
30 import com.sun.star.lang.XComponent;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextContent;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 /**
40 * initial description
41 * @see ifc._XComponent
42 * @see ifc._TextContent
43 * @see ifc._XTextContent
44 * @see ifc._XTextField
47 public class SvxUnoTextField extends TestCase {
49 static XComponent xDrawDoc;
51 /**
52 * in general this method creates a testdocument
54 * @param tParam class which contains additional test parameters
55 * @param log class to log the test state and result
58 * @see TestParameters
59 * @see PrintWriter
62 @Override
63 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
64 log.println( "creating a drawdoc" );
65 xDrawDoc = DrawTools.createDrawDoc( tParam.getMSF());
68 /**
69 * in general this method disposes the testenvironment and document
71 * @param tParam class which contains additional test parameters
72 * @param log class to log the test state and result
75 * @see TestParameters
76 * @see PrintWriter
79 @Override
80 protected void cleanup( TestParameters tParam, PrintWriter log ) {
81 log.println( " disposing xDrawDoc " );
82 util.DesktopTools.closeDoc(xDrawDoc);
84 /**
85 * creating a TestEnvironment for the interfaces to be tested
87 * @param tParam class which contains additional test parameters
88 * @param log class to log the test state and result
90 * @return Status class
92 * @see TestParameters
93 * @see PrintWriter
95 @Override
96 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
98 XInterface oObj = null;
99 XShape oShape = null;
101 // creation of testobject here
102 // first we write what we are intend to do to log file
103 log.println( "creating a test environment" );
104 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF());
105 oShape = SOF.createShape(xDrawDoc,5000,3500,7500,5000,"Rectangle");
106 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape);
108 XTextCursor the_Cursor = null;
110 // create testobject here
111 XText the_Text = UnoRuntime.queryInterface(XText.class,oShape);
112 XMultiServiceFactory oDocMSF = UnoRuntime.queryInterface( XMultiServiceFactory.class, xDrawDoc );
113 the_Cursor = the_Text.createTextCursor();
114 oObj = (XInterface)
115 oDocMSF.createInstance( "com.sun.star.text.TextField.DateTime" );
116 XTextContent the_Field = UnoRuntime.queryInterface(XTextContent.class,oObj);
119 the_Text.insertTextContent(the_Cursor,the_Field,false);
121 log.println( "creating a new environment for FieldMaster object" );
122 TestEnvironment tEnv = new TestEnvironment( oObj );
123 tEnv.addObjRelation("RANGE", the_Cursor);
125 return tEnv;
126 } // finish method getTestEnvironment
128 } // finish class SvxUnoTextField