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: SwXFootnoteText.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
.InstCreator
;
40 import util
.ParagraphDsc
;
41 import util
.SOfficeFactory
;
42 import util
.TextSectionDsc
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.text
.XFootnote
;
46 import com
.sun
.star
.text
.XSimpleText
;
47 import com
.sun
.star
.text
.XText
;
48 import com
.sun
.star
.text
.XTextCursor
;
49 import com
.sun
.star
.text
.XTextDocument
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
54 * Object implements the following interfaces :
56 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
57 * <li> <code>com::sun::star::text::XSimpleText</code></li>
58 * <li> <code>com::sun::star::text::XTextRange</code></li>
59 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
60 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
61 * <li> <code>com::sun::star::container::XElementAccess</code></li>
62 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
63 * <li> <code>com::sun::star::text::XText</code></li>
65 * This object test <b> is NOT </b> designed to be run in several
66 * threads concurently.
67 * @see com.sun.star.text.XTextRangeMover
68 * @see com.sun.star.text.XSimpleText
69 * @see com.sun.star.text.XTextRange
70 * @see com.sun.star.text.XRelativeTextContentInsert
71 * @see com.sun.star.text.XTextRangeCompare
72 * @see com.sun.star.container.XElementAccess
73 * @see com.sun.star.container.XEnumerationAccess
74 * @see com.sun.star.text.XText
75 * @see ifc.text._XTextRangeMover
76 * @see ifc.text._XSimpleText
77 * @see ifc.text._XTextRange
78 * @see ifc.text._XRelativeTextContentInsert
79 * @see ifc.text._XTextRangeCompare
80 * @see ifc.container._XElementAccess
81 * @see ifc.container._XEnumerationAccess
82 * @see ifc.text._XText
84 public class SwXFootnoteText
extends TestCase
{
85 XTextDocument xTextDoc
;
89 * Creates text document.
91 protected void initialize( TestParameters tParam
, PrintWriter log
) {
92 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
94 log
.println( "creating a textdocument" );
95 xTextDoc
= SOF
.createTextDoc( null );
96 } catch ( com
.sun
.star
.uno
.Exception e
) {
97 e
.printStackTrace( log
);
98 throw new StatusException( "Couldn't create document", e
);
103 * Disposes text document.
105 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
106 log
.println( " disposing xTextDoc " );
107 util
.DesktopTools
.closeDoc(xTextDoc
);
111 * Creating a Testenvironment for the interfaces to be tested.
112 * Creates an instance of the service
113 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote
114 * to the text, and finally sets a string to the footnote. Then the text
115 * gotten from the footnote is returned as tested component.<br>
116 * Object relations created :
118 * <li> <code>'TEXT'</code> for
119 * {@link ifc.text._XTextRangeCompare} : footnote text</li>
120 * <li> <code>'XTEXTINFO'</code> for
121 * {@link ifc.text._XRelativeTextContentInsert},
122 * {@link ifc.text._XText} : text section creator</li>
123 * <li> <code>'PARA'</code> for
124 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
127 public synchronized TestEnvironment
createTestEnvironment(
128 TestParameters tParam
, PrintWriter log
) throws StatusException
{
129 XInterface oObj
= null;
132 log
.println( "creating a test environment" );
133 XMultiServiceFactory msf
= (XMultiServiceFactory
)
134 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
135 log
.println("creating a footnote");
138 oFootnote
= (XFootnote
)UnoRuntime
.queryInterface(XFootnote
.class,
139 msf
.createInstance("com.sun.star.text.Footnote"));
140 } catch (com
.sun
.star
.uno
.Exception e
) {
141 e
.printStackTrace(log
);
142 throw new StatusException("Couldn't create footnote", e
);
145 XText oText
= xTextDoc
.getText();
146 XTextCursor oCursor
= oText
.createTextCursor();
148 log
.println("inserting the footnote into text document");
150 oText
.insertTextContent(oCursor
, oFootnote
, false);
151 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
152 e
.printStackTrace(log
);
153 throw new StatusException("Couldn't insert the footnote", e
);
156 XSimpleText oFootText
= (XSimpleText
)
157 UnoRuntime
.queryInterface(XSimpleText
.class, oFootnote
);
158 oFootText
.setString("SwXFootnoteText");
160 oObj
= oFootText
.getText();
162 TestEnvironment tEnv
= new TestEnvironment(oObj
);
164 log
.println( "adding TextDocument as mod relation to environment" );
165 tEnv
.addObjRelation("TEXT", (XText
) oObj
);
167 TextSectionDsc tDsc
= new TextSectionDsc();
168 log
.println( " adding InstCreator object" );
169 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
171 log
.println( " adding Paragraph" );
172 ParagraphDsc pDsc
= new ParagraphDsc();
173 tEnv
.addObjRelation( "PARA", new InstCreator( xTextDoc
, pDsc
) );
176 } // finish method getTestEnvironment
178 } // finish class SwXFootnoteText