Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnote.java
blob745e3d69c9f308d176b094c83ba2436ebb967bd6
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.FrameDsc;
27 import util.InstCreator;
28 import util.SOfficeFactory;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XFootnote;
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.text.XTextDocument;
36 import com.sun.star.uno.UnoRuntime;
38 /**
39 * Test for object which is represented by service
40 * <code>com.sun.star.text.Footnote</code>. <p>
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::text::XFootnote</code></li>
44 * <li> <code>com::sun::star::lang::XComponent</code></li>
45 * <li> <code>com::sun::star::text::XSimpleText</code></li>
46 * <li> <code>com::sun::star::text::Footnote</code></li>
47 * <li> <code>com::sun::star::text::XTextContent</code></li>
48 * <li> <code>com::sun::star::text::XTextRange</code></li>
49 * <li> <code>com::sun::star::text::XText</code></li>
50 * </ul> <p>
51 * This object test <b> is NOT </b> designed to be run in several
52 * threads concurrently.
53 * @see com.sun.star.text.XFootnote
54 * @see com.sun.star.lang.XComponent
55 * @see com.sun.star.text.XSimpleText
56 * @see com.sun.star.text.Footnote
57 * @see com.sun.star.text.XTextContent
58 * @see com.sun.star.text.XTextRange
59 * @see com.sun.star.text.XText
60 * @see ifc.text._XFootnote
61 * @see ifc.lang._XComponent
62 * @see ifc.text._XSimpleText
63 * @see ifc.text._Footnote
64 * @see ifc.text._XTextContent
65 * @see ifc.text._XTextRange
66 * @see ifc.text._XText
68 public class SwXFootnote extends TestCase {
69 XTextDocument xTextDoc;
71 /**
72 * Creates text document.
74 @Override
75 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
76 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
77 log.println( "creating a textdocument" );
78 xTextDoc = SOF.createTextDoc( null );
81 /**
82 * Disposes text document.
84 @Override
85 protected void cleanup( TestParameters tParam, PrintWriter log ) {
86 log.println( " disposing xTextDoc " );
87 util.DesktopTools.closeDoc(xTextDoc);
90 /**
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.text.Footnote</code>. Then inserts created footnote
94 * to a text of document as content.
95 * Object relations created :
96 * <ul>
97 * <li><code>'XTEXTINFO'</code> for
98 * {@link ifc.text._XText} </li>
99 * </ul>
101 @Override
102 protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) throws Exception {
103 XFootnote oFootnote;
105 log.println( "Creating a test environment" );
106 // get a soffice factory object
107 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
108 log.println("creating a footnote");
109 Object instance = null;
110 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
111 msf.createInstance("com.sun.star.text.Footnote"));
112 instance = msf.createInstance("com.sun.star.text.Footnote");
114 XText oText = xTextDoc.getText();
115 XTextCursor oCursor = oText.createTextCursor();
117 log.println("inserting the footnote into text document");
118 oText.insertTextContent(oCursor, oFootnote, false);
120 TestEnvironment tEnv = new TestEnvironment(oFootnote);
122 tEnv.addObjRelation("CONTENT", UnoRuntime.queryInterface(XTextContent.class,instance));
123 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
125 log.println( "adding InstDescriptor object" );
126 FrameDsc tDsc = new FrameDsc( 3000, 6000 );
127 log.println( "adding InstCreator object" );
128 tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
130 return tEnv;
133 } // finish class SwXFootnote