Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteText.java
blob374e89c660acafbdb2eafce993c864723b97f648
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._sw;
21 import java.io.PrintWriter;
23 import lib.TestCase;
24 import lib.TestEnvironment;
25 import lib.TestParameters;
26 import util.InstCreator;
27 import util.ParagraphDsc;
28 import util.SOfficeFactory;
29 import util.TextSectionDsc;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XFootnote;
33 import com.sun.star.text.XSimpleText;
34 import com.sun.star.text.XText;
35 import com.sun.star.text.XTextCursor;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
40 /**
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
44 * <li> <code>com::sun::star::text::XSimpleText</code></li>
45 * <li> <code>com::sun::star::text::XTextRange</code></li>
46 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
47 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
48 * <li> <code>com::sun::star::container::XElementAccess</code></li>
49 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
50 * <li> <code>com::sun::star::text::XText</code></li>
51 * </ul> <p>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurrently.
54 * @see com.sun.star.text.XTextRangeMover
55 * @see com.sun.star.text.XSimpleText
56 * @see com.sun.star.text.XTextRange
57 * @see com.sun.star.text.XRelativeTextContentInsert
58 * @see com.sun.star.text.XTextRangeCompare
59 * @see com.sun.star.container.XElementAccess
60 * @see com.sun.star.container.XEnumerationAccess
61 * @see com.sun.star.text.XText
62 * @see ifc.text._XTextRangeMover
63 * @see ifc.text._XSimpleText
64 * @see ifc.text._XTextRange
65 * @see ifc.text._XRelativeTextContentInsert
66 * @see ifc.text._XTextRangeCompare
67 * @see ifc.container._XElementAccess
68 * @see ifc.container._XEnumerationAccess
69 * @see ifc.text._XText
71 public class SwXFootnoteText extends TestCase {
72 XTextDocument xTextDoc;
74 /**
75 * Creates text document.
77 @Override
78 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
79 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
80 log.println( "creating a textdocument" );
81 xTextDoc = SOF.createTextDoc( null );
84 /**
85 * Disposes text document.
87 @Override
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xTextDoc " );
90 util.DesktopTools.closeDoc(xTextDoc);
93 /**
94 * Creating a TestEnvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
97 * to the text, and finally sets a string to the footnote. Then the text
98 * gotten from the footnote is returned as tested component.<br>
99 * Object relations created :
100 * <ul>
101 * <li> <code>'TEXT'</code> for
102 * {@link ifc.text._XTextRangeCompare} : footnote text</li>
103 * <li> <code>'XTEXTINFO'</code> for
104 * {@link ifc.text._XRelativeTextContentInsert},
105 * {@link ifc.text._XText} : text section creator</li>
106 * <li> <code>'PARA'</code> for
107 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
108 * </ul>
110 @Override
111 public TestEnvironment createTestEnvironment(
112 TestParameters tParam, PrintWriter log ) throws Exception {
113 XInterface oObj = null;
114 XFootnote oFootnote;
116 log.println( "creating a test environment" );
117 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
118 log.println("creating a footnote");
120 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
121 msf.createInstance("com.sun.star.text.Footnote"));
123 XText oText = xTextDoc.getText();
124 XTextCursor oCursor = oText.createTextCursor();
126 log.println("inserting the footnote into text document");
127 oText.insertTextContent(oCursor, oFootnote, false);
129 XSimpleText oFootText = UnoRuntime.queryInterface(XSimpleText.class, oFootnote);
130 oFootText.setString("SwXFootnoteText");
132 oObj = oFootText.getText();
134 TestEnvironment tEnv = new TestEnvironment(oObj);
136 log.println( "adding TextDocument as mod relation to environment" );
137 tEnv.addObjRelation("TEXT", oObj);
139 TextSectionDsc tDsc = new TextSectionDsc();
140 log.println( " adding InstCreator object" );
141 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
143 log.println( " adding Paragraph" );
144 ParagraphDsc pDsc = new ParagraphDsc();
145 tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
147 return tEnv;
148 } // finish method getTestEnvironment
150 } // finish class SwXFootnoteText