bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteProperties.java
blobde75d200e95fd5015a23ffd5610e2c1ce0ba72e2
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.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.text.XFootnote;
31 import com.sun.star.text.XFootnotesSupplier;
32 import com.sun.star.text.XText;
33 import com.sun.star.text.XTextCursor;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.UnoRuntime;
36 import com.sun.star.uno.XInterface;
39 /**
40 * Test for the object, which is represented as set of footnote properties
41 * (instance of <code>com.sun.star.text.FootnoteSettings</code> service).
42 * Object implements the following interfaces :
43 * <ul>
44 * <li> <code>com::sun::star::text::FootnoteSettings</code></li>
45 * </ul> <p>
46 * This object test <b> is NOT </b> designed to be run in several
47 * threads concurently.
48 * @see com.sun.star.text.FootnoteSettings
49 * @see ifc.text._FootnoteSettings
51 public class SwXFootnoteProperties extends TestCase {
52 XTextDocument xTextDoc;
54 /**
55 * Creates text document.
57 @Override
58 protected void initialize( TestParameters tParam, PrintWriter log ) {
59 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
60 try {
61 log.println( "creating a textdocument" );
62 xTextDoc = SOF.createTextDoc( null );
63 } catch ( com.sun.star.uno.Exception e ) {
64 e.printStackTrace( log );
65 throw new StatusException( "Couldn't create document", e );
69 /**
70 * Disposes text document.
72 @Override
73 protected void cleanup( TestParameters tParam, PrintWriter log ) {
74 log.println( " disposing xTextDoc " );
75 util.DesktopTools.closeDoc(xTextDoc);
78 /**
79 * Creating a Testenvironment for the interfaces to be tested.
80 * Creates an instance of the service
81 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
82 * to the text document, and finally gets footnote settings from text
83 * document through <code>XFootnotesSupplier</code> interface.<br>
85 @Override
86 public synchronized TestEnvironment createTestEnvironment(
87 TestParameters Param, PrintWriter log ) throws StatusException {
88 XFootnotesSupplier oInterface = null;
89 XInterface oObj = null;
90 XFootnote oFootnote;
92 log.println( "Creating a test environment" );
93 // get a soffice factory object
94 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
95 log.println("creating a footnote");
97 try {
98 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
99 msf.createInstance("com.sun.star.text.Footnote"));
100 } catch (com.sun.star.uno.Exception e) {
101 e.printStackTrace(log);
102 throw new StatusException("Couldn't create footnote", e);
105 XText oText = xTextDoc.getText();
106 XTextCursor oCursor = oText.createTextCursor();
108 log.println("inserting the footnote into text document");
109 try {
110 oText.insertTextContent(oCursor, oFootnote, false);
111 } catch (com.sun.star.lang.IllegalArgumentException e) {
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't insert the footnote", e);
116 oInterface = UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc);
117 oObj = oInterface.getFootnoteSettings();
119 TestEnvironment tEnv = new TestEnvironment(oObj);
120 return tEnv;