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
This commit is contained in:
Dominik Stadler 2015-09-29 07:51:48 +00:00
parent 8e02c19b15
commit 3109f16a7f
2 changed files with 44 additions and 0 deletions

View 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();
}
}

Binary file not shown.