From: Dominik Stadler Date: Tue, 29 Sep 2015 07:51:48 +0000 (+0000) Subject: Add test which shows that bug 46515 is fixed since some time already. X-Git-Tag: REL_3_14_BETA1~285 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3109f16a7ff17da81917a2830c8789109e9c39bf;p=poi.git Add test which shows that bug 46515 is fixed since some time already. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705807 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java index 37d592f694..b62cae1ef5 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java @@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; @@ -31,6 +32,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -39,6 +41,8 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; +import javax.imageio.ImageIO; + import org.apache.poi.EncryptedDocumentException; import org.apache.poi.hssf.HSSFITestDataProvider; import org.apache.poi.hssf.HSSFTestDataSamples; @@ -75,6 +79,7 @@ import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.LocaleUtil; import org.junit.After; +import org.junit.Assume; import org.junit.Ignore; import org.junit.Test; @@ -2930,4 +2935,43 @@ public final class TestBugs extends BaseTestBugzillaIssues { wb.close(); } + + @Test + public void test46515() throws IOException { + Workbook wb = HSSFTestDataSamples.openSampleWorkbook("46515.xls"); + + // Get structure from webservice + String urlString = "http://poi.apache.org/resources/images/project-logo.jpg"; + URL structURL = new URL(urlString); + BufferedImage bimage; + try { + bimage = ImageIO.read(structURL); + } catch (IOException e) { + Assume.assumeNoException("Downloading a jpg from poi.apache.org should work", e); + return; + } + + // Convert BufferedImage to byte[] + ByteArrayOutputStream imageBAOS = new ByteArrayOutputStream(); + ImageIO.write(bimage, "jpeg", imageBAOS); + imageBAOS.flush(); + byte[]imageBytes = imageBAOS.toByteArray(); + imageBAOS.close(); + + // Pop structure into Structure HSSFSheet + int pict = wb.addPicture(imageBytes, HSSFWorkbook.PICTURE_TYPE_JPEG); + Sheet sheet = wb.getSheet("Structure"); + assertNotNull("Did not find sheet", sheet); + HSSFPatriarch patriarch = (HSSFPatriarch) sheet.createDrawingPatriarch(); + HSSFClientAnchor anchor = new HSSFClientAnchor(0, 0, 0, 0, (short) 1, 1, (short) 10, 22); + anchor.setAnchorType(2); + patriarch.createPicture(anchor, pict); + + // Write out destination file +// FileOutputStream fileOut = new FileOutputStream("/tmp/46515.xls"); +// wb.write(fileOut); +// fileOut.close(); + + wb.close(); + } } diff --git a/test-data/spreadsheet/46515.xls b/test-data/spreadsheet/46515.xls new file mode 100644 index 0000000000..01c1dfe517 Binary files /dev/null and b/test-data/spreadsheet/46515.xls differ