Bug 57915: Fix Dev2Hex for numbers larger than Integer.MAX_VALUE and less than Integer.MIN_VALUE

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1703672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-09-17 19:23:25 +00:00
parent 2f0ceddc7f
commit e47a129a5b
2 changed files with 23 additions and 1 deletions

View File

@ -112,7 +112,7 @@ public final class Dec2Hex extends Var1or2ArgFunction implements FreeRefFunction
hex = String.format(Locale.ROOT, "%0"+placesNumber+"X", number1.intValue());
}
else {
hex = Integer.toHexString(number1.intValue());
hex = Long.toHexString(number1.longValue());
}
if (number1 < 0) {

View File

@ -81,6 +81,28 @@ public final class TestDec2Hex extends TestCase {
confirmValue("Converts decimal -54 to hexadecimal, 2 is ignored","-54", "2", "FFFFFFFFCA");
confirmValue("places is optionnal","-54", "FFFFFFFFCA");
confirmValue("Converts normal decimal number to hexadecimal", "100", "64");
String maxInt = Integer.toString(Integer.MAX_VALUE);
assertEquals("2147483647", maxInt);
confirmValue("Converts INT_MAX to hexadecimal", maxInt, "7FFFFFFF");
String minInt = Integer.toString(Integer.MIN_VALUE);
assertEquals("-2147483648", minInt);
confirmValue("Converts INT_MIN to hexadecimal", minInt, "FF80000000");
String maxIntPlusOne = Long.toString(((long)Integer.MAX_VALUE)+1);
assertEquals("2147483648", maxIntPlusOne);
confirmValue("Converts INT_MAX + 1 to hexadecimal", maxIntPlusOne, "80000000");
String maxLong = Long.toString(549755813887l);
assertEquals("549755813887", maxLong);
confirmValue("Converts the max supported value to hexadecimal", maxLong, "7FFFFFFFFF");
String minLong = Long.toString(-549755813888l);
assertEquals("-549755813888", minLong);
confirmValue("Converts the min supported value to hexadecimal", minLong, "FF80000000");
}
public void testErrors() {