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