Author: centic
Date: Sat Feb 23 07:51:57 2019
New Revision: 1854190
URL: http://svn.apache.org/viewvc?rev=1854190&view=rev
Log:
Add some more testing for bug 63151: NullPointerException in
HSSFOptimiser.optimiseFonts(), also execute it as part of large regression
tests in the future
Modified:
poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
poi/trunk/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
Modified:
poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java?rev=1854190&r1=1854189&r2=1854190&view=diff
==============================================================================
--- poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
(original)
+++ poi/trunk/src/integrationtest/org/apache/poi/stress/HSSFFileHandler.java
Sat Feb 23 07:51:57 2019
@@ -64,6 +64,8 @@ public class HSSFFileHandler extends Spr
}
}
}
+
+ HSSFOptimiser.optimiseFonts(wb);
}
private static final Set<String> EXPECTED_ADDITIONAL_FAILURES = new
HashSet<>();
@@ -85,6 +87,7 @@ public class HSSFFileHandler extends Spr
public void handleAdditional(File file) throws Exception {
// redirect stdout as the examples often write lots of text
PrintStream oldOut = System.out;
+ String fileWithParent = file.getParentFile().getName() + "/" +
file.getName();
try {
System.setOut(new PrintStream(new OutputStream() {
@Override
@@ -95,11 +98,11 @@ public class HSSFFileHandler extends Spr
BiffViewer.main(new String[]{file.getAbsolutePath()});
assertFalse("Expected Extraction to fail for file " +
file + " and handler " + this + ", but did not fail!",
-
EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/" +
file.getName()));
+
EXPECTED_ADDITIONAL_FAILURES.contains(fileWithParent));
} catch (OldExcelFormatException e) {
// old excel formats are not supported here
} catch (RuntimeException e) {
-
if(!EXPECTED_ADDITIONAL_FAILURES.contains(file.getParentFile().getName() + "/"
+ file.getName())) {
+
if(!EXPECTED_ADDITIONAL_FAILURES.contains(fileWithParent)) {
throw e;
}
} finally {
Modified:
poi/trunk/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/common/UnicodeString.java?rev=1854190&r1=1854189&r2=1854190&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/common/UnicodeString.java
(original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/common/UnicodeString.java Sat
Feb 23 07:51:57 2019
@@ -712,7 +712,7 @@ public class UnicodeString implements Co
if (field_4_format_runs != null) {
for (int i = 0; i < field_4_format_runs.size();i++) {
FormatRun r = field_4_format_runs.get(i);
- buffer.append(" .format_run"+i+" =
").append(r).append("\n");
+ buffer.append(" .format_run").append(i).append(" =
").append(r).append("\n");
}
}
if (field_5_ext_rst != null) {
Modified:
poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
URL:
http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java?rev=1854190&r1=1854189&r2=1854190&view=diff
==============================================================================
---
poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
(original)
+++
poi/trunk/src/testcases/org/apache/poi/hssf/record/common/TestUnicodeString.java
Sat Feb 23 07:51:57 2019
@@ -59,9 +59,10 @@ public final class TestUnicodeString {
private static void confirmSize(int expectedSize, UnicodeString s) {
confirmSize(expectedSize, s, 0);
}
+
/**
* Note - a value of zero for <tt>amountUsedInCurrentRecord</tt> would
only ever occur just
- * after a {@link ContinueRecord} had been started. In the initial {@link
SSTRecord} this
+ * after a {@link ContinueRecord} had been started. In the initial {@link
SSTRecord} this
* value starts at 8 (for the first {@link UnicodeString} written). In
general, it can be
* any value between 0 and {@link #MAX_DATA_SIZE}
*/
@@ -181,7 +182,7 @@ public final class TestUnicodeString {
}
@Test
- public void formatRun() throws Exception {
+ public void formatRun() {
FormatRun fr = new FormatRun((short)4, (short)0x15c);
assertEquals(4, fr.getCharacterPos());
assertEquals(0x15c, fr.getFontIndex());
@@ -207,7 +208,7 @@ public final class TestUnicodeString {
}
@Test
- public void extRstFromEmpty() throws Exception {
+ public void extRstFromEmpty() {
ExtRst ext = new ExtRst();
assertEquals(0, ext.getNumberOfRuns());
@@ -231,14 +232,14 @@ public final class TestUnicodeString {
assertEquals(-1, b[0]);
assertEquals(-1, b[1]);
assertEquals(14, b[2]);
- assertEquals(00, b[3]);
+ assertEquals(0, b[3]);
// Reserved
assertEquals(1, b[4]);
assertEquals(0, b[5]);
// Data size
assertEquals(10, b[6]);
- assertEquals(00, b[7]);
+ assertEquals(0, b[7]);
// Font*2
assertEquals(0, b[8]);
assertEquals(0, b[9]);
@@ -274,13 +275,13 @@ public final class TestUnicodeString {
}
@Test
- public void extRstFromData() throws Exception {
+ public void extRstFromData() {
byte[] data = new byte[] {
- 01, 00, 0x0C, 00,
- 00, 00, 0x37, 00,
- 00, 00,
- 00, 00, 00, 00,
- 00, 00 // Cruft at the end, as found from real files
+ 1, 0, 0x0C, 0,
+ 0, 0, 0x37, 0,
+ 0, 0,
+ 0, 0, 0, 0,
+ 0, 0 // Cruft at the end, as found from real files
};
assertEquals(16, data.length);
@@ -298,7 +299,7 @@ public final class TestUnicodeString {
}
@Test
- public void corruptExtRstDetection() throws Exception {
+ public void corruptExtRstDetection() {
byte[] data = new byte[] {
0x79, 0x79, 0x11, 0x11,
0x22, 0x22, 0x33, 0x33,
@@ -385,7 +386,7 @@ public final class TestUnicodeString {
* @return a string of the specified number of characters
*/
private static UnicodeString makeUnicodeString(int numChars, boolean
is16Bit) {
- StringBuilder b = new StringBuilder(numChars);
+ StringBuilder b = new StringBuilder(numChars);
int charBase = is16Bit ? 0x8A00 : 'A';
for (int i = 0; i < numChars; i++) {
char ch = (char) ((i % 16) + charBase);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]