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.SOfficeFactory;
33 import util.dbg;
34 
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.text.XEndnotesSupplier;
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 import com.sun.star.uno.XInterface;
44 
45 /**
46  * Test for object which is represented by service
47  * <code>com.sun.star.text.FootnoteSettings</code>. <p>
48  * Object implements the following interfaces :
49  * <ul>
50  *  <li> <code>com::sun::star::text::FootnoteSettings</code></li>
51  * </ul> <p>
52  * This object test <b> is NOT </b> designed to be run in several
53  * threads concurently.
54  * @see com.sun.star.text.FootnoteSettings
55  * @see ifc.text._FootnoteSettings
56  */
57 public class SwXEndnoteProperties extends TestCase {
58     XTextDocument xTextDoc;
59 
60     /**
61     * Creates text document.
62     */
initialize( TestParameters tParam, PrintWriter log )63     protected void initialize( TestParameters tParam, PrintWriter log ) {
64         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
65         try {
66             log.println( "creating a textdocument" );
67             xTextDoc = SOF.createTextDoc( null );
68         } catch ( com.sun.star.uno.Exception e ) {
69             e.printStackTrace( log );
70             throw new StatusException( "Couldn't create document", e );
71         }
72     }
73 
74     /**
75     * Disposes text document.
76     */
cleanup( TestParameters tParam, PrintWriter log )77     protected void cleanup( TestParameters tParam, PrintWriter log ) {
78         log.println( "    disposing xTextDoc " );
79         util.DesktopTools.closeDoc(xTextDoc);
80     }
81 
82     /**
83     * Creating a Testenvironment for the interfaces to be tested.
84     * Creates an instance of the service
85     * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted
86     * to the text document, and finally endnote settings are gotten from text
87     * document using <code>XEndnotesSupplier</code> interface.
88     */
createTestEnvironment( TestParameters Param, PrintWriter log )89     public synchronized TestEnvironment createTestEnvironment(
90             TestParameters Param, PrintWriter log ) throws StatusException {
91         XEndnotesSupplier oInterface = null;
92         XInterface oObj = null;
93         XInterface oEndnote;
94 
95         log.println( "Creating a test environment" );
96         XMultiServiceFactory msf = (XMultiServiceFactory)
97             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
98         log.println("creating a endnote");
99         try {
100             oEndnote = (XInterface) UnoRuntime.queryInterface(XInterface.class,
101                     msf.createInstance("com.sun.star.text.Endnote"));
102         } catch (com.sun.star.uno.Exception e) {
103             e.printStackTrace(log);
104             throw new StatusException("Couldn't create endnote", e);
105         }
106 
107         XText oText = xTextDoc.getText();
108         XTextCursor oCursor = oText.createTextCursor();
109 
110         log.println("inserting the footnote into text document");
111         XTextContent xTC = (XTextContent)
112             UnoRuntime.queryInterface(XTextContent.class, oEndnote);
113         try {
114             oText.insertTextContent(oCursor, xTC, false);
115         } catch (com.sun.star.lang.IllegalArgumentException e) {
116             e.printStackTrace(log);
117             throw new StatusException("Couldn't insert the endnote", e);
118         }
119 
120         oInterface = (XEndnotesSupplier)
121             UnoRuntime.queryInterface(XEndnotesSupplier.class, xTextDoc);
122         oObj = oInterface.getEndnoteSettings();
123         dbg.printPropertiesNames((XPropertySet) oObj);
124 
125         TestEnvironment tEnv = new TestEnvironment(oObj);
126         return tEnv;
127     }
128 
129 }
130 
131