Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteProperties.java
blobc86bc30c7fff5ececdf356187ea7e0a1cf67e26e
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.SOfficeFactory;
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.text.XFootnote;
30 import com.sun.star.text.XFootnotesSupplier;
31 import com.sun.star.text.XText;
32 import com.sun.star.text.XTextCursor;
33 import com.sun.star.text.XTextDocument;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.uno.XInterface;
38 /**
39 * Test for the object, which is represented as set of footnote properties
40 * (instance of <code>com.sun.star.text.FootnoteSettings</code> service).
41 * Object implements the following interfaces :
42 * <ul>
43 * <li> <code>com::sun::star::text::FootnoteSettings</code></li>
44 * </ul> <p>
45 * This object test <b> is NOT </b> designed to be run in several
46 * threads concurrently.
47 * @see com.sun.star.text.FootnoteSettings
48 * @see ifc.text._FootnoteSettings
50 public class SwXFootnoteProperties extends TestCase {
51 XTextDocument xTextDoc;
53 /**
54 * Creates text document.
56 @Override
57 protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
58 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
59 log.println( "creating a textdocument" );
60 xTextDoc = SOF.createTextDoc( null );
63 /**
64 * Disposes text document.
66 @Override
67 protected void cleanup( TestParameters tParam, PrintWriter log ) {
68 log.println( " disposing xTextDoc " );
69 util.DesktopTools.closeDoc(xTextDoc);
72 /**
73 * Creating a TestEnvironment for the interfaces to be tested.
74 * Creates an instance of the service
75 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
76 * to the text document, and finally gets footnote settings from text
77 * document through <code>XFootnotesSupplier</code> interface.<br>
79 @Override
80 public TestEnvironment createTestEnvironment(
81 TestParameters Param, PrintWriter log ) throws Exception {
82 XFootnotesSupplier oInterface = null;
83 XInterface oObj = null;
84 XFootnote oFootnote;
86 log.println( "Creating a test environment" );
87 // get a soffice factory object
88 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
89 log.println("creating a footnote");
91 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
92 msf.createInstance("com.sun.star.text.Footnote"));
94 XText oText = xTextDoc.getText();
95 XTextCursor oCursor = oText.createTextCursor();
97 log.println("inserting the footnote into text document");
98 oText.insertTextContent(oCursor, oFootnote, false);
100 oInterface = UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc);
101 oObj = oInterface.getFootnoteSettings();
103 TestEnvironment tEnv = new TestEnvironment(oObj);
104 return tEnv;