Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _svx / SvxUnoTextCursor.java
blobec367094a253bd1591955dae96591441acb942c6
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.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.drawing.XShape;
31 import com.sun.star.lang.XComponent;
32 import com.sun.star.text.ControlCharacter;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextCursor;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
38 public class SvxUnoTextCursor extends TestCase {
40 static XComponent xDrawDoc;
42 /**
43 * in general this method creates a testdocument
45 * @param tParam class which contains additional test parameters
46 * @param log class to log the test state and result
49 * @see TestParameters
50 * @see PrintWriter
53 @Override
54 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
55 log.println( "creating a drawdoc" );
56 xDrawDoc = DrawTools.createDrawDoc(tParam.getMSF());
59 /**
60 * in general this method disposes the testenvironment and document
62 * @param tParam class which contains additional test parameters
63 * @param log class to log the test state and result
66 * @see TestParameters
67 * @see PrintWriter
70 @Override
71 protected void cleanup( TestParameters tParam, PrintWriter log ) {
72 log.println( " disposing xDrawDoc " );
73 util.DesktopTools.closeDoc(xDrawDoc);
77 /**
78 * creating a TestEnvironment for the interfaces to be tested
80 * @param tParam class which contains additional test parameters
81 * @param log class to log the test state and result
83 * @return Status class
85 * @see TestParameters
86 * @see PrintWriter
88 @Override
89 public TestEnvironment createTestEnvironment( TestParameters tParam,
90 PrintWriter log )
91 throws StatusException {
93 XInterface oObj = null;
94 // create testobject here
96 try {
97 SOfficeFactory SOF = SOfficeFactory.getFactory(tParam.getMSF()) ;
98 XShape oShape = SOF.createShape
99 (xDrawDoc,5000,3500,7500,5000,"Text");
100 DrawTools.getShapes(DrawTools.getDrawPage(xDrawDoc,0)).add(oShape) ;
102 XText text = UnoRuntime.queryInterface(XText.class, oShape) ;
104 XTextCursor cursor = text.createTextCursor() ;
106 text.insertString(cursor, "Paragraph 1", false) ;
107 text.insertControlCharacter(cursor,
108 ControlCharacter.PARAGRAPH_BREAK, false) ;
109 text.insertString(cursor, "Paragraph 2", false) ;
110 text.insertControlCharacter(cursor,
111 ControlCharacter.PARAGRAPH_BREAK, false) ;
112 text.insertString(cursor, "Paragraph 3", false) ;
113 text.insertControlCharacter(cursor,
114 ControlCharacter.PARAGRAPH_BREAK, false) ;
116 oObj = cursor ;
118 } catch (Exception e) {
119 log.println("Can't create test object") ;
120 e.printStackTrace(log) ;
123 // create test environment here
124 TestEnvironment tEnv = new TestEnvironment( oObj );
127 return tEnv;
128 } // finish method getTestEnvironment
130 } // finish class SvxUnoTextCursor