Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / util / _XTextSearch.java
blobf5e130a3e14b45c1afe6ace3450977c831a49cd8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XTextSearch.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.util;
33 import lib.MultiMethodTest;
35 import com.sun.star.util.SearchAlgorithms;
36 import com.sun.star.util.SearchFlags;
37 import com.sun.star.util.SearchOptions;
38 import com.sun.star.util.SearchResult;
39 import com.sun.star.util.XTextSearch;
41 /**
42 * Testing <code>com.sun.star.util.XTextSearch</code>
43 * interface methods :
44 * <ul>
45 * <li><code> setOptions()</code></li>
46 * <li><code> searchForward()</code></li>
47 * <li><code> searchBackward()</code></li>
48 * </ul> <p>
49 * Test is <b> NOT </b> multithread compilant. <p>
50 * @see com.sun.star.util.XTextSearch
52 public class _XTextSearch extends MultiMethodTest {
54 // oObj filled by MultiMethodTest
55 public XTextSearch oObj = null ;
57 protected final String str = "acababaabcababadcdaa" ;
58 protected final int startPos = 2 , endPos = 20 ;
59 protected final String searchStr = "(ab)*a(c|d)+" ;
60 protected final int fStartRes = 10, fEndRes = 18 ;
61 protected final int bStartRes = 18, bEndRes = 14 ;
63 /**
64 * Sets options for searching regular expression in a string,
65 * ignoring case. <p>
66 * Has <b>OK</b> status if no runtime exceptions occured.
68 public void _setOptions() {
70 SearchOptions opt = new SearchOptions() ;
71 opt.algorithmType = SearchAlgorithms.REGEXP ;
72 opt.searchFlag = SearchFlags.ALL_IGNORE_CASE ;
73 opt.searchString = searchStr ;
75 oObj.setOptions(opt) ;
77 tRes.tested("setOptions()", true) ;
81 /**
82 * Tries to find a substring matching regular expression. <p>
83 * Has <b>OK</b> if the correct substring position returned.
85 public void _searchForward() {
86 requiredMethod("setOptions()") ;
88 SearchResult res = oObj.searchForward(str, startPos, endPos) ;
90 log.println("Result of searching '" + searchStr + "' substring in \n'" +
91 str + "' string (" + res.subRegExpressions + " matches):") ;
93 for (int i = 0; i < res.subRegExpressions; i++)
94 log.println(" (" + res.startOffset[i] + ", " + res.endOffset[i] + ")") ;
96 tRes.tested("searchForward()", res.subRegExpressions > 0 &&
97 res.startOffset[0] == fStartRes && res.endOffset[0] == fEndRes) ;
101 * Tries to find a substring matching regular expression walking
102 * backward. <p>
103 * Has <b>OK</b> if the correct substring position returned.
105 public void _searchBackward() {
106 requiredMethod("setOptions()") ;
108 SearchResult res = oObj.searchBackward(str, endPos, startPos) ;
110 log.println("Result of searching '" + searchStr + "' substring in \n'" +
111 str + "' string (" + res.subRegExpressions + " matches):") ;
113 for (int i = 0; i < res.subRegExpressions; i++)
114 log.println(" (" + res.startOffset[i] + ", " + res.endOffset[i] + ")") ;
116 tRes.tested("searchBackward()", res.subRegExpressions > 0 &&
117 res.startOffset[0] == bStartRes && res.endOffset[0] == bEndRes) ;