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.InstCreator;
33 import util.ParagraphDsc;
34 import util.SOfficeFactory;
35 import util.TextSectionDsc;
36 
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.text.XFootnote;
39 import com.sun.star.text.XSimpleText;
40 import com.sun.star.text.XText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 
46 /**
47  * Object implements the following interfaces :
48  * <ul>
49  *  <li> <code>com::sun::star::text::XTextRangeMover</code></li>
50  *  <li> <code>com::sun::star::text::XSimpleText</code></li>
51  *  <li> <code>com::sun::star::text::XTextRange</code></li>
52  *  <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
53  *  <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
54  *  <li> <code>com::sun::star::container::XElementAccess</code></li>
55  *  <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
56  *  <li> <code>com::sun::star::text::XText</code></li>
57  * </ul> <p>
58  * This object test <b> is NOT </b> designed to be run in several
59  * threads concurently.
60  * @see com.sun.star.text.XTextRangeMover
61  * @see com.sun.star.text.XSimpleText
62  * @see com.sun.star.text.XTextRange
63  * @see com.sun.star.text.XRelativeTextContentInsert
64  * @see com.sun.star.text.XTextRangeCompare
65  * @see com.sun.star.container.XElementAccess
66  * @see com.sun.star.container.XEnumerationAccess
67  * @see com.sun.star.text.XText
68  * @see ifc.text._XTextRangeMover
69  * @see ifc.text._XSimpleText
70  * @see ifc.text._XTextRange
71  * @see ifc.text._XRelativeTextContentInsert
72  * @see ifc.text._XTextRangeCompare
73  * @see ifc.container._XElementAccess
74  * @see ifc.container._XEnumerationAccess
75  * @see ifc.text._XText
76  */
77 public class SwXFootnoteText extends TestCase {
78     XTextDocument xTextDoc;
79     SOfficeFactory SOF;
80 
81     /**
82     * Creates text document.
83     */
initialize( TestParameters tParam, PrintWriter log )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     */
cleanup( TestParameters tParam, PrintWriter log )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 the text, and finally sets a string to the footnote. Then the text
108     * gotten from the footnote is returned as tested component.<br>
109     *     Object relations created :
110     * <ul>
111     *  <li> <code>'TEXT'</code> for
112     *    {@link ifc.text._XTextRangeCompare} : footnote text</li>
113     *  <li> <code>'XTEXTINFO'</code> for
114     *    {@link ifc.text._XRelativeTextContentInsert},
115     *    {@link ifc.text._XText} : text section creator</li>
116     *  <li> <code>'PARA'</code> for
117     *    {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
118     * </ul>
119     */
createTestEnvironment( TestParameters tParam, PrintWriter log )120     public synchronized TestEnvironment createTestEnvironment(
121             TestParameters tParam, PrintWriter log ) throws StatusException {
122         XInterface oObj = null;
123         XFootnote oFootnote;
124 
125         log.println( "creating a test environment" );
126         XMultiServiceFactory msf = (XMultiServiceFactory)
127             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
128         log.println("creating a footnote");
129 
130         try {
131             oFootnote = (XFootnote)UnoRuntime.queryInterface(XFootnote.class,
132                     msf.createInstance("com.sun.star.text.Footnote"));
133         } catch (com.sun.star.uno.Exception e) {
134             e.printStackTrace(log);
135             throw new StatusException("Couldn't create footnote", e);
136         }
137 
138         XText oText = xTextDoc.getText();
139         XTextCursor oCursor = oText.createTextCursor();
140 
141         log.println("inserting the footnote into text document");
142         try {
143             oText.insertTextContent(oCursor, oFootnote, false);
144         } catch (com.sun.star.lang.IllegalArgumentException e) {
145             e.printStackTrace(log);
146             throw new StatusException("Couldn't insert the footnote", e);
147         }
148 
149         XSimpleText oFootText = (XSimpleText)
150             UnoRuntime.queryInterface(XSimpleText.class, oFootnote);
151         oFootText.setString("SwXFootnoteText");
152 
153         oObj = oFootText.getText();
154 
155         TestEnvironment tEnv = new TestEnvironment(oObj);
156 
157         log.println( "adding TextDocument as mod relation to environment" );
158         tEnv.addObjRelation("TEXT", (XText) oObj);
159 
160         TextSectionDsc tDsc = new TextSectionDsc();
161         log.println( "    adding InstCreator object" );
162         tEnv.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc, tDsc ) );
163 
164         log.println( "    adding Paragraph" );
165         ParagraphDsc pDsc = new ParagraphDsc();
166         tEnv.addObjRelation( "PARA", new InstCreator( xTextDoc, pDsc ) );
167 
168         return tEnv;
169     } // finish method getTestEnvironment
170 
171 }    // finish class SwXFootnoteText
172 
173