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