Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XSearchable.java
blob27a243e0e3261d91ff2b085144ba31cbbb07ad3c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 package ifc.util;
30 import lib.MultiMethodTest;
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;
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>
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>
51 * Test is <b> NOT </b> multithread compilant. <p>
52 * @see com.sun.star.util.XSearchable
54 public class _XSearchable extends MultiMethodTest {
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;
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.
69 protected void before() {
70 Object o = tEnv.getObjRelation("SEARCHSTRING");
71 if (o != null) {
72 mSearchString = (String)o;
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};
80 else if (o instanceof XCell[]) {
81 cells = (XCell[])o;
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.");
87 for (int i=0; i<cells.length; i++) {
88 cells[i].setFormula(mSearchString);
90 mDispose = true;
92 mExcludeFindNext = (tEnv.getObjRelation("EXCLUDEFINDNEXT")==null)?false:true;
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.
101 public void _createSearchDescriptor() {
103 log.println("testing createSearchDescriptor() ... ");
105 Sdesc = oObj.createSearchDescriptor();
106 Sdesc.setSearchString(mSearchString);
107 tRes.tested("createSearchDescriptor()", Sdesc != null);
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>
121 public void _findAll() {
123 requiredMethod("createSearchDescriptor()");
124 log.println("testing findAll()");
126 XIndexAccess IA = oObj.findAll(Sdesc);
127 tRes.tested("findAll()", IA != null);
131 * Performs search using descriptor created before. Storing the
132 * first occurrence 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>
141 public void _findFirst() {
143 requiredMethod("createSearchDescriptor()");
144 log.println("testing findFirst()");
145 start = oObj.findFirst(Sdesc);
146 tRes.tested("findFirst()", start != null);
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>
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);
165 else{
166 requiredMethod("findFirst()");
168 log.println("testing findNext()");
169 Object xI = oObj.findNext(start,Sdesc);
170 tRes.tested("findNext()", xI != null);
175 * In case the interface itself made the entry to search for, the environment
176 * must be disposed
178 protected void after() {
179 if(mDispose) {
180 disposeEnvironment();