bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXEndnoteProperties.java
blob87d1dc9aa2b4b162e09f252c42c254465316d500
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;
28 import util.dbg;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XEndnotesSupplier;
33 import com.sun.star.text.XText;
34 import com.sun.star.text.XTextContent;
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 * Test for object which is represented by service
42 * <code>com.sun.star.text.FootnoteSettings</code>. <p>
43 * Object implements the following interfaces :
44 * <ul>
45 * <li> <code>com::sun::star::text::FootnoteSettings</code></li>
46 * </ul> <p>
47 * This object test <b> is NOT </b> designed to be run in several
48 * threads concurently.
49 * @see com.sun.star.text.FootnoteSettings
50 * @see ifc.text._FootnoteSettings
52 public class SwXEndnoteProperties extends TestCase {
53 XTextDocument xTextDoc;
55 /**
56 * Creates text document.
58 protected void initialize( TestParameters tParam, PrintWriter log ) {
59 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)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 protected void cleanup( TestParameters tParam, PrintWriter log ) {
73 log.println( " disposing xTextDoc " );
74 util.DesktopTools.closeDoc(xTextDoc);
77 /**
78 * Creating a Testenvironment for the interfaces to be tested.
79 * Creates an instance of the service
80 * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted
81 * to the text document, and finally endnote settings are gotten from text
82 * document using <code>XEndnotesSupplier</code> interface.
84 public synchronized TestEnvironment createTestEnvironment(
85 TestParameters Param, PrintWriter log ) throws StatusException {
86 XEndnotesSupplier oInterface = null;
87 XInterface oObj = null;
88 XInterface oEndnote;
90 log.println( "Creating a test environment" );
91 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
92 log.println("creating a endnote");
93 try {
94 oEndnote = UnoRuntime.queryInterface(XInterface.class,
95 msf.createInstance("com.sun.star.text.Endnote"));
96 } catch (com.sun.star.uno.Exception e) {
97 e.printStackTrace(log);
98 throw new StatusException("Couldn't create endnote", e);
101 XText oText = xTextDoc.getText();
102 XTextCursor oCursor = oText.createTextCursor();
104 log.println("inserting the footnote into text document");
105 XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote);
106 try {
107 oText.insertTextContent(oCursor, xTC, false);
108 } catch (com.sun.star.lang.IllegalArgumentException e) {
109 e.printStackTrace(log);
110 throw new StatusException("Couldn't insert the endnote", e);
113 oInterface = UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc);
114 oObj = oInterface.getEndnoteSettings();
115 dbg.printPropertiesNames((XPropertySet) oObj);
117 TestEnvironment tEnv = new TestEnvironment(oObj);
118 return tEnv;