1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XSearchable.java,v $
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 ************************************************************************/
33 import lib
.MultiMethodTest
;
35 import com
.sun
.star
.container
.XIndexAccess
;
36 import com
.sun
.star
.table
.XCell
;
37 import com
.sun
.star
.util
.XSearchDescriptor
;
38 import com
.sun
.star
.util
.XSearchable
;
41 * Testing <code>com.sun.star.util.XSearchable</code>
44 * <li><code> createSearchDescriptor()</code></li>
45 * <li><code> findAll()</code></li>
46 * <li><code> findFirst()</code></li>
47 * <li><code> findNext()</code></li>
50 * The requipment for the tested object is that it
51 * <b>must containt</b> string 'xTextDoc'. Only
52 * in that case this interface is tested correctly. <p>
54 * Test is <b> NOT </b> multithread compilant. <p>
55 * @see com.sun.star.util.XSearchable
57 public class _XSearchable
extends MultiMethodTest
{
59 public XSearchable oObj
= null; // oObj filled by MultiMethodTest
60 public XSearchDescriptor Sdesc
= null;
61 public Object start
= null;
62 private String mSearchString
= "xTextDoc";
63 private boolean mDispose
= false;
64 private boolean mExcludeFindNext
= false;
67 * Creates an entry to search for, if the current object does not provide
68 * one. In this case, the environment is disposed after the test, since
69 * the inserted object may influence following tests.
72 protected void before() {
73 Object o
= tEnv
.getObjRelation("SEARCHSTRING");
75 mSearchString
= (String
)o
;
77 o
= tEnv
.getObjRelation("XSearchable.MAKEENTRYINCELL");
79 XCell
[] cells
= new XCell
[0];
80 if (o
instanceof XCell
) {
81 cells
= new XCell
[]{(XCell
)o
};
83 else if (o
instanceof XCell
[]) {
87 log
.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
88 + o
.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
90 for (int i
=0; i
<cells
.length
; i
++) {
91 cells
[i
].setFormula(mSearchString
);
95 mExcludeFindNext
= (tEnv
.getObjRelation("EXCLUDEFINDNEXT")==null)?
false:true;
99 * Creates the search descriptor which searches for
100 * 'xTextDoc' string. <p>
101 * Has <b> OK </b> status if the method returns not
102 * <code>null</code> value.
104 public void _createSearchDescriptor() {
106 log
.println("testing createSearchDescriptor() ... ");
108 Sdesc
= oObj
.createSearchDescriptor();
109 Sdesc
.setSearchString(mSearchString
);
110 tRes
.tested("createSearchDescriptor()", Sdesc
!= null);
115 * Performs search using descriptor created before. <p>
116 * Has <b> OK </b> status if the method not <code>null</code>
118 * The following method tests are to be completed successfully before :
120 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
121 * required for search. </li>
124 public void _findAll() {
126 requiredMethod("createSearchDescriptor()");
127 log
.println("testing findAll()");
129 XIndexAccess IA
= oObj
.findAll(Sdesc
);
130 tRes
.tested("findAll()", IA
!= null);
134 * Performs search using descriptor created before. Storing the
135 * first occurence result. <p>
136 * Has <b> OK </b> status if the method not <code>null</code>
138 * The following method tests are to be completed successfully before :
140 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
141 * required for search. </li>
144 public void _findFirst() {
146 requiredMethod("createSearchDescriptor()");
147 log
.println("testing findFirst()");
148 start
= oObj
.findFirst(Sdesc
);
149 tRes
.tested("findFirst()", start
!= null);
153 * Performs search using descriptor and first search result
154 * created before. <p>
155 * Has <b> OK </b> status if the method not <code>null</code>
157 * The following method tests are to be completed successfully before :
159 * <li> <code> findFirst() </code> : to have first search result. </li>
162 public void _findNext() {
163 if (mExcludeFindNext
) {
164 log
.println("Testing findNext() excluded, because only one" +
165 " search result is available.");
166 tRes
.tested("findNext()", true);
169 requiredMethod("findFirst()");
171 log
.println("testing findNext()");
172 Object xI
= oObj
.findNext(start
,Sdesc
);
173 tRes
.tested("findNext()", xI
!= null);
178 * In case the interface itself made the entry to search for, the environment
181 protected void after() {
183 disposeEnvironment();