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.XTextContent;
36 import com.sun.star.text.XTextDocument;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 
40 /**
41  * Test for object which is represented by service
42  * <code>com.sun.star.text.Bookmark</code>. <p>
43  * Object implements the following interfaces :
44  * <ul>
45  *  <li> <code>com::sun::star::container::XNamed</code></li>
46  *  <li> <code>com::sun::star::lang::XComponent</code></li>
47  *  <li> <code>com::sun::star::text::XTextContent</code></li>
48  *  <li> <code>com::sun::star::text::TextContent</code></li>
49  * </ul> <p>
50  * This object test <b> is NOT </b> designed to be run in several
51  * threads concurently.
52  * @see com.sun.star.container.XNamed
53  * @see com.sun.star.lang.XComponent
54  * @see com.sun.star.text.XTextContent
55  * @see com.sun.star.text.TextContent
56  * @see ifc.container._XNamed
57  * @see ifc.lang._XComponent
58  * @see ifc.text._XTextContent
59  * @see ifc.text._TextContent
60  */
61 public class SwXBookmark extends TestCase {
62     XTextDocument xTextDoc;
63     SOfficeFactory SOF;
64 
65     /**
66     * Creates text document.
67     */
initialize( TestParameters tParam, PrintWriter log )68     protected void initialize( TestParameters tParam, PrintWriter log ) {
69         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
70         try {
71             log.println( "creating a textdocument" );
72             xTextDoc = SOF.createTextDoc( null );
73         } catch ( com.sun.star.uno.Exception e ) {
74             e.printStackTrace( log );
75             throw new StatusException( "Couldn't create document", e );
76         }
77     }
78 
79     /**
80     * Disposes text document.
81     */
cleanup( TestParameters tParam, PrintWriter log )82     protected void cleanup( TestParameters tParam, PrintWriter log ) {
83         log.println( "    disposing xTextDoc " );
84         util.DesktopTools.closeDoc(xTextDoc);
85     }
86 
87     /**
88     * Creating a Testenvironment for the interfaces to be tested. After creating
89     * a bookmark, it is inserted to the text document.
90     */
createTestEnvironment(TestParameters tParam, PrintWriter log)91     protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) {
92         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
93         XInterface oObj = null;
94         Object instance = null;
95         log.println( "creating a test environment" );
96         try {
97             oObj = SOF.createBookmark( xTextDoc );
98             SOF.insertTextContent( xTextDoc, (XTextContent) oObj );
99             instance = SOF.createInstance(xTextDoc,"com.sun.star.text.Bookmark");
100         } catch ( com.sun.star.uno.Exception e ) {
101             e.printStackTrace( log );
102             throw new StatusException( "Couldn't create Bookmark", e );
103         }
104         log.println( "creating a new environment for bodytext object" );
105         TestEnvironment tEnv = new TestEnvironment( oObj );
106 
107         util.dbg.printInterfaces((XInterface) instance);
108 
109         tEnv.addObjRelation("CONTENT", (XTextContent)
110                         UnoRuntime.queryInterface(XTextContent.class,instance));
111         tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor());
112         return tEnv;
113     } // finish method getTestEnvironment
114 
115 
116 }    // finish class SwXBookmark
117 
118