1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.util;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.container.XIndexAccess;
29 import com.sun.star.table.XCell;
30 import com.sun.star.util.XSearchDescriptor;
31 import com.sun.star.util.XSearchable;
32 
33 /**
34  * Testing <code>com.sun.star.util.XSearchable</code>
35  * interface methods :
36  * <ul>
37  *  <li><code> createSearchDescriptor()</code></li>
38  *  <li><code> findAll()</code></li>
39  *  <li><code> findFirst()</code></li>
40  *  <li><code> findNext()</code></li>
41  * </ul> <p>
42  *
43  * The requipment for the tested object is that it
44  * <b>must containt</b> string 'xTextDoc'. Only
45  * in that case this interface is tested correctly. <p>
46  *
47  * Test is <b> NOT </b> multithread compilant. <p>
48  * @see com.sun.star.util.XSearchable
49  */
50 public class _XSearchable extends MultiMethodTest {
51 
52     public XSearchable oObj = null;                // oObj filled by MultiMethodTest
53     public XSearchDescriptor Sdesc = null;
54     public Object start = null;
55     private String mSearchString = "xTextDoc";
56     private boolean mDispose = false;
57     private boolean mExcludeFindNext = false;
58 
59     /**
60      * Creates an entry to search for, if the current object does not provide
61      * one. In this case, the environment is disposed after the test, since
62      * the inserted object may influence following tests.
63      *
64      */
before()65     protected void before() {
66         Object o = tEnv.getObjRelation("SEARCHSTRING");
67         if (o != null) {
68             mSearchString = (String)o;
69         }
70         o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL");
71         if (o != null) {
72             XCell[] cells = new XCell[0];
73             if (o instanceof XCell) {
74                 cells = new XCell[]{(XCell)o};
75             }
76             else if (o instanceof XCell[]) {
77                 cells = (XCell[])o;
78             }
79             else {
80                 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
81                             + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
82             }
83             for (int i=0; i<cells.length; i++) {
84                 cells[i].setFormula(mSearchString);
85             }
86             mDispose = true;
87         }
88         mExcludeFindNext = (tEnv.getObjRelation("EXCLUDEFINDNEXT")==null)?false:true;
89     }
90 
91     /**
92      * Creates the search descriptor which searches for
93      * 'xTextDoc' string. <p>
94      * Has <b> OK </b> status if the method returns not
95      * <code>null</code> value.
96      */
_createSearchDescriptor()97     public void _createSearchDescriptor() {
98 
99         log.println("testing createSearchDescriptor() ... ");
100 
101         Sdesc = oObj.createSearchDescriptor();
102         Sdesc.setSearchString(mSearchString);
103         tRes.tested("createSearchDescriptor()", Sdesc != null);
104 
105     }
106 
107     /**
108      * Performs search using descriptor created before. <p>
109      * Has <b> OK </b> status if the method not <code>null</code>
110      * collections. <p>
111      * The following method tests are to be completed successfully before :
112      * <ul>
113      *  <li> <code> createSearchDescriptor() </code> : creates the descriptor
114      *  required for search. </li>
115      * </ul>
116      */
_findAll()117     public void _findAll() {
118 
119         requiredMethod("createSearchDescriptor()");
120         log.println("testing findAll()");
121 
122         XIndexAccess IA = oObj.findAll(Sdesc);
123         tRes.tested("findAll()", IA != null);
124     }
125 
126     /**
127      * Performs search using descriptor created before. Storing the
128      * first occurence result. <p>
129      * Has <b> OK </b> status if the method not <code>null</code>
130      * value. <p>
131      * The following method tests are to be completed successfully before :
132      * <ul>
133      *  <li> <code> createSearchDescriptor() </code> : creates the descriptor
134      *  required for search. </li>
135      * </ul>
136      */
_findFirst()137     public void _findFirst() {
138 
139         requiredMethod("createSearchDescriptor()");
140         log.println("testing findFirst()");
141         start = oObj.findFirst(Sdesc);
142         tRes.tested("findFirst()", start != null);
143     }
144 
145     /**
146      * Performs search using descriptor and first search result
147      * created before. <p>
148      * Has <b> OK </b> status if the method not <code>null</code>
149      * value. <p>
150      * The following method tests are to be completed successfully before :
151      * <ul>
152      *  <li> <code> findFirst() </code> : to have first search result. </li>
153      * </ul>
154      */
_findNext()155     public void _findNext() {
156         if (mExcludeFindNext) {
157             log.println("Testing findNext() excluded, because only one" +
158                         " search result is available.");
159             tRes.tested("findNext()", true);
160         }
161         else{
162             requiredMethod("findFirst()");
163 
164             log.println("testing findNext()");
165             Object xI = oObj.findNext(start,Sdesc);
166             tRes.tested("findNext()", xI != null);
167         }
168     }
169 
170     /**
171      * In case the interface itself made the entry to search for, the environment
172      * must be disposed
173      */
after()174     protected void after() {
175         if(mDispose) {
176             disposeEnvironment();
177         }
178     }
179 }
180 
181 
182