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.container.XNameAccess;
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XBookmarksSupplier;
37 import com.sun.star.text.XTextContent;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 
42 /**
43  * Test for object which is represented by service
44  * <code>com.sun.star.text.Bookmarks</code>. <p>
45  * Object implements the following interfaces :
46  * <ul>
47  *  <li> <code>com::sun::star::container::XNameAccess</code></li>
48  *  <li> <code>com::sun::star::container::XElementAccess</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.XNameAccess
53  * @see com.sun.star.container.XElementAccess
54  * @see ifc.container._XNameAccess
55  * @see ifc.container._XElementAccess
56  */
57 public class SwXBookmarks extends TestCase {
58     XTextDocument xTextDoc;
59     SOfficeFactory SOF;
60 
61     /**
62     * Creates text document.
63     */
initialize( TestParameters tParam, PrintWriter log )64     protected void initialize( TestParameters tParam, PrintWriter log ) {
65         SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
66         try {
67             log.println( "creating a textdocument" );
68             xTextDoc = SOF.createTextDoc( null );
69         } catch ( com.sun.star.uno.Exception e ) {
70             e.printStackTrace( log );
71             throw new StatusException( "Couldn't create document", e );
72         }
73     }
74 
75     /**
76     * Disposes text document.
77     */
cleanup( TestParameters tParam, PrintWriter log )78     protected void cleanup( TestParameters tParam, PrintWriter log ) {
79         log.println( "    disposing xTextDoc " );
80         util.DesktopTools.closeDoc(xTextDoc);
81     }
82 
83     /**
84     * Creating a Testenvironment for the interfaces to be tested. Method
85     * creates two bookmarks and inserts them to the text document. Then bookmarks
86     * are gotten from text document using <code>XBookmarksSupplier</code>
87     * interface.
88     */
createTestEnvironment( TestParameters Param, PrintWriter log )89     public synchronized TestEnvironment createTestEnvironment(
90             TestParameters Param, PrintWriter log ) throws StatusException {
91         XInterface oObj = null;
92 
93         log.println( "creating a test environment" );
94         try {
95             oObj = SOF.createBookmark( xTextDoc );
96             SOF.insertTextContent( xTextDoc, (XTextContent) oObj );
97             oObj = SOF.createBookmark( xTextDoc );
98             SOF.insertTextContent( xTextDoc, (XTextContent) oObj );
99         } catch( com.sun.star.uno.Exception e ) {
100             e.printStackTrace( log );
101             throw new StatusException( "Couldn't create Bookmark", e );
102         }
103 
104         XBookmarksSupplier oBSupp = (XBookmarksSupplier)
105             UnoRuntime.queryInterface(XBookmarksSupplier.class, xTextDoc);
106         XNameAccess oBookNA = oBSupp.getBookmarks();
107         oObj = oBookNA;
108         log.println( "creating a new environment for Bookmarks object" );
109 
110         TestEnvironment tEnv = new TestEnvironment( oObj );
111         return tEnv;
112     } // finish method getTestEnvironment
113 
114 }    // finish class SwXBookmarks
115 
116