Improve some assertions and error messages for exceptions seen in the regression tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1873385 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2020-01-30 21:09:17 +00:00
parent 522ee9c554
commit d3767e1de7
4 changed files with 23 additions and 23 deletions

View File

@ -50,7 +50,7 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
// write out the file // write out the file
ByteArrayOutputStream out = writeToArray(ss); ByteArrayOutputStream out = writeToArray(ss);
readContent(ss); readContent(ss);
// read in the written file // read in the written file
@ -67,11 +67,11 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} finally { } finally {
stream.close(); stream.close();
} }
return stream; return stream;
} }
private void readContent(SlideShow<?,?> ss) { private void readContent(SlideShow<?,?> ss) {
for (Slide<?,?> s : ss.getSlides()) { for (Slide<?,?> s : ss.getSlides()) {
s.getTitle(); s.getTitle();
@ -96,8 +96,8 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
private void readShapes(Shape<?,?> s) { private void readShapes(Shape<?,?> s) {
// recursively walk group-shapes // recursively walk group-shapes
if(s instanceof GroupShape) { if(s instanceof GroupShape) {
GroupShape<? extends Shape, ?> shapes = (GroupShape<? extends Shape, ?>) s; GroupShape<? extends Shape<?,?>, ?> shapes = (GroupShape<? extends Shape<?,?>, ?>) s;
for (Shape<? extends Shape, ?> shape : shapes) { for (Shape<? extends Shape<?,?>, ?> shape : shapes) {
readShapes(shape); readShapes(shape);
} }
} }
@ -123,20 +123,22 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
} }
} }
} }
private void readPictures(SlideShow<?,?> ss) { private void readPictures(SlideShow<?,?> ss) {
for (PictureData pd : ss.getPictureData()) { for (PictureData pd : ss.getPictureData()) {
Dimension dim = pd.getImageDimension(); Dimension dim = pd.getImageDimension();
assertTrue(dim.getHeight() >= 0); assertTrue("Expecting a valid height, but had an image with height: " + dim.getHeight(),
assertTrue(dim.getWidth() >= 0); dim.getHeight() >= 0);
assertTrue("Expecting a valid width, but had an image with width: " + dim.getWidth(),
dim.getWidth() >= 0);
} }
} }
private void renderSlides(SlideShow<?,?> ss) { private void renderSlides(SlideShow<?,?> ss) {
Dimension pgsize = ss.getPageSize(); Dimension pgSize = ss.getPageSize();
for (Slide<?,?> s : ss.getSlides()) { for (Slide<?,?> s : ss.getSlides()) {
BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_ARGB); BufferedImage img = new BufferedImage(pgSize.width, pgSize.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D graphics = img.createGraphics(); Graphics2D graphics = img.createGraphics();
// default rendering options // default rendering options
@ -145,10 +147,10 @@ public abstract class SlideShowHandler extends POIFSFileHandler {
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
graphics.setRenderingHint(Drawable.BUFFERED_IMAGE, new WeakReference<>(img)); graphics.setRenderingHint(Drawable.BUFFERED_IMAGE, new WeakReference<>(img));
// draw stuff // draw stuff
s.draw(graphics); s.draw(graphics);
graphics.dispose(); graphics.dispose();
img.flush(); img.flush();
} }

View File

@ -89,13 +89,10 @@ public final class HeaderFooterRecord extends StandardRecord {
} }
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); return '[' + "HEADERFOOTER" + "] (0x" +
Integer.toHexString(sid).toUpperCase(Locale.ROOT) + ")\n" +
sb.append('[').append("HEADERFOOTER").append("] (0x"); " rawData=" + HexDump.toHex(_rawData) + "\n" +
sb.append(Integer.toHexString(sid).toUpperCase(Locale.ROOT)).append(")\n"); "[/" + "HEADERFOOTER" + "]\n";
sb.append(" rawData=").append(HexDump.toHex(_rawData)).append("\n");
sb.append("[/").append("HEADERFOOTER").append("]\n");
return sb.toString();
} }
@Override @Override

View File

@ -60,7 +60,7 @@ public abstract class HPBFPart {
dir = (DirectoryNode)dir.getEntry(path[i]); dir = (DirectoryNode)dir.getEntry(path[i]);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new IllegalArgumentException("File invalid - failed to find directory entry '" throw new IllegalArgumentException("File invalid - failed to find directory entry '"
+ path[i] + "'"); + path[i] + "': " + e);
} }
} }
return dir; return dir;
@ -101,7 +101,7 @@ public abstract class HPBFPart {
public final byte[] getData() { public final byte[] getData() {
return data; return data;
} }
protected final void setData(byte[] data) { protected final void setData(byte[] data) {
this.data = data.clone(); this.data = data.clone();
} }

View File

@ -64,7 +64,8 @@ public class ComplexFileTable {
this._grpprls = sprmBuffers.toArray(new SprmBuffer[0]); this._grpprls = sprmBuffers.toArray(new SprmBuffer[0]);
if (tableStream[offset] != TEXT_PIECE_TABLE_TYPE) { if (tableStream[offset] != TEXT_PIECE_TABLE_TYPE) {
throw new IOException("The text piece table is corrupted"); throw new IOException("The text piece table is corrupted, expected byte value " + TEXT_PIECE_TABLE_TYPE +
" but had " + tableStream[offset]);
} }
int pieceTableSize = LittleEndian.getInt(tableStream, ++offset); int pieceTableSize = LittleEndian.getInt(tableStream, ++offset);
offset += LittleEndian.INT_SIZE; offset += LittleEndian.INT_SIZE;