Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XRelativeTextContentInsert.java
blobaf6995662ff0a1f0f587907935501b6425907ca2
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 ifc.text;
21 import lib.MultiMethodTest;
22 import util.XInstCreator;
24 import com.sun.star.text.XRelativeTextContentInsert;
25 import com.sun.star.text.XText;
26 import com.sun.star.text.XTextContent;
27 import com.sun.star.text.XTextCursor;
28 import com.sun.star.uno.UnoRuntime;
29 import com.sun.star.uno.XInterface;
31 /**
32 * Testing <code>com.sun.star.text.XRelativeTextContentInsert</code>
33 * interface methods :
34 * <ul>
35 * <li><code> insertTextContentBefore()</code></li>
36 * <li><code> insertTextContentAfter()</code></li>
37 * </ul> <p>
38 * This test needs the following object relations :
39 * <ul>
40 * <li> <code>'PARA'</code> (of type <code>XInstCreator</code>):
41 * the creator which can create instances of
42 * <code>com.sun.star.text.Paragraph</code> service. </li>
43 * <li> <code>'XTEXTINFO'</code> (of type <code>XInstCreator</code>):
44 * the creator which can create instances of some text content
45 * service (objects which implement <code>XTextContent</code>).
46 * </li>
47 * <ul> <p>
49 * Tested component <b>must implement</b> <code>XText</code>
50 * interface for proper testing. <p>
52 * Test is <b> NOT </b> multithread compliant. <p>
53 * @see com.sun.star.text.XRelativeTextContentInsert
55 public class _XRelativeTextContentInsert extends MultiMethodTest {
57 public XRelativeTextContentInsert oObj = null;
58 public XTextContent content = null;
60 /**
61 * First an instance of <code>Paragraph</code> service created
62 * using relation and inserted into text. Then an instance
63 * of text content is created and inserted after the paragraph. <p>
65 * Has <b>OK</b> status if no exceptions occurred.
67 public void _insertTextContentAfter() {
69 try {
70 XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
71 XInterface oInt = para.createInstance();
72 XTextContent new_content = (XTextContent) oInt;
73 XText theText = UnoRuntime.queryInterface(XText.class,oObj);
74 XTextCursor oCursor = theText.createTextCursor();
75 XInstCreator info = (XInstCreator)
76 tEnv.getObjRelation( "XTEXTINFO" );
77 oInt = info.createInstance();
78 content = (XTextContent) oInt;
79 theText.insertTextContent(oCursor, content, false);
80 oObj.insertTextContentAfter(new_content,content);
81 tRes.tested("insertTextContentAfter()",true);
83 catch (com.sun.star.lang.IllegalArgumentException ex) {
84 log.println("Exception occurred while checking "+
85 "insertTextContentAfter()");
86 ex.printStackTrace(log);
87 tRes.tested("insertTextContentAfter()",false);
91 } // end _insertTextContentAfter()
93 /**
94 * An instance of text content is created using relation
95 * and inserted before the paragraph which was added into
96 * text in <code>insertTextContentAfter</code> method test. <p>
98 * Has <b>OK</b> status if no exceptions occurred. <p>
100 * The following method tests are to be completed successfully before :
101 * <ul>
102 * <li> <code> insertTextContentAfter() </code> : here the
103 * <code>Paragraph</code> instance is inserted. </li>
104 * </ul>
106 public void _insertTextContentBefore() {
107 requiredMethod("insertTextContentAfter()");
108 try {
109 XInstCreator para = (XInstCreator)tEnv.getObjRelation( "PARA" );
110 XInterface oInt = para.createInstance();
111 XTextContent new_content = (XTextContent) oInt;
112 oObj.insertTextContentBefore(new_content,content);
113 tRes.tested("insertTextContentBefore()",true);
115 catch (com.sun.star.lang.IllegalArgumentException ex) {
116 log.println("Exception occurred while checking "+
117 "insertTextContentBefore()");
118 ex.printStackTrace(log);
119 tRes.tested("insertTextContentBefore()",false);
123 } // end _insertTextContentBefore()