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