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