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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
28 import util
.InstCreator
;
29 import util
.SOfficeFactory
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XFootnote
;
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
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.text.Footnote</code>. <p>
42 * Object implements the following interfaces :
44 * <li> <code>com::sun::star::text::XFootnote</code></li>
45 * <li> <code>com::sun::star::lang::XComponent</code></li>
46 * <li> <code>com::sun::star::text::XSimpleText</code></li>
47 * <li> <code>com::sun::star::text::Footnote</code></li>
48 * <li> <code>com::sun::star::text::XTextContent</code></li>
49 * <li> <code>com::sun::star::text::XTextRange</code></li>
50 * <li> <code>com::sun::star::text::XText</code></li>
52 * This object test <b> is NOT </b> designed to be run in several
53 * threads concurently.
54 * @see com.sun.star.text.XFootnote
55 * @see com.sun.star.lang.XComponent
56 * @see com.sun.star.text.XSimpleText
57 * @see com.sun.star.text.Footnote
58 * @see com.sun.star.text.XTextContent
59 * @see com.sun.star.text.XTextRange
60 * @see com.sun.star.text.XText
61 * @see ifc.text._XFootnote
62 * @see ifc.lang._XComponent
63 * @see ifc.text._XSimpleText
64 * @see ifc.text._Footnote
65 * @see ifc.text._XTextContent
66 * @see ifc.text._XTextRange
67 * @see ifc.text._XText
69 public class SwXFootnote
extends TestCase
{
70 XTextDocument xTextDoc
;
73 * Creates text document.
76 protected void initialize( TestParameters tParam
, PrintWriter log
) {
77 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
79 log
.println( "creating a textdocument" );
80 xTextDoc
= SOF
.createTextDoc( null );
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Disposes text document.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xTextDoc " );
93 util
.DesktopTools
.closeDoc(xTextDoc
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.text.Footnote</code>. Then inserts created footnote
100 * to a text of document as content.
101 * Object relations created :
103 * <li><code>'XTEXTINFO'</code> for
104 * {@link ifc.text._XText} </li>
108 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
111 log
.println( "Creating a test environment" );
112 // get a soffice factory object
113 XMultiServiceFactory msf
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
114 log
.println("creating a footnote");
115 Object instance
= null;
117 oFootnote
= UnoRuntime
.queryInterface(XFootnote
.class,
118 msf
.createInstance("com.sun.star.text.Footnote"));
119 instance
= msf
.createInstance("com.sun.star.text.Footnote");
120 } catch (com
.sun
.star
.uno
.Exception e
) {
121 e
.printStackTrace(log
);
122 throw new StatusException("Couldn't create footnote", e
);
125 XText oText
= xTextDoc
.getText();
126 XTextCursor oCursor
= oText
.createTextCursor();
128 log
.println("inserting the footnote into text document");
130 oText
.insertTextContent(oCursor
, oFootnote
, false);
131 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
132 e
.printStackTrace(log
);
133 throw new StatusException("Couldn't insert the footnote", e
);
136 TestEnvironment tEnv
= new TestEnvironment(oFootnote
);
138 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
139 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
141 log
.println( "adding InstDescriptor object" );
142 FrameDsc tDsc
= new FrameDsc( 3000, 6000 );
143 log
.println( "adding InstCreator object" );
144 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
149 } // finish class SwXFootnote