xref: /AOO41X/main/qadevOOo/tests/java/mod/_sw/SwXFootnoteProperties.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sw;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.text.XFootnote;
40 import com.sun.star.text.XFootnotesSupplier;
41 import com.sun.star.text.XText;
42 import com.sun.star.text.XTextCursor;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 
48 /**
49  * Test for the object, which is represented as set of footnote properties
50  * (instance of <code>com.sun.star.text.FootnoteSettings</code> service).
51  * Object implements the following interfaces :
52  * <ul>
53  *  <li> <code>com::sun::star::text::FootnoteSettings</code></li>
54  * </ul> <p>
55  * This object test <b> is NOT </b> designed to be run in several
56  * threads concurently.
57  * @see com.sun.star.text.FootnoteSettings
58  * @see ifc.text._FootnoteSettings
59  */
60 public class SwXFootnoteProperties extends TestCase {
61     XTextDocument xTextDoc;
62 
63     /**
64     * Creates text document.
65     */
66     protected void initialize( TestParameters tParam, PrintWriter log ) {
67         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
68         try {
69             log.println( "creating a textdocument" );
70             xTextDoc = SOF.createTextDoc( null );
71         } catch ( com.sun.star.uno.Exception e ) {
72             e.printStackTrace( log );
73             throw new StatusException( "Couldn't create document", e );
74         }
75     }
76 
77     /**
78     * Disposes text document.
79     */
80     protected void cleanup( TestParameters tParam, PrintWriter log ) {
81         log.println( "    disposing xTextDoc " );
82         util.DesktopTools.closeDoc(xTextDoc);
83     }
84 
85     /**
86     * Creating a Testenvironment for the interfaces to be tested.
87     * Creates an instance of the service
88     * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
89     * to the text document, and finally gets footnote settings from text
90     * document through <code>XFootnotesSupplier</code> interface.<br>
91     */
92     public synchronized TestEnvironment createTestEnvironment(
93             TestParameters Param, PrintWriter log ) throws StatusException {
94         XFootnotesSupplier oInterface = null;
95         XInterface oObj = null;
96         XFootnote oFootnote;
97 
98         log.println( "Creating a test environment" );
99         // get a soffice factory object
100         XMultiServiceFactory msf = (XMultiServiceFactory)
101             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
102         log.println("creating a footnote");
103 
104         try {
105             oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class,
106                     msf.createInstance("com.sun.star.text.Footnote"));
107         } catch (com.sun.star.uno.Exception e) {
108             e.printStackTrace(log);
109             throw new StatusException("Couldn't create footnote", e);
110         }
111 
112         XText oText = xTextDoc.getText();
113         XTextCursor oCursor = oText.createTextCursor();
114 
115         log.println("inserting the footnote into text document");
116         try {
117             oText.insertTextContent(oCursor, oFootnote, false);
118         } catch (com.sun.star.lang.IllegalArgumentException e) {
119             e.printStackTrace(log);
120             throw new StatusException("Couldn't insert the footnote", e);
121         }
122 
123         oInterface = (XFootnotesSupplier)
124             UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc);
125         oObj = oInterface.getFootnoteSettings();
126 
127         TestEnvironment tEnv = new TestEnvironment(oObj);
128         return tEnv;
129     }
130 
131 }
132 
133