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.ss.formula.functions; |
19 |
|
20 |
import junit.framework.AssertionFailedError; |
21 |
import junit.framework.TestCase; |
22 |
|
23 |
import org.apache.poi.hssf.usermodel.HSSFCell; |
24 |
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; |
25 |
import org.apache.poi.hssf.usermodel.HSSFSheet; |
26 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
27 |
import org.apache.poi.ss.usermodel.Cell; |
28 |
import org.apache.poi.ss.usermodel.CellValue; |
29 |
|
30 |
public final class TestProper extends TestCase { |
31 |
private HSSFCell cell11; |
32 |
private HSSFFormulaEvaluator evaluator; |
33 |
|
34 |
public void setUp() { |
35 |
HSSFWorkbook wb = new HSSFWorkbook(); |
36 |
HSSFSheet sheet = wb.createSheet("new sheet"); |
37 |
cell11 = sheet.createRow(0).createCell(0); |
38 |
cell11.setCellType(HSSFCell.CELL_TYPE_FORMULA); |
39 |
evaluator = new HSSFFormulaEvaluator(wb); |
40 |
} |
41 |
|
42 |
public void testValid() { |
43 |
confirm("PROPER(\"hi there\")", "Hi There"); |
44 |
confirm("PROPER(\"what's up\")", "What'S Up"); |
45 |
confirm("PROPER(\"I DON'T TH!NK SO!\")", "I Don'T Th!Nk So!"); |
46 |
confirm("PROPER(\"drÜbö'ä éloş|ëè \")", "Drübö'Ä Éloş|Ëè "); |
47 |
} |
48 |
|
49 |
private void confirm(String formulaText, String expectedResult) { |
50 |
cell11.setCellFormula(formulaText); |
51 |
evaluator.clearAllCachedResultValues(); |
52 |
CellValue cv = evaluator.evaluate(cell11); |
53 |
if (cv.getCellType() != Cell.CELL_TYPE_STRING) { |
54 |
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString()); |
55 |
} |
56 |
String actualValue = cv.getStringValue(); |
57 |
assertEquals(expectedResult, actualValue); |
58 |
} |
59 |
} |