Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / SwXTextSearch.java
blobec8dc1e7c96b0fb389fa5d54b50d2fa971df9197
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.text.ControlCharacter;
30 import com.sun.star.text.XText;
31 import com.sun.star.text.XTextCursor;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
35 import com.sun.star.util.XSearchDescriptor;
36 import com.sun.star.util.XSearchable;
38 /**
40 * initial description
41 * @see com.sun.star.beans.XPropertySet
42 * @see com.sun.star.util.SearchDescriptor
43 * @see com.sun.star.util.XSearchDescriptor
46 public class SwXTextSearch extends TestCase {
47 XTextDocument xTextDoc;
49 @Override
50 protected void initialize( TestParameters tParam, PrintWriter log ) {
51 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
53 try {
54 log.println( "creating a textdocument" );
55 xTextDoc = SOF.createTextDoc( null );
56 } catch ( com.sun.star.uno.Exception e ) {
57 // Some exception occurs.FAILED
58 e.printStackTrace( log );
59 throw new StatusException( "Couldn't create document", e );
63 @Override
64 protected void cleanup( TestParameters tParam, PrintWriter log ) {
65 log.println( " disposing xTextDoc " );
66 util.DesktopTools.closeDoc(xTextDoc);
69 /**
70 * creating a Testenvironment for the interfaces to be tested
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
75 * @return Status class
77 * @see TestParameters
78 * @see PrintWriter
80 @Override
81 public synchronized TestEnvironment createTestEnvironment
82 (TestParameters tParam, PrintWriter log ) {
84 XInterface oObj = null;
86 // creation of testobject here
87 // first we write what we are intend to do to log file
88 log.println( "creating a test environment" );
90 // create testobject here
92 XText oText = xTextDoc.getText();
93 XTextCursor oCursor = oText.createTextCursor();
95 for (int j =0; j < 5; j++){
96 try{
97 oText.insertString( oCursor,
98 "SwXTextSearch...SwXTextSearch...SwXTextSearch", false);
99 oText.insertControlCharacter( oCursor,
100 ControlCharacter.PARAGRAPH_BREAK, false );
102 catch( Exception e ){
103 log.println( "EXCEPTION: " + e);
107 XSearchable oSearch = UnoRuntime.queryInterface
108 (XSearchable.class, xTextDoc);
109 XSearchDescriptor xSDesc = oSearch.createSearchDescriptor();
110 xSDesc.setSearchString("SwXTextSearch");
112 oObj = xSDesc;
114 log.println( "creating a new environment for TextSearch object" );
115 TestEnvironment tEnv = new TestEnvironment( oObj );
117 log.println( "adding TextDocument as mod relation to environment" );
118 tEnv.addObjRelation("TEXTDOC", xTextDoc);
120 return tEnv;
121 } // finish method getTestEnvironment
123 } // finish class SwXTextSearch