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