1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sw;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.FrameDsc;
33 import util.InstCreator;
34 import util.SOfficeFactory;
35 
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.text.XFootnote;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextContent;
40 import com.sun.star.text.XTextCursor;
41 import com.sun.star.text.XTextDocument;
42 import com.sun.star.uno.UnoRuntime;
43 
44 /**
45  * Test for object which is represented by service
46  * <code>com.sun.star.text.Footnote</code>. <p>
47  * Object implements the following interfaces :
48  * <ul>
49  *  <li> <code>com::sun::star::text::XFootnote</code></li>
50  *  <li> <code>com::sun::star::lang::XComponent</code></li>
51  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
52  *  <li> <code>com::sun::star::text::Footnote</code></li>
53  *  <li> <code>com::sun::star::text::XTextContent</code></li>
54  *  <li> <code>com::sun::star::text::XTextRange</code></li>
55  *  <li> <code>com::sun::star::text::XText</code></li>
56  * </ul> <p>
57  * This object test <b> is NOT </b> designed to be run in several
58  * threads concurently.
59  * @see com.sun.star.text.XFootnote
60  * @see com.sun.star.lang.XComponent
61  * @see com.sun.star.text.XSimpleText
62  * @see com.sun.star.text.Footnote
63  * @see com.sun.star.text.XTextContent
64  * @see com.sun.star.text.XTextRange
65  * @see com.sun.star.text.XText
66  * @see ifc.text._XFootnote
67  * @see ifc.lang._XComponent
68  * @see ifc.text._XSimpleText
69  * @see ifc.text._Footnote
70  * @see ifc.text._XTextContent
71  * @see ifc.text._XTextRange
72  * @see ifc.text._XText
73  */
74 public class SwXFootnote extends TestCase {
75     XTextDocument xTextDoc;
76 
77     /**
78     * Creates text document.
79     */
initialize( TestParameters tParam, PrintWriter log )80     protected void initialize( TestParameters tParam, PrintWriter log ) {
81         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
82         try {
83             log.println( "creating a textdocument" );
84             xTextDoc = SOF.createTextDoc( null );
85         } catch ( com.sun.star.uno.Exception e ) {
86             e.printStackTrace( log );
87             throw new StatusException( "Couldn't create document", e );
88         }
89     }
90 
91     /**
92     * Disposes text document.
93     */
cleanup( TestParameters tParam, PrintWriter log )94     protected void cleanup( TestParameters tParam, PrintWriter log ) {
95         log.println( "    disposing xTextDoc " );
96         util.DesktopTools.closeDoc(xTextDoc);
97     }
98 
99     /**
100     * Creating a Testenvironment for the interfaces to be tested.
101     * Creates an instance of the service
102     * <code>com.sun.star.text.Footnote</code>. Then inserts created footnote
103     * to a text of document as content.
104     *     Object relations created :
105     * <ul>
106     *  <li><code>'XTEXTINFO'</code> for
107     *    {@link ifc.text._XText} </li>
108     * </ul>
109     */
createTestEnvironment(TestParameters Param, PrintWriter log)110     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
111         XFootnote oFootnote;
112 
113         log.println( "Creating a test environment" );
114         // get a soffice factory object
115         XMultiServiceFactory msf = (XMultiServiceFactory)
116             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
117         log.println("creating a footnote");
118         Object instance = null;
119         try {
120             oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class,
121                     msf.createInstance("com.sun.star.text.Footnote"));
122             instance = msf.createInstance("com.sun.star.text.Footnote");
123         } catch (com.sun.star.uno.Exception e) {
124             e.printStackTrace(log);
125             throw new StatusException("Couldn't create footnote", e);
126         }
127 
128         XText oText = xTextDoc.getText();
129         XTextCursor oCursor = oText.createTextCursor();
130 
131         log.println("inserting the footnote into text document");
132         try {
133             oText.insertTextContent(oCursor, oFootnote, false);
134         } catch (com.sun.star.lang.IllegalArgumentException e) {
135             e.printStackTrace(log);
136             throw new StatusException("Couldn't insert the footnote", e);
137         }
138 
139         TestEnvironment tEnv = new TestEnvironment(oFootnote);
140 
141         tEnv.addObjRelation("CONTENT", (XTextContent)
142                         UnoRuntime.queryInterface(XTextContent.class,instance));
143         tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
144 
145         log.println( "adding InstDescriptor object" );
146         FrameDsc tDsc = new FrameDsc( 3000, 6000 );
147         log.println( "adding InstCreator object" );
148         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
149 
150         return tEnv;
151     }
152 
153 }    // finish class SwXFootnote
154 
155