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.ControlCharacter;
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.UnoRuntime;
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.util.XSearchDescriptor;
42 import com.sun.star.util.XSearchable;
43 
44 /**
45  *
46  * initial description
47  * @see com.sun.star.container.XElementAccess
48  * @see com.sun.star.container.XIndexAccess
49  *
50  */
51 public class SwXTextRanges extends TestCase {
52     XTextDocument xTextDoc;
53 
initialize( TestParameters tParam, PrintWriter log )54     protected void initialize( TestParameters tParam, PrintWriter log ) {
55         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
56 
57         try {
58             log.println( "creating a textdocument" );
59             xTextDoc = SOF.createTextDoc( null );
60         } catch ( com.sun.star.uno.Exception e ) {
61             // Some exception occures.FAILED
62             e.printStackTrace( log );
63             throw new StatusException( "Couldn't create document", e );
64         }
65     }
66 
cleanup( TestParameters tParam, PrintWriter log )67     protected void cleanup( TestParameters tParam, PrintWriter log ) {
68         log.println( "    disposing xTextDoc " );
69         util.DesktopTools.closeDoc(xTextDoc);
70     }
71 
72     /**
73      *    creating a Testenvironment for the interfaces to be tested
74      *
75      *  @param tParam    class which contains additional test parameters
76      *  @param log        class to log the test state and result
77      *
78      *  @return    Status class
79      *
80      *  @see TestParameters
81      *    @see PrintWriter
82      */
createTestEnvironment(TestParameters tParam, PrintWriter log)83     public synchronized TestEnvironment createTestEnvironment
84             (TestParameters tParam, PrintWriter log) {
85 
86         XInterface oObj = null;
87 
88         // creation of testobject here
89         // first we write what we are intend to do to log file
90         log.println( "creating a test environment" );
91 
92         // create testobject here
93         XText oText = xTextDoc.getText();
94          XTextCursor oCursor = oText.createTextCursor();
95 
96         for (int j =0; j < 5; j++){
97             try{
98                 oText.insertString( oCursor,
99                     "SwXTextRanges...SwXTextRanges...SwXTextRanges", false);
100                 oText.insertControlCharacter( oCursor,
101                     ControlCharacter.PARAGRAPH_BREAK, false );
102             }
103             catch( Exception e ){
104                 log.println( "EXCEPTION: " + e);
105             }
106         }
107 
108         XSearchable oSearch = (XSearchable)UnoRuntime.queryInterface
109             (XSearchable.class, xTextDoc);
110         XSearchDescriptor xSDesc = oSearch.createSearchDescriptor();
111         xSDesc.setSearchString("SwXTextRanges");
112 
113         oObj = oSearch.findAll(xSDesc);
114 
115         log.println( "creating a new environment for textrange object" );
116         TestEnvironment tEnv = new TestEnvironment( oObj );
117 
118         log.println( "adding TextDocument as mod relation to environment" );
119         tEnv.addObjRelation("TEXTDOC", xTextDoc);
120 
121         return tEnv;
122     } // finish method getTestEnvironment
123 
124 }    // finish class SwXTextRanges
125 
126