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 org.apache.poi.hssf.record.formula.eval.ErrorEval; |
21 |
import org.apache.poi.hssf.record.formula.eval.NumberEval; |
22 |
import org.apache.poi.hssf.record.formula.eval.StringEval; |
23 |
import org.apache.poi.hssf.record.formula.eval.ValueEval; |
24 |
|
25 |
import junit.framework.TestCase; |
26 |
|
27 |
/** |
28 |
* |
29 |
* Test cases for {@link TextFunction#LEFT} and {@link TextFunction#RIGHT} |
30 |
* |
31 |
* @author Brendan Nolan |
32 |
* |
33 |
*/ |
34 |
public class TestLeftRight extends TestCase { |
35 |
|
36 |
private static final NumberEval NEGATIVE_OPERAND = new NumberEval(-1.0); |
37 |
private static final StringEval ANY_STRING_VALUE = new StringEval("ANYSTRINGVALUE"); |
38 |
|
39 |
|
40 |
private static ValueEval invokeLeft(ValueEval text, ValueEval operand) { |
41 |
ValueEval[] args = new ValueEval[] { text, operand }; |
42 |
return TextFunction.LEFT.evaluate(args, -1, (short)-1); |
43 |
} |
44 |
|
45 |
private static ValueEval invokeRight(ValueEval text, ValueEval operand) { |
46 |
ValueEval[] args = new ValueEval[] { text, operand }; |
47 |
return TextFunction.RIGHT.evaluate(args, -1, (short)-1); |
48 |
} |
49 |
|
50 |
public void testLeftRight_bug49841() { |
51 |
|
52 |
try { |
53 |
invokeLeft(ANY_STRING_VALUE, NEGATIVE_OPERAND); |
54 |
invokeRight(ANY_STRING_VALUE, NEGATIVE_OPERAND); |
55 |
} catch (StringIndexOutOfBoundsException e) { |
56 |
fail("Identified bug 49841"); |
57 |
} |
58 |
|
59 |
} |
60 |
|
61 |
public void testLeftRightNegativeOperand() { |
62 |
|
63 |
assertEquals(ErrorEval.VALUE_INVALID, invokeRight(ANY_STRING_VALUE, NEGATIVE_OPERAND)); |
64 |
assertEquals(ErrorEval.VALUE_INVALID, invokeLeft(ANY_STRING_VALUE, NEGATIVE_OPERAND)); |
65 |
|
66 |
} |
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
} |