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 
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.XDocumentIndexMark;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextCursor;
39 import com.sun.star.text.XTextDocument;
40 import com.sun.star.uno.UnoRuntime;
41 
42 
43 /**
44  * Test for object which is represented by service
45  * <code>com.sun.star.text.DocumentIndexMark</code>. <p>
46  * Object implements the following interfaces :
47  * <ul>
48  *  <li> <code>com::sun::star::lang::XComponent</code></li>
49  *  <li> <code>com::sun::star::text::BaseIndexMark</code></li>
50  *  <li> <code>com::sun::star::text::XTextContent</code></li>
51  *  <li> <code>com::sun::star::text::TextContent</code></li>
52  *  <li> <code>com::sun::star::text::DocumentIndexMark</code></li>
53  * </ul> <p>
54  * This object test <b> is NOT </b> designed to be run in several
55  * threads concurently.
56  * @see com.sun.star.lang.XComponent
57  * @see com.sun.star.text.BaseIndexMark
58  * @see com.sun.star.text.XTextContent
59  * @see com.sun.star.text.TextContent
60  * @see com.sun.star.text.DocumentIndexMark
61  * @see ifc.lang._XComponent
62  * @see ifc.text._BaseIndexMark
63  * @see ifc.text._XTextContent
64  * @see ifc.text._TextContent
65  * @see ifc.text._DocumentIndexMark
66  */
67 public class SwXDocumentIndexMark extends TestCase {
68     XTextDocument xTextDoc;
69 
70     /**
71     * Creates text document.
72     */
initialize( TestParameters tParam, PrintWriter log )73     protected void initialize( TestParameters tParam, PrintWriter log ) {
74         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
75         try {
76             log.println( "creating a textdocument" );
77             xTextDoc = SOF.createTextDoc( null );
78         } catch ( com.sun.star.uno.Exception e ) {
79             e.printStackTrace( log );
80             throw new StatusException( "Couldn't create document", e );
81         }
82     }
83 
84     /**
85     * Disposes text document.
86     */
cleanup( TestParameters tParam, PrintWriter log )87     protected void cleanup( TestParameters tParam, PrintWriter log ) {
88         log.println( "    disposing xTextDoc " );
89         util.DesktopTools.closeDoc(xTextDoc);
90     }
91 
92 
93     /**
94     * Creating a Testenvironment for the interfaces to be tested.
95     * Creates an instance of the service
96     * <code>com.sun.star.text.DocumentIndexMark</code>, attaches text to
97     * created DocumentIndexMark, and inserts DocumentIndexMark to the
98     * text document.
99     */
createTestEnvironment(TestParameters tParam, PrintWriter log)100     protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
101 
102         XText oText = xTextDoc.getText();
103         XTextCursor oCursor = oText.createTextCursor();
104 
105         XMultiServiceFactory oDocMSF = (XMultiServiceFactory)
106             UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc);
107 
108         Object oDIM = null;
109         Object instance = null;
110         try {
111             oDIM = oDocMSF.createInstance
112                 ("com.sun.star.text.DocumentIndexMark");
113             instance = oDocMSF.createInstance
114                 ("com.sun.star.text.DocumentIndexMark");
115         } catch ( com.sun.star.uno.Exception e ) {
116             log.println("Error:" + e);
117         }
118 
119         XDocumentIndexMark xDIM = (XDocumentIndexMark)
120             UnoRuntime.queryInterface(XDocumentIndexMark.class, oDIM);
121 
122         try {
123             oText.insertTextContent(oCursor, xDIM, false);
124         } catch (com.sun.star.lang.IllegalArgumentException e) {
125             e.printStackTrace(log);
126             throw new StatusException
127                 ("Couldn't insert the DocumentIndexMark", e);
128         }
129 
130         TestEnvironment tEnv = new TestEnvironment(xDIM);
131 
132         tEnv.addObjRelation("CONTENT", (XTextContent)
133                         UnoRuntime.queryInterface(XTextContent.class,instance));
134         tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
135 
136         return tEnv;
137 
138     } // finish method getTestEnvironment
139 
140  }    // finish class SwXDocumentIndexMark
141 
142