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: SwXFootnote.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
;
40 import util
.InstCreator
;
41 import util
.SOfficeFactory
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XFootnote
;
45 import com
.sun
.star
.text
.XText
;
46 import com
.sun
.star
.text
.XTextContent
;
47 import com
.sun
.star
.text
.XTextCursor
;
48 import com
.sun
.star
.text
.XTextDocument
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
52 * Test for object which is represented by service
53 * <code>com.sun.star.text.Footnote</code>. <p>
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::text::XFootnote</code></li>
57 * <li> <code>com::sun::star::lang::XComponent</code></li>
58 * <li> <code>com::sun::star::text::XSimpleText</code></li>
59 * <li> <code>com::sun::star::text::Footnote</code></li>
60 * <li> <code>com::sun::star::text::XTextContent</code></li>
61 * <li> <code>com::sun::star::text::XTextRange</code></li>
62 * <li> <code>com::sun::star::text::XText</code></li>
64 * This object test <b> is NOT </b> designed to be run in several
65 * threads concurently.
66 * @see com.sun.star.text.XFootnote
67 * @see com.sun.star.lang.XComponent
68 * @see com.sun.star.text.XSimpleText
69 * @see com.sun.star.text.Footnote
70 * @see com.sun.star.text.XTextContent
71 * @see com.sun.star.text.XTextRange
72 * @see com.sun.star.text.XText
73 * @see ifc.text._XFootnote
74 * @see ifc.lang._XComponent
75 * @see ifc.text._XSimpleText
76 * @see ifc.text._Footnote
77 * @see ifc.text._XTextContent
78 * @see ifc.text._XTextRange
79 * @see ifc.text._XText
81 public class SwXFootnote
extends TestCase
{
82 XTextDocument xTextDoc
;
85 * Creates text document.
87 protected void initialize( TestParameters tParam
, PrintWriter log
) {
88 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
90 log
.println( "creating a textdocument" );
91 xTextDoc
= SOF
.createTextDoc( null );
92 } catch ( com
.sun
.star
.uno
.Exception e
) {
93 e
.printStackTrace( log
);
94 throw new StatusException( "Couldn't create document", e
);
99 * Disposes text document.
101 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
102 log
.println( " disposing xTextDoc " );
103 util
.DesktopTools
.closeDoc(xTextDoc
);
107 * Creating a Testenvironment for the interfaces to be tested.
108 * Creates an instance of the service
109 * <code>com.sun.star.text.Footnote</code>. Then inserts created footnote
110 * to a text of document as content.
111 * Object relations created :
113 * <li><code>'XTEXTINFO'</code> for
114 * {@link ifc.text._XText} </li>
117 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
120 log
.println( "Creating a test environment" );
121 // get a soffice factory object
122 XMultiServiceFactory msf
= (XMultiServiceFactory
)
123 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
124 log
.println("creating a footnote");
125 Object instance
= null;
127 oFootnote
= (XFootnote
) UnoRuntime
.queryInterface(XFootnote
.class,
128 msf
.createInstance("com.sun.star.text.Footnote"));
129 instance
= msf
.createInstance("com.sun.star.text.Footnote");
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace(log
);
132 throw new StatusException("Couldn't create footnote", e
);
135 XText oText
= xTextDoc
.getText();
136 XTextCursor oCursor
= oText
.createTextCursor();
138 log
.println("inserting the footnote into text document");
140 oText
.insertTextContent(oCursor
, oFootnote
, false);
141 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException("Couldn't insert the footnote", e
);
146 TestEnvironment tEnv
= new TestEnvironment(oFootnote
);
148 tEnv
.addObjRelation("CONTENT", (XTextContent
)
149 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
150 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
152 log
.println( "adding InstDescriptor object" );
153 FrameDsc tDsc
= new FrameDsc( 3000, 6000 );
154 log
.println( "adding InstCreator object" );
155 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
160 } // finish class SwXFootnote