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 .
21 import lib
.MultiMethodTest
;
23 import com
.sun
.star
.container
.XIndexAccess
;
24 import com
.sun
.star
.table
.XCell
;
25 import com
.sun
.star
.util
.XSearchDescriptor
;
26 import com
.sun
.star
.util
.XSearchable
;
29 * Testing <code>com.sun.star.util.XSearchable</code>
32 * <li><code> createSearchDescriptor()</code></li>
33 * <li><code> findAll()</code></li>
34 * <li><code> findFirst()</code></li>
35 * <li><code> findNext()</code></li>
38 * The requipment for the tested object is that it
39 * <b>must containt</b> string 'xTextDoc'. Only
40 * in that case this interface is tested correctly. <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.util.XSearchable
45 public class _XSearchable
extends MultiMethodTest
{
47 public XSearchable oObj
= null; // oObj filled by MultiMethodTest
48 public XSearchDescriptor Sdesc
= null;
49 public Object start
= null;
50 private String mSearchString
= "xTextDoc";
51 private boolean mDispose
= false;
52 private boolean mExcludeFindNext
= false;
55 * Creates an entry to search for, if the current object does not provide
56 * one. In this case, the environment is disposed after the test, since
57 * the inserted object may influence following tests.
60 protected void before() {
61 Object o
= tEnv
.getObjRelation("SEARCHSTRING");
63 mSearchString
= (String
)o
;
65 o
= tEnv
.getObjRelation("XSearchable.MAKEENTRYINCELL");
67 XCell
[] cells
= new XCell
[0];
68 if (o
instanceof XCell
) {
69 cells
= new XCell
[]{(XCell
)o
};
71 else if (o
instanceof XCell
[]) {
75 log
.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
76 + o
.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
78 for (int i
=0; i
<cells
.length
; i
++) {
79 cells
[i
].setFormula(mSearchString
);
83 mExcludeFindNext
= (tEnv
.getObjRelation("EXCLUDEFINDNEXT")==null)?
false:true;
87 * Creates the search descriptor which searches for
88 * 'xTextDoc' string. <p>
89 * Has <b> OK </b> status if the method returns not
90 * <code>null</code> value.
92 public void _createSearchDescriptor() {
94 log
.println("testing createSearchDescriptor() ... ");
96 Sdesc
= oObj
.createSearchDescriptor();
97 Sdesc
.setSearchString(mSearchString
);
98 tRes
.tested("createSearchDescriptor()", Sdesc
!= null);
103 * Performs search using descriptor created before. <p>
104 * Has <b> OK </b> status if the method not <code>null</code>
106 * The following method tests are to be completed successfully before :
108 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
109 * required for search. </li>
112 public void _findAll() {
114 requiredMethod("createSearchDescriptor()");
115 log
.println("testing findAll()");
117 XIndexAccess IA
= oObj
.findAll(Sdesc
);
118 tRes
.tested("findAll()", IA
!= null);
122 * Performs search using descriptor created before. Storing the
123 * first occurrence result. <p>
124 * Has <b> OK </b> status if the method not <code>null</code>
126 * The following method tests are to be completed successfully before :
128 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
129 * required for search. </li>
132 public void _findFirst() {
134 requiredMethod("createSearchDescriptor()");
135 log
.println("testing findFirst()");
136 start
= oObj
.findFirst(Sdesc
);
137 tRes
.tested("findFirst()", start
!= null);
141 * Performs search using descriptor and first search result
142 * created before. <p>
143 * Has <b> OK </b> status if the method not <code>null</code>
145 * The following method tests are to be completed successfully before :
147 * <li> <code> findFirst() </code> : to have first search result. </li>
150 public void _findNext() {
151 if (mExcludeFindNext
) {
152 log
.println("Testing findNext() excluded, because only one" +
153 " search result is available.");
154 tRes
.tested("findNext()", true);
157 requiredMethod("findFirst()");
159 log
.println("testing findNext()");
160 Object xI
= oObj
.findNext(start
,Sdesc
);
161 tRes
.tested("findNext()", xI
!= null);
166 * In case the interface itself made the entry to search for, the environment
169 protected void after() {
171 disposeEnvironment();