Line 0
Link Here
|
|
|
1 |
/* ==================================================================== |
2 |
Licensed to the Apache Software Foundation (ASF) under one or more |
3 |
contributor license agreements. See the NOTICE file distributed with |
4 |
this work for additional information regarding copyright ownership. |
5 |
The ASF licenses this file to You under the Apache License, Version 2.0 |
6 |
(the "License"); you may not use this file except in compliance with |
7 |
the License. You may obtain a copy of the License at |
8 |
|
9 |
http://www.apache.org/licenses/LICENSE-2.0 |
10 |
|
11 |
Unless required by applicable law or agreed to in writing, software |
12 |
distributed under the License is distributed on an "AS IS" BASIS, |
13 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 |
See the License for the specific language governing permissions and |
15 |
limitations under the License. |
16 |
==================================================================== */ |
17 |
|
18 |
package org.apache.poi.hssf.record.formula.functions; |
19 |
|
20 |
import junit.framework.TestCase; |
21 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
22 |
import org.apache.poi.hssf.usermodel.HSSFSheet; |
23 |
import org.apache.poi.hssf.usermodel.HSSFRow; |
24 |
import org.apache.poi.hssf.usermodel.HSSFCell; |
25 |
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; |
26 |
|
27 |
/** |
28 |
* @author Torstein Svendsen (torstei@officenet.no) |
29 |
*/ |
30 |
|
31 |
public final class TestFind extends TestCase { |
32 |
|
33 |
public void testFind() { |
34 |
HSSFWorkbook wb = new HSSFWorkbook(); |
35 |
HSSFSheet sheet1 = wb.createSheet(); |
36 |
|
37 |
HSSFRow row = sheet1.createRow(0); |
38 |
HSSFCell cell = row.createCell(0); |
39 |
|
40 |
|
41 |
cell.setCellFormula("find(\"n\", \"haystack\")"); |
42 |
HSSFFormulaEvaluator fe = new HSSFFormulaEvaluator(wb); |
43 |
HSSFFormulaEvaluator.CellValue result = fe.evaluate(cell); |
44 |
assertEquals(HSSFCell.CELL_TYPE_ERROR, result.getCellType()); |
45 |
|
46 |
fe.clearAllCachedResultValues(); |
47 |
cell.setCellFormula("find(\"h\", \"haystack\")"); |
48 |
result = fe.evaluate(cell); |
49 |
assertEquals( result.getCellType(), HSSFCell.CELL_TYPE_NUMERIC); |
50 |
assertTrue( 1 == result.getNumberValue()); |
51 |
|
52 |
cell.setCellFormula("find(\"a\", \"haystack\",2)"); |
53 |
fe.clearAllCachedResultValues(); |
54 |
result = fe.evaluate(cell); |
55 |
assertEquals( result.getCellType(), HSSFCell.CELL_TYPE_NUMERIC); |
56 |
assertTrue( 2 == result.getNumberValue()); |
57 |
|
58 |
cell.setCellFormula("find(\"a\", \"haystack\",3)"); |
59 |
fe.clearAllCachedResultValues(); |
60 |
result = fe.evaluate(cell); |
61 |
assertEquals( result.getCellType(), HSSFCell.CELL_TYPE_NUMERIC); |
62 |
|
63 |
assertTrue( 6 == result.getNumberValue()); |
64 |
|
65 |
cell.setCellFormula("find(\"k\", \"haystack\",9)"); |
66 |
fe.clearAllCachedResultValues(); |
67 |
result = fe.evaluate(cell); |
68 |
assertEquals( result.getCellType(), HSSFCell.CELL_TYPE_ERROR); |
69 |
|
70 |
|
71 |
} |
72 |
} |