1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._sw;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 import util.utils;
38 
39 import com.sun.star.lang.XMultiServiceFactory;
40 import com.sun.star.text.XText;
41 import com.sun.star.text.XTextCursor;
42 import com.sun.star.text.XTextDocument;
43 import com.sun.star.uno.XInterface;
44 
45 public class SwXTextRange extends TestCase {
46     XTextDocument xTextDoc;
47 
48     protected void initialize( TestParameters tParam, PrintWriter log ) {
49         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
50 
51         try {
52             log.println( "creating a textdocument" );
53             xTextDoc = SOF.createTextDoc( null );
54         } catch ( com.sun.star.uno.Exception e ) {
55             // Some exception occures.FAILED
56             e.printStackTrace( log );
57             throw new StatusException( "Couldn't create document", e );
58         }
59     }
60 
61     protected void cleanup( TestParameters tParam, PrintWriter log ) {
62         log.println( "    disposing xTextDoc " );
63         util.DesktopTools.closeDoc(xTextDoc);
64     }
65 
66     /**
67      *    creating a Testenvironment for the interfaces to be tested
68      */
69     public synchronized TestEnvironment createTestEnvironment( TestParameters Param,
70                                                   PrintWriter log )
71                                                     throws StatusException {
72 
73         XText aText = null;
74 
75         // creation of testobject here
76         // first we write what we are intend to do to log file
77         log.println( "creating a test environment" );
78 
79 
80         // get the bodytext of textdocument here
81         log.println( "getting the TextRange of the text document" );
82         aText = xTextDoc.getText();
83         XTextCursor oCursor = aText.createTextCursor();
84 
85         XInterface oObj = oCursor.getStart();
86 
87         log.println( "creating a new environment for textrange object" );
88         TestEnvironment tEnv = new TestEnvironment( oObj );
89 
90         log.println( "adding TextDocument as mod relation to environment" );
91         tEnv.addObjRelation("TEXTDOC", xTextDoc);
92 
93         System.out.println("Implementation Name: "+utils.getImplName(oObj));
94 
95         return tEnv;
96     } // finish method getTestEnvironment
97 
98 }    // finish class SwXTextRange
99 
100