bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXFootnoteProperties.java
blob4659f0198e93ccfc0bba62761e920989c181740f
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 protected void initialize( TestParameters tParam, PrintWriter log ) {
58 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
59 try {
60 log.println( "creating a textdocument" );
61 xTextDoc = SOF.createTextDoc( null );
62 } catch ( com.sun.star.uno.Exception e ) {
63 e.printStackTrace( log );
64 throw new StatusException( "Couldn't create document", e );
68 /**
69 * Disposes text document.
71 protected void cleanup( TestParameters tParam, PrintWriter log ) {
72 log.println( " disposing xTextDoc " );
73 util.DesktopTools.closeDoc(xTextDoc);
76 /**
77 * Creating a Testenvironment for the interfaces to be tested.
78 * Creates an instance of the service
79 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
80 * to the text document, and finally gets footnote settings from text
81 * document through <code>XFootnotesSupplier</code> interface.<br>
83 public synchronized TestEnvironment createTestEnvironment(
84 TestParameters Param, PrintWriter log ) throws StatusException {
85 XFootnotesSupplier oInterface = null;
86 XInterface oObj = null;
87 XFootnote oFootnote;
89 log.println( "Creating a test environment" );
90 // get a soffice factory object
91 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
92 log.println("creating a footnote");
94 try {
95 oFootnote = UnoRuntime.queryInterface(XFootnote.class,
96 msf.createInstance("com.sun.star.text.Footnote"));
97 } catch (com.sun.star.uno.Exception e) {
98 e.printStackTrace(log);
99 throw new StatusException("Couldn't create footnote", e);
102 XText oText = xTextDoc.getText();
103 XTextCursor oCursor = oText.createTextCursor();
105 log.println("inserting the footnote into text document");
106 try {
107 oText.insertTextContent(oCursor, oFootnote, false);
108 } catch (com.sun.star.lang.IllegalArgumentException e) {
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't insert the footnote", e);
113 oInterface = UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc);
114 oObj = oInterface.getFootnoteSettings();
116 TestEnvironment tEnv = new TestEnvironment(oObj);
117 return tEnv;