1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.util; 29 30 import lib.MultiMethodTest; 31 32 import com.sun.star.container.XIndexAccess; 33 import com.sun.star.table.XCell; 34 import com.sun.star.util.XSearchDescriptor; 35 import com.sun.star.util.XSearchable; 36 37 /** 38 * Testing <code>com.sun.star.util.XSearchable</code> 39 * interface methods : 40 * <ul> 41 * <li><code> createSearchDescriptor()</code></li> 42 * <li><code> findAll()</code></li> 43 * <li><code> findFirst()</code></li> 44 * <li><code> findNext()</code></li> 45 * </ul> <p> 46 * 47 * The requipment for the tested object is that it 48 * <b>must containt</b> string 'xTextDoc'. Only 49 * in that case this interface is tested correctly. <p> 50 * 51 * Test is <b> NOT </b> multithread compilant. <p> 52 * @see com.sun.star.util.XSearchable 53 */ 54 public class _XSearchable extends MultiMethodTest { 55 56 public XSearchable oObj = null; // oObj filled by MultiMethodTest 57 public XSearchDescriptor Sdesc = null; 58 public Object start = null; 59 private String mSearchString = "xTextDoc"; 60 private boolean mDispose = false; 61 private boolean mExcludeFindNext = false; 62 63 /** 64 * Creates an entry to search for, if the current object does not provide 65 * one. In this case, the environment is disposed after the test, since 66 * the inserted object may influence following tests. 67 * 68 */ 69 protected void before() { 70 Object o = tEnv.getObjRelation("SEARCHSTRING"); 71 if (o != null) { 72 mSearchString = (String)o; 73 } 74 o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL"); 75 if (o != null) { 76 XCell[] cells = new XCell[0]; 77 if (o instanceof XCell) { 78 cells = new XCell[]{(XCell)o}; 79 } 80 else if (o instanceof XCell[]) { 81 cells = (XCell[])o; 82 } 83 else { 84 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '" 85 + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead."); 86 } 87 for (int i=0; i<cells.length; i++) { 88 cells[i].setFormula(mSearchString); 89 } 90 mDispose = true; 91 } 92 mExcludeFindNext = (tEnv.getObjRelation("EXCLUDEFINDNEXT")==null)?false:true; 93 } 94 95 /** 96 * Creates the search descriptor which searches for 97 * 'xTextDoc' string. <p> 98 * Has <b> OK </b> status if the method returns not 99 * <code>null</code> value. 100 */ 101 public void _createSearchDescriptor() { 102 103 log.println("testing createSearchDescriptor() ... "); 104 105 Sdesc = oObj.createSearchDescriptor(); 106 Sdesc.setSearchString(mSearchString); 107 tRes.tested("createSearchDescriptor()", Sdesc != null); 108 109 } 110 111 /** 112 * Performs search using descriptor created before. <p> 113 * Has <b> OK </b> status if the method not <code>null</code> 114 * collections. <p> 115 * The following method tests are to be completed successfully before : 116 * <ul> 117 * <li> <code> createSearchDescriptor() </code> : creates the descriptor 118 * required for search. </li> 119 * </ul> 120 */ 121 public void _findAll() { 122 123 requiredMethod("createSearchDescriptor()"); 124 log.println("testing findAll()"); 125 126 XIndexAccess IA = oObj.findAll(Sdesc); 127 tRes.tested("findAll()", IA != null); 128 } 129 130 /** 131 * Performs search using descriptor created before. Storing the 132 * first occurence result. <p> 133 * Has <b> OK </b> status if the method not <code>null</code> 134 * value. <p> 135 * The following method tests are to be completed successfully before : 136 * <ul> 137 * <li> <code> createSearchDescriptor() </code> : creates the descriptor 138 * required for search. </li> 139 * </ul> 140 */ 141 public void _findFirst() { 142 143 requiredMethod("createSearchDescriptor()"); 144 log.println("testing findFirst()"); 145 start = oObj.findFirst(Sdesc); 146 tRes.tested("findFirst()", start != null); 147 } 148 149 /** 150 * Performs search using descriptor and first search result 151 * created before. <p> 152 * Has <b> OK </b> status if the method not <code>null</code> 153 * value. <p> 154 * The following method tests are to be completed successfully before : 155 * <ul> 156 * <li> <code> findFirst() </code> : to have first search result. </li> 157 * </ul> 158 */ 159 public void _findNext() { 160 if (mExcludeFindNext) { 161 log.println("Testing findNext() excluded, because only one" + 162 " search result is available."); 163 tRes.tested("findNext()", true); 164 } 165 else{ 166 requiredMethod("findFirst()"); 167 168 log.println("testing findNext()"); 169 Object xI = oObj.findNext(start,Sdesc); 170 tRes.tested("findNext()", xI != null); 171 } 172 } 173 174 /** 175 * In case the interface itself made the entry to search for, the environment 176 * must be disposed 177 */ 178 protected void after() { 179 if(mDispose) { 180 disposeEnvironment(); 181 } 182 } 183 } 184 185 186