Skip to content

Commit 39f2814

Browse files
committed
PDFBOX-5660: improve test coverage
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930188 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0e045a9 commit 39f2814

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

pdfbox/src/test/java/org/apache/pdfbox/util/TestHexUtil.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package org.apache.pdfbox.util;
1717

1818
import java.nio.charset.StandardCharsets;
19+
import java.util.HashSet;
1920
import java.util.Locale;
21+
import java.util.Set;
2022

2123
import org.junit.jupiter.api.Test;
2224

@@ -85,4 +87,35 @@ void testMisc()
8587
assertArrayEquals(byteSrcArray, Hex.decodeHex(dstString));
8688
}
8789

90+
@Test
91+
void testGetHexValue()
92+
{
93+
Set<Character> validHexCharacters = new HashSet<>();
94+
for (char c = '0'; c <= '9'; ++c)
95+
{
96+
validHexCharacters.add(c);
97+
String s = new StringBuilder().append(c).toString();
98+
assertEquals(Integer.parseInt(s, 16), Hex.getHexValue(c));
99+
}
100+
for (char c = 'a'; c <= 'f'; ++c)
101+
{
102+
validHexCharacters.add(c);
103+
String s = new StringBuilder().append(c).toString();
104+
assertEquals(Integer.parseInt(s, 16), Hex.getHexValue(c));
105+
}
106+
for (char c = 'A'; c <= 'F'; ++c)
107+
{
108+
validHexCharacters.add(c);
109+
String s = new StringBuilder().append(c).toString();
110+
assertEquals(Integer.parseInt(s, 16), Hex.getHexValue(c));
111+
}
112+
assertEquals(22, validHexCharacters.size());
113+
for (char c = 0; c < 256; ++c)
114+
{
115+
if (!validHexCharacters.contains(c))
116+
{
117+
assertEquals(-256, Hex.getHexValue(c));
118+
}
119+
}
120+
}
88121
}

0 commit comments

Comments
 (0)