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.utils;
34 
35 import com.sun.star.lang.XMultiServiceFactory;
36 import com.sun.star.text.XText;
37 import com.sun.star.text.XTextCursor;
38 import com.sun.star.text.XTextDocument;
39 import com.sun.star.uno.XInterface;
40 
41 public class SwXTextRange extends TestCase {
42     XTextDocument xTextDoc;
43 
44     protected void initialize( TestParameters tParam, PrintWriter log ) {
45         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
46 
47         try {
48             log.println( "creating a textdocument" );
49             xTextDoc = SOF.createTextDoc( null );
50         } catch ( com.sun.star.uno.Exception e ) {
51             // Some exception occures.FAILED
52             e.printStackTrace( log );
53             throw new StatusException( "Couldn't create document", e );
54         }
55     }
56 
57     protected void cleanup( TestParameters tParam, PrintWriter log ) {
58         log.println( "    disposing xTextDoc " );
59         util.DesktopTools.closeDoc(xTextDoc);
60     }
61 
62     /**
63      *    creating a Testenvironment for the interfaces to be tested
64      */
65     public synchronized TestEnvironment createTestEnvironment( TestParameters Param,
66                                                   PrintWriter log )
67                                                     throws StatusException {
68 
69         XText aText = null;
70 
71         // creation of testobject here
72         // first we write what we are intend to do to log file
73         log.println( "creating a test environment" );
74 
75 
76         // get the bodytext of textdocument here
77         log.println( "getting the TextRange of the text document" );
78         aText = xTextDoc.getText();
79         XTextCursor oCursor = aText.createTextCursor();
80 
81         XInterface oObj = oCursor.getStart();
82 
83         log.println( "creating a new environment for textrange object" );
84         TestEnvironment tEnv = new TestEnvironment( oObj );
85 
86         log.println( "adding TextDocument as mod relation to environment" );
87         tEnv.addObjRelation("TEXTDOC", xTextDoc);
88 
89         System.out.println("Implementation Name: "+utils.getImplName(oObj));
90 
91         return tEnv;
92     } // finish method getTestEnvironment
93 
94 }    // finish class SwXTextRange
95 
96