Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXEndnoteProperties.java
blobb6a101ce98a43334981f97b3bf397343506005dc
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 @Override
59 protected void initialize( TestParameters tParam, PrintWriter log ) {
60 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
61 try {
62 log.println( "creating a textdocument" );
63 xTextDoc = SOF.createTextDoc( null );
64 } catch ( com.sun.star.uno.Exception e ) {
65 e.printStackTrace( log );
66 throw new StatusException( "Couldn't create document", e );
70 /**
71 * Disposes text document.
73 @Override
74 protected void cleanup( TestParameters tParam, PrintWriter log ) {
75 log.println( " disposing xTextDoc " );
76 util.DesktopTools.closeDoc(xTextDoc);
79 /**
80 * Creating a Testenvironment for the interfaces to be tested.
81 * Creates an instance of the service
82 * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted
83 * to the text document, and finally endnote settings are gotten from text
84 * document using <code>XEndnotesSupplier</code> interface.
86 @Override
87 public synchronized TestEnvironment createTestEnvironment(
88 TestParameters Param, PrintWriter log ) throws StatusException {
89 XEndnotesSupplier oInterface = null;
90 XInterface oObj = null;
91 XInterface oEndnote;
93 log.println( "Creating a test environment" );
94 XMultiServiceFactory msf = UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
95 log.println("creating a endnote");
96 try {
97 oEndnote = UnoRuntime.queryInterface(XInterface.class,
98 msf.createInstance("com.sun.star.text.Endnote"));
99 } catch (com.sun.star.uno.Exception e) {
100 e.printStackTrace(log);
101 throw new StatusException("Couldn't create endnote", e);
104 XText oText = xTextDoc.getText();
105 XTextCursor oCursor = oText.createTextCursor();
107 log.println("inserting the footnote into text document");
108 XTextContent xTC = UnoRuntime.queryInterface(XTextContent.class, oEndnote);
109 try {
110 oText.insertTextContent(oCursor, xTC, false);
111 } catch (com.sun.star.lang.IllegalArgumentException e) {
112 e.printStackTrace(log);
113 throw new StatusException("Couldn't insert the endnote", e);
116 oInterface = UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc);
117 oObj = oInterface.getEndnoteSettings();
118 dbg.printPropertiesNames((XPropertySet) oObj);
120 TestEnvironment tEnv = new TestEnvironment(oObj);
121 return tEnv;