Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XSearchable.java
blob932a47455a88114aa709b259dcc51329cf72a7dc
1 /*
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 .
19 package ifc.util;
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;
28 /**
29 * Testing <code>com.sun.star.util.XSearchable</code>
30 * interface methods :
31 * <ul>
32 * <li><code> createSearchDescriptor()</code></li>
33 * <li><code> findAll()</code></li>
34 * <li><code> findFirst()</code></li>
35 * <li><code> findNext()</code></li>
36 * </ul> <p>
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 compliant. <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;
54 /**
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 @Override
61 protected void before() {
62 Object o = tEnv.getObjRelation("SEARCHSTRING");
63 if (o != null) {
64 mSearchString = (String)o;
66 o = tEnv.getObjRelation("XSearchable.MAKEENTRYINCELL");
67 if (o != null) {
68 XCell[] cells = new XCell[0];
69 if (o instanceof XCell) {
70 cells = new XCell[]{(XCell)o};
72 else if (o instanceof XCell[]) {
73 cells = (XCell[])o;
75 else {
76 log.println("Needed object relation 'XSearchable.MAKEENTRYINCELL' is there, but is of type '"
77 + o.getClass().getName() + "'. Should be 'XCell' or 'XCell[]' instead.");
79 for (int i=0; i<cells.length; i++) {
80 cells[i].setFormula(mSearchString);
82 mDispose = true;
84 mExcludeFindNext = (tEnv.getObjRelation("EXCLUDEFINDNEXT")==null)?false:true;
87 /**
88 * Creates the search descriptor which searches for
89 * 'xTextDoc' string. <p>
90 * Has <b> OK </b> status if the method returns not
91 * <code>null</code> value.
93 public void _createSearchDescriptor() {
95 log.println("testing createSearchDescriptor() ... ");
97 Sdesc = oObj.createSearchDescriptor();
98 Sdesc.setSearchString(mSearchString);
99 tRes.tested("createSearchDescriptor()", Sdesc != null);
104 * Performs search using descriptor created before. <p>
105 * Has <b> OK </b> status if the method not <code>null</code>
106 * collections. <p>
107 * The following method tests are to be completed successfully before :
108 * <ul>
109 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
110 * required for search. </li>
111 * </ul>
113 public void _findAll() {
115 requiredMethod("createSearchDescriptor()");
116 log.println("testing findAll()");
118 XIndexAccess IA = oObj.findAll(Sdesc);
119 tRes.tested("findAll()", IA != null);
123 * Performs search using descriptor created before. Storing the
124 * first occurrence result. <p>
125 * Has <b> OK </b> status if the method not <code>null</code>
126 * value. <p>
127 * The following method tests are to be completed successfully before :
128 * <ul>
129 * <li> <code> createSearchDescriptor() </code> : creates the descriptor
130 * required for search. </li>
131 * </ul>
133 public void _findFirst() {
135 requiredMethod("createSearchDescriptor()");
136 log.println("testing findFirst()");
137 start = oObj.findFirst(Sdesc);
138 tRes.tested("findFirst()", start != null);
142 * Performs search using descriptor and first search result
143 * created before. <p>
144 * Has <b> OK </b> status if the method not <code>null</code>
145 * value. <p>
146 * The following method tests are to be completed successfully before :
147 * <ul>
148 * <li> <code> findFirst() </code> : to have first search result. </li>
149 * </ul>
151 public void _findNext() {
152 if (mExcludeFindNext) {
153 log.println("Testing findNext() excluded, because only one" +
154 " search result is available.");
155 tRes.tested("findNext()", true);
157 else{
158 requiredMethod("findFirst()");
160 log.println("testing findNext()");
161 Object xI = oObj.findNext(start,Sdesc);
162 tRes.tested("findNext()", xI != null);
167 * In case the interface itself made the entry to search for, the environment
168 * must be disposed
170 @Override
171 protected void after() {
172 if(mDispose) {
173 disposeEnvironment();