]> source.dussan.org Git - poi.git/commitdiff
Add test which shows that bug 46515 is fixed since some time already.
authorDominik Stadler <centic@apache.org>
Tue, 29 Sep 2015 07:51:48 +0000 (07:51 +0000)
committerDominik Stadler <centic@apache.org>
Tue, 29 Sep 2015 07:51:48 +0000 (07:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705807 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/46515.xls [new file with mode: 0644]

index 37d592f6942f910c89a01f2c1d1377eb9fedcf61..b62cae1ef514337d6e2e3c93d1b3a14975e06e1e 100644 (file)
@@ -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 (file)
index 0000000..01c1dfe
Binary files /dev/null and b/test-data/spreadsheet/46515.xls differ