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