From 6a8332a1732fda8425e5885aca0774c9c68fcbf2 Mon Sep 17 00:00:00 2001 From: Andreas Beeker Date: Tue, 13 Dec 2016 00:31:23 +0000 Subject: [PATCH] eclipse warnings - raw list access close resources git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1773906 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/record/TestBOFRecord.java | 22 +- .../poi/hssf/record/TestHyperlinkRecord.java | 434 +++++++++--------- .../poi/hssf/record/TestRecordFactory.java | 49 +- .../usermodel/TestFormulaEvaluatorDocs.java | 26 +- .../poifs/filesystem/TestEmptyDocument.java | 41 +- 5 files changed, 280 insertions(+), 292 deletions(-) diff --git a/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java index 843e17d2a6..612fbcb651 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestBOFRecord.java @@ -17,25 +17,17 @@ package org.apache.poi.hssf.record; -import java.io.InputStream; - -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.hssf.HSSFTestDataSamples; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.junit.Test; /** * */ -public final class TestBOFRecord extends TestCase { - public void testBOFRecord() throws Exception { - InputStream is = HSSFTestDataSamples.openSampleFileStream("bug_42794.xls"); - - // This used to throw an error before - try { - new HSSFWorkbook(is); - } catch (ArrayIndexOutOfBoundsException e) { - throw new AssertionFailedError("Identified bug 42794"); - } +public final class TestBOFRecord { + @Test + public void testBOFRecord() throws IOException { + // This used to throw an error before - #42794 + HSSFTestDataSamples.openSampleWorkbook("bug_42794.xls").close(); } } diff --git a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java index 953266b4f5..2379a29db4 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java +++ b/src/testcases/org/apache/poi/hssf/record/TestHyperlinkRecord.java @@ -30,235 +30,245 @@ import org.junit.Test; /** * Test HyperlinkRecord - * - * @author Nick Burch - * @author Yegor Kozlov */ public final class TestHyperlinkRecord { //link to http://www.lakings.com/ - private static final byte[] data1 = { 0x02, 0x00, //First row of the hyperlink - 0x02, 0x00, //Last row of the hyperlink - 0x00, 0x00, //First column of the hyperlink - 0x00, 0x00, //Last column of the hyperlink - - //16-byte GUID. Seems to be always the same. Does not depend on the hyperlink type - (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - 0x02, 0x00, 0x00, 0x00, //integer, always 2 - - // flags. Define the type of the hyperlink: - // HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL - 0x17, 0x00, 0x00, 0x00, - - 0x08, 0x00, 0x00, 0x00, //length of the label including the trailing '\0' - - //label: - 0x4D, 0x00, 0x79, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6B, 0x00, 0x00, 0x00, - - //16-byte link moniker: HyperlinkRecord.URL_MONIKER - (byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - //count of bytes in the address including the tail - 0x48, 0x00, 0x00, 0x00, //integer - - //the actual link, terminated by '\u0000' - 0x68, 0x00, 0x74, 0x00, 0x74, 0x00, 0x70, 0x00, 0x3A, 0x00, 0x2F, 0x00, - 0x2F, 0x00, 0x77, 0x00, 0x77, 0x00, 0x77, 0x00, 0x2E, 0x00, 0x6C, 0x00, - 0x61, 0x00, 0x6B, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x73, 0x00, - 0x2E, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x2F, 0x00, 0x00, 0x00, - - //standard 24-byte tail of a URL link. Seems to always be the same for all URL HLINKs - 0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, 0x2C, - (byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00, - 0x00, (byte)0xA5, (byte)0xAB, 0x00, 0x00}; + private static final byte[] data1 = { + 0x02, 0x00, //First row of the hyperlink + 0x02, 0x00, //Last row of the hyperlink + 0x00, 0x00, //First column of the hyperlink + 0x00, 0x00, //Last column of the hyperlink + + //16-byte GUID. Seems to be always the same. Does not depend on the hyperlink type + (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + 0x02, 0x00, 0x00, 0x00, //integer, always 2 + + // flags. Define the type of the hyperlink: + // HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL + 0x17, 0x00, 0x00, 0x00, + + 0x08, 0x00, 0x00, 0x00, //length of the label including the trailing '\0' + + //label: + 0x4D, 0x00, 0x79, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x6B, 0x00, 0x00, 0x00, + + //16-byte link moniker: HyperlinkRecord.URL_MONIKER + (byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + //count of bytes in the address including the tail + 0x48, 0x00, 0x00, 0x00, //integer + + //the actual link, terminated by '\u0000' + 0x68, 0x00, 0x74, 0x00, 0x74, 0x00, 0x70, 0x00, 0x3A, 0x00, 0x2F, 0x00, + 0x2F, 0x00, 0x77, 0x00, 0x77, 0x00, 0x77, 0x00, 0x2E, 0x00, 0x6C, 0x00, + 0x61, 0x00, 0x6B, 0x00, 0x69, 0x00, 0x6E, 0x00, 0x67, 0x00, 0x73, 0x00, + 0x2E, 0x00, 0x63, 0x00, 0x6F, 0x00, 0x6D, 0x00, 0x2F, 0x00, 0x00, 0x00, + + //standard 24-byte tail of a URL link. Seems to always be the same for all URL HLINKs + 0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, 0x2C, + (byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00, + 0x00, (byte)0xA5, (byte)0xAB, 0x00, 0x00 + }; //link to a file in the current directory: link1.xls - private static final byte[] data2 = {0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type - (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - 0x02, 0x00, 0x00, 0x00, //integer, always 2 - - 0x15, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_LABEL - - 0x05, 0x00, 0x00, 0x00, //length of the label - //label - 0x66, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x00, 0x00, - - //16-byte link moniker: HyperlinkRecord.FILE_MONIKER - 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, - - 0x00, 0x00, //level - 0x0A, 0x00, 0x00, 0x00, //length of the path ) - - //path to the file (plain ISO-8859 bytes, NOT UTF-16LE!) - 0x6C, 0x69, 0x6E, 0x6B, 0x31, 0x2E, 0x78, 0x6C, 0x73, 0x00, - - //standard 24-byte tail of a file link - (byte)0xFF, (byte)0xFF, (byte)0xAD, (byte)0xDE, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - - 0x00, 0x00, 0x00, 0x00, // length of address link field - }; + private static final byte[] data2 = { + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type + (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + 0x02, 0x00, 0x00, 0x00, //integer, always 2 + + 0x15, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_LABEL + + 0x05, 0x00, 0x00, 0x00, //length of the label + //label + 0x66, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x65, 0x00, 0x00, 0x00, + + //16-byte link moniker: HyperlinkRecord.FILE_MONIKER + 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46, + + 0x00, 0x00, //level + 0x0A, 0x00, 0x00, 0x00, //length of the path ) + + //path to the file (plain ISO-8859 bytes, NOT UTF-16LE!) + 0x6C, 0x69, 0x6E, 0x6B, 0x31, 0x2E, 0x78, 0x6C, 0x73, 0x00, + + //standard 24-byte tail of a file link + (byte)0xFF, (byte)0xFF, (byte)0xAD, (byte)0xDE, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, // length of address link field + }; // mailto:ebgans@mail.ru?subject=Hello,%20Ebgans! - private static final byte[] data3 = {0x01, 0x00, - 0x01, 0x00, - 0x00, 0x00, - 0x00, 0x00, - - //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type - (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - 0x02, 0x00, 0x00, 0x00, //integer, always 2 - - 0x17, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL - - 0x06, 0x00, 0x00, 0x00, //length of the label - 0x65, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x00, 0x00, //label - - //16-byte link moniker: HyperlinkRecord.URL_MONIKER - (byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - //length of the address including the tail. - 0x76, 0x00, 0x00, 0x00, - - //the address is terminated by '\u0000' - 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x74, 0x00, 0x6F, 0x00, - 0x3A, 0x00, 0x65, 0x00, 0x62, 0x00, 0x67, 0x00, 0x61, 0x00, 0x6E, 0x00, - 0x73, 0x00, 0x40, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, - 0x2E, 0x00, 0x72, 0x00, 0x75, 0x00, 0x3F, 0x00, 0x73, 0x00, 0x75, 0x00, - 0x62, 0x00, 0x6A, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x3D, 0x00, - 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x2C, 0x00, - 0x25, 0x00, 0x32, 0x00, 0x30, 0x00, 0x45, 0x00, 0x62, 0x00, 0x67, 0x00, - 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x21, 0x00, 0x00, 0x00, - - //standard 24-byte tail of a URL link - 0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, (byte)0x2C, - (byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00, - 0x00, (byte)0xA5, (byte)0xAB, 0x00, 0x00 + private static final byte[] data3 = { + 0x01, 0x00, + 0x01, 0x00, + 0x00, 0x00, + 0x00, 0x00, + + //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type + (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + 0x02, 0x00, 0x00, 0x00, //integer, always 2 + + 0x17, 0x00, 0x00, 0x00, //options: HyperlinkRecord.HLINK_URL | HyperlinkRecord.HLINK_ABS | HyperlinkRecord.HLINK_LABEL + + 0x06, 0x00, 0x00, 0x00, //length of the label + 0x65, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x00, 0x00, //label + + //16-byte link moniker: HyperlinkRecord.URL_MONIKER + (byte)0xE0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + //length of the address including the tail. + 0x76, 0x00, 0x00, 0x00, + + //the address is terminated by '\u0000' + 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, 0x74, 0x00, 0x6F, 0x00, + 0x3A, 0x00, 0x65, 0x00, 0x62, 0x00, 0x67, 0x00, 0x61, 0x00, 0x6E, 0x00, + 0x73, 0x00, 0x40, 0x00, 0x6D, 0x00, 0x61, 0x00, 0x69, 0x00, 0x6C, 0x00, + 0x2E, 0x00, 0x72, 0x00, 0x75, 0x00, 0x3F, 0x00, 0x73, 0x00, 0x75, 0x00, + 0x62, 0x00, 0x6A, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x3D, 0x00, + 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x2C, 0x00, + 0x25, 0x00, 0x32, 0x00, 0x30, 0x00, 0x45, 0x00, 0x62, 0x00, 0x67, 0x00, + 0x61, 0x00, 0x6E, 0x00, 0x73, 0x00, 0x21, 0x00, 0x00, 0x00, + + //standard 24-byte tail of a URL link + 0x79, 0x58, (byte)0x81, (byte)0xF4, 0x3B, 0x1D, 0x7F, 0x48, (byte)0xAF, (byte)0x2C, + (byte)0x82, 0x5D, (byte)0xC4, (byte)0x85, 0x27, 0x63, 0x00, 0x00, 0x00, + 0x00, (byte)0xA5, (byte)0xAB, 0x00, 0x00 }; //link to a place in worksheet: Sheet1!A1 - private static final byte[] data4 = {0x03, 0x00, - 0x03, 0x00, - 0x00, 0x00, - 0x00, 0x00, - - //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type - (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, - (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, - - 0x02, 0x00, 0x00, 0x00, //integer, always 2 - - 0x1C, 0x00, 0x00, 0x00, //flags: HyperlinkRecord.HLINK_LABEL | HyperlinkRecord.HLINK_PLACE - - 0x06, 0x00, 0x00, 0x00, //length of the label - - 0x70, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x00, //label - - 0x0A, 0x00, 0x00, 0x00, //length of the document link including trailing zero - - //link: Sheet1!A1 - 0x53, 0x00, 0x68, 0x00, 0x65, 0x00, 0x65, 0x00, 0x74, 0x00, 0x31, 0x00, 0x21, - 0x00, 0x41, 0x00, 0x31, 0x00, 0x00, 0x00}; - - private static final byte[] dataLinkToWorkbook = HexRead.readFromString("01 00 01 00 01 00 01 00 " + - "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + - "02 00 00 00 " + - "1D 00 00 00 " + // options: LABEL | PLACE | FILE_OR_URL - // label: "My Label" - "09 00 00 00 " + - "4D 00 79 00 20 00 4C 00 61 00 62 00 65 00 6C 00 00 00 " + - "03 03 00 00 00 00 00 00 C0 00 00 00 00 00 00 46 " + // file GUID - "00 00 " + // file options - // shortFileName: "YEARFR~1.XLS" - "0D 00 00 00 " + - "59 45 41 52 46 52 7E 31 2E 58 4C 53 00 " + - // FILE_TAIL - unknown byte sequence - "FF FF AD DE 00 00 00 00 " + - "00 00 00 00 00 00 00 00 " + - "00 00 00 00 00 00 00 00 " + - // field len, char data len - "2E 00 00 00 " + - "28 00 00 00 " + - "03 00 " + // unknown ushort - // _address: "yearfracExamples.xls" - "79 00 65 00 61 00 72 00 66 00 72 00 61 00 63 00 " + - "45 00 78 00 61 00 6D 00 70 00 6C 00 65 00 73 00 " + - "2E 00 78 00 6C 00 73 00 " + - // textMark: "Sheet1!B6" - "0A 00 00 00 " + - "53 00 68 00 65 00 65 00 74 00 31 00 21 00 42 00 " + - "36 00 00 00"); - - private static final byte[] dataTargetFrame = HexRead.readFromString("0E 00 0E 00 00 00 00 00 " + - "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + - "02 00 00 00 " + - "83 00 00 00 " + // options: TARGET_FRAME | ABS | FILE_OR_URL - // targetFrame: "_blank" - "07 00 00 00 " + - "5F 00 62 00 6C 00 61 00 6E 00 6B 00 00 00 " + - // url GUID - "E0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + - // address: "http://www.regnow.com/softsell/nph-softsell.cgi?currency=USD&item=7924-37" - "94 00 00 00 " + - "68 00 74 00 74 00 70 00 3A 00 2F 00 2F 00 77 00 " + - "77 00 77 00 2E 00 72 00 65 00 67 00 6E 00 6F 00 " + - "77 00 2E 00 63 00 6F 00 6D 00 2F 00 73 00 6F 00 " + - "66 00 74 00 73 00 65 00 6C 00 6C 00 2F 00 6E 00 " + - "70 00 68 00 2D 00 73 00 6F 00 66 00 74 00 73 00 " + - "65 00 6C 00 6C 00 2E 00 63 00 67 00 69 00 3F 00 " + - "63 00 75 00 72 00 72 00 65 00 6E 00 63 00 79 00 " + - "3D 00 55 00 53 00 44 00 26 00 69 00 74 00 65 00 " + - "6D 00 3D 00 37 00 39 00 32 00 34 00 2D 00 33 00 " + - "37 00 00 00"); - - - private static final byte[] dataUNC = HexRead.readFromString("01 00 01 00 01 00 01 00 " + - "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + - "02 00 00 00 " + - "1F 01 00 00 " + // options: UNC_PATH | LABEL | TEXT_MARK | ABS | FILE_OR_URL - "09 00 00 00 " + // label: "My Label" - "4D 00 79 00 20 00 6C 00 61 00 62 00 65 00 6C 00 00 00 " + - // note - no moniker GUID - "27 00 00 00 " + // "\\\\MyServer\\my-share\\myDir\\PRODNAME.xls" - "5C 00 5C 00 4D 00 79 00 53 00 65 00 72 00 76 00 " + - "65 00 72 00 5C 00 6D 00 79 00 2D 00 73 00 68 00 " + - "61 00 72 00 65 00 5C 00 6D 00 79 00 44 00 69 00 " + - "72 00 5C 00 50 00 52 00 4F 00 44 00 4E 00 41 00 " + - "4D 00 45 00 2E 00 78 00 6C 00 73 00 00 00 " + - - "0C 00 00 00 " + // textMark: PRODNAME!C2 - "50 00 52 00 4F 00 44 00 4E 00 41 00 4D 00 45 00 21 00 " + - "43 00 32 00 00 00"); + private static final byte[] data4 = { + 0x03, 0x00, + 0x03, 0x00, + 0x00, 0x00, + 0x00, 0x00, + + //16-bit GUID. Seems to be always the same. Does not depend on the hyperlink type + (byte)0xD0, (byte)0xC9, (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, + (byte)0x8C, (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, + + 0x02, 0x00, 0x00, 0x00, //integer, always 2 + + 0x1C, 0x00, 0x00, 0x00, //flags: HyperlinkRecord.HLINK_LABEL | HyperlinkRecord.HLINK_PLACE + + 0x06, 0x00, 0x00, 0x00, //length of the label + + 0x70, 0x00, 0x6C, 0x00, 0x61, 0x00, 0x63, 0x00, 0x65, 0x00, 0x00, 0x00, //label + + 0x0A, 0x00, 0x00, 0x00, //length of the document link including trailing zero + + //link: Sheet1!A1 + 0x53, 0x00, 0x68, 0x00, 0x65, 0x00, 0x65, 0x00, 0x74, 0x00, 0x31, 0x00, 0x21, + 0x00, 0x41, 0x00, 0x31, 0x00, 0x00, 0x00 + }; + + private static final byte[] dataLinkToWorkbook = HexRead.readFromString( + "01 00 01 00 01 00 01 00 " + + "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + + "02 00 00 00 " + + "1D 00 00 00 " + // options: LABEL | PLACE | FILE_OR_URL + // label: "My Label" + "09 00 00 00 " + + "4D 00 79 00 20 00 4C 00 61 00 62 00 65 00 6C 00 00 00 " + + "03 03 00 00 00 00 00 00 C0 00 00 00 00 00 00 46 " + // file GUID + "00 00 " + // file options + // shortFileName: "YEARFR~1.XLS" + "0D 00 00 00 " + + "59 45 41 52 46 52 7E 31 2E 58 4C 53 00 " + + // FILE_TAIL - unknown byte sequence + "FF FF AD DE 00 00 00 00 " + + "00 00 00 00 00 00 00 00 " + + "00 00 00 00 00 00 00 00 " + + // field len, char data len + "2E 00 00 00 " + + "28 00 00 00 " + + "03 00 " + // unknown ushort + // _address: "yearfracExamples.xls" + "79 00 65 00 61 00 72 00 66 00 72 00 61 00 63 00 " + + "45 00 78 00 61 00 6D 00 70 00 6C 00 65 00 73 00 " + + "2E 00 78 00 6C 00 73 00 " + + // textMark: "Sheet1!B6" + "0A 00 00 00 " + + "53 00 68 00 65 00 65 00 74 00 31 00 21 00 42 00 " + + "36 00 00 00" + ); + + private static final byte[] dataTargetFrame = HexRead.readFromString( + "0E 00 0E 00 00 00 00 00 " + + "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + + "02 00 00 00 " + + "83 00 00 00 " + // options: TARGET_FRAME | ABS | FILE_OR_URL + // targetFrame: "_blank" + "07 00 00 00 " + + "5F 00 62 00 6C 00 61 00 6E 00 6B 00 00 00 " + + // url GUID + "E0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + + // address: "http://www.regnow.com/softsell/nph-softsell.cgi?currency=USD&item=7924-37" + "94 00 00 00 " + + "68 00 74 00 74 00 70 00 3A 00 2F 00 2F 00 77 00 " + + "77 00 77 00 2E 00 72 00 65 00 67 00 6E 00 6F 00 " + + "77 00 2E 00 63 00 6F 00 6D 00 2F 00 73 00 6F 00 " + + "66 00 74 00 73 00 65 00 6C 00 6C 00 2F 00 6E 00 " + + "70 00 68 00 2D 00 73 00 6F 00 66 00 74 00 73 00 " + + "65 00 6C 00 6C 00 2E 00 63 00 67 00 69 00 3F 00 " + + "63 00 75 00 72 00 72 00 65 00 6E 00 63 00 79 00 " + + "3D 00 55 00 53 00 44 00 26 00 69 00 74 00 65 00 " + + "6D 00 3D 00 37 00 39 00 32 00 34 00 2D 00 33 00 " + + "37 00 00 00" + ); + + + private static final byte[] dataUNC = HexRead.readFromString( + "01 00 01 00 01 00 01 00 " + + "D0 C9 EA 79 F9 BA CE 11 8C 82 00 AA 00 4B A9 0B " + + "02 00 00 00 " + + "1F 01 00 00 " + // options: UNC_PATH | LABEL | TEXT_MARK | ABS | FILE_OR_URL + "09 00 00 00 " + // label: "My Label" + "4D 00 79 00 20 00 6C 00 61 00 62 00 65 00 6C 00 00 00 " + + // note - no moniker GUID + "27 00 00 00 " + // "\\\\MyServer\\my-share\\myDir\\PRODNAME.xls" + "5C 00 5C 00 4D 00 79 00 53 00 65 00 72 00 76 00 " + + "65 00 72 00 5C 00 6D 00 79 00 2D 00 73 00 68 00 " + + "61 00 72 00 65 00 5C 00 6D 00 79 00 44 00 69 00 " + + "72 00 5C 00 50 00 52 00 4F 00 44 00 4E 00 41 00 " + + "4D 00 45 00 2E 00 78 00 6C 00 73 00 00 00 " + + + "0C 00 00 00 " + // textMark: PRODNAME!C2 + "50 00 52 00 4F 00 44 00 4E 00 41 00 4D 00 45 00 21 00 " + + "43 00 32 00 00 00" + ); /** * From Bugzilla 47498 */ private static byte[] data_47498 = { - 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xD0, (byte)0xC9, - (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, (byte)0x8C, - (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x02, 0x00, - 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x00, - 0x44, 0x00, 0x46, 0x00, 0x00, 0x00, (byte)0xE0, (byte)0xC9, (byte)0xEA, - 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, (byte)0x11, (byte)0x8C, (byte)0x82, - 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x28, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x66, 0x00, 0x6F, 0x00, - 0x6C, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00, 0x2F, 0x00, 0x74, 0x00, - 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x2E, 0x00, 0x50, 0x00, 0x44, 0x00, - 0x46, 0x00, 0x00, 0x00}; + 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, (byte)0xD0, (byte)0xC9, + (byte)0xEA, 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, 0x11, (byte)0x8C, + (byte)0x82, 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x02, 0x00, + 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x50, 0x00, + 0x44, 0x00, 0x46, 0x00, 0x00, 0x00, (byte)0xE0, (byte)0xC9, (byte)0xEA, + 0x79, (byte)0xF9, (byte)0xBA, (byte)0xCE, (byte)0x11, (byte)0x8C, (byte)0x82, + 0x00, (byte)0xAA, 0x00, 0x4B, (byte)0xA9, 0x0B, 0x28, 0x00, 0x00, 0x00, + 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x66, 0x00, 0x6F, 0x00, + 0x6C, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x00, 0x2F, 0x00, 0x74, 0x00, + 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x2E, 0x00, 0x50, 0x00, 0x44, 0x00, + 0x46, 0x00, 0x00, 0x00 + }; private void confirmGUID(GUID expectedGuid, GUID actualGuid) { diff --git a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java index 8be6684fe9..5b46346bd4 100644 --- a/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java +++ b/src/testcases/org/apache/poi/hssf/record/TestRecordFactory.java @@ -17,28 +17,22 @@ package org.apache.poi.hssf.record; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.*; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Iterator; import java.util.List; -import junit.framework.AssertionFailedError; -import junit.framework.TestCase; - import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.util.HexRead; +import org.junit.Test; /** * Tests the record factory - * @author Glen Stampoultzis (glens at apache.org) - * @author Andrew C. Oliver (acoliver at apache dot org) - * @author Csaba Nagy (ncsaba at yahoo dot com) */ -public final class TestRecordFactory extends TestCase { +public final class TestRecordFactory { /** @@ -49,6 +43,7 @@ public final class TestRecordFactory extends TestCase { * FAILURE: The wrong records are creates or contain the wrong values

* */ + @Test public void testBasicRecordConstruction() { short recType = BOFRecord.sid; byte[] data = { @@ -91,7 +86,8 @@ public final class TestRecordFactory extends TestCase { * FAILURE: The wrong records are created or contain the wrong values

* */ - public void testSpecial() { + @Test + public void testSpecial() { short recType = RKRecord.sid; byte[] data = { 0, 0, 0, 0, 21, 0, 0, 0, 0, 0 @@ -117,6 +113,7 @@ public final class TestRecordFactory extends TestCase { * SUCCESS: Record factory creates the expected records.

* FAILURE: The wrong records are created or contain the wrong values

*/ + @Test public void testContinuedUnknownRecord() { byte[] data = { 0, -1, 0, 0, // an unknown record with 0 length @@ -152,7 +149,8 @@ public final class TestRecordFactory extends TestCase { * There can actually be OBJ records mixed between the continues. * Record factory must preserve this structure when reading records. */ - public void testMixedContinue() throws Exception { + @Test + public void testMixedContinue() throws IOException { /** * Adapted from a real test sample file 39512.xls (Offset 0x4854). * See Bug 39512 for details. @@ -184,7 +182,7 @@ public final class TestRecordFactory extends TestCase { "00 00 00 00 00 00 00"; byte[] data = HexRead.readFromString(dump); - List records = RecordFactory.createRecords(new ByteArrayInputStream(data)); + List records = RecordFactory.createRecords(new ByteArrayInputStream(data)); assertEquals(5, records.size()); assertTrue(records.get(0) instanceof ObjRecord); assertTrue(records.get(1) instanceof DrawingRecord); @@ -194,8 +192,7 @@ public final class TestRecordFactory extends TestCase { //serialize and verify that the serialized data is the same as the original ByteArrayOutputStream out = new ByteArrayOutputStream(); - for(Iterator it = records.iterator(); it.hasNext(); ){ - Record rec = (Record)it.next(); + for(Record rec : records){ out.write(rec.serialize()); } @@ -204,7 +201,8 @@ public final class TestRecordFactory extends TestCase { assertArrayEquals(data, ser); } - public void testNonZeroPadding_bug46987() { + @Test + public void testNonZeroPadding_bug46987() throws IOException { Record[] recs = { new BOFRecord(), new WriteAccessRecord(), // need *something* between BOF and EOF @@ -231,23 +229,12 @@ public final class TestRecordFactory extends TestCase { POIFSFileSystem fs = new POIFSFileSystem(); - InputStream is; - try { - fs.createDocument(new ByteArrayInputStream(baos.toByteArray()), "dummy"); - is = fs.getRoot().createDocumentInputStream("dummy"); - } catch (IOException e) { - throw new RuntimeException(e); - } + fs.createDocument(new ByteArrayInputStream(baos.toByteArray()), "dummy"); + InputStream is = fs.getRoot().createDocumentInputStream("dummy"); - List outRecs; - try { - outRecs = RecordFactory.createRecords(is); - } catch (RuntimeException e) { - if (e.getMessage().equals("Buffer underrun - requested 512 bytes but 192 was available")) { - throw new AssertionFailedError("Identified bug 46987"); - } - throw e; - } + List outRecs = RecordFactory.createRecords(is); + // Buffer underrun - requested 512 bytes but 192 was available assertEquals(5, outRecs.size()); + fs.close(); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java index 3ceebffa54..5e52a0c149 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulaEvaluatorDocs.java @@ -17,9 +17,10 @@ package org.apache.poi.hssf.usermodel; -import java.util.Iterator; - +import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import junit.framework.TestCase; @@ -68,15 +69,10 @@ public final class TestFormulaEvaluatorDocs extends TestCase { // Do a full evaluate, as per our docs // uses evaluateFormulaCell() - for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) { - HSSFSheet sheet = wb.getSheetAt(sheetNum); + for(Sheet sheet : wb) { HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); - - for(Iterator rit = sheet.rowIterator(); rit.hasNext();) { - HSSFRow r = (HSSFRow)rit.next(); - - for(Iterator cit = r.cellIterator(); cit.hasNext();) { - HSSFCell c = (HSSFCell)cit.next(); + for(Row r : sheet) { + for(Cell c : r) { if(c.getCellTypeEnum() == CellType.FORMULA) { evaluator.evaluateFormulaCellEnum(c); @@ -103,15 +99,11 @@ public final class TestFormulaEvaluatorDocs extends TestCase { // Now do the alternate call, which zaps the formulas // uses evaluateInCell() - for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) { - HSSFSheet sheet = wb.getSheetAt(sheetNum); + for(Sheet sheet : wb) { HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb); - for(Iterator rit = sheet.rowIterator(); rit.hasNext();) { - HSSFRow r = (HSSFRow)rit.next(); - - for(Iterator cit = r.cellIterator(); cit.hasNext();) { - HSSFCell c = (HSSFCell)cit.next(); + for(Row r : sheet) { + for(Cell c : r) { if(c.getCellTypeEnum() == CellType.FORMULA) { evaluator.evaluateInCell(c); } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java index 22449e5c6c..9c7b688b58 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestEmptyDocument.java @@ -17,24 +17,22 @@ package org.apache.poi.poifs.filesystem; -import java.io.IOException; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.util.Arrays; - -import junit.framework.TestCase; +import java.io.IOException; import org.apache.poi.util.IOUtils; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.poifs.filesystem.POIFSWriterEvent; -import org.apache.poi.poifs.filesystem.POIFSWriterListener; -import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogger; +import org.junit.Test; -public final class TestEmptyDocument extends TestCase { - private static POILogger _logger = POILogFactory.getLogger(TestEmptyDocument.class); +public final class TestEmptyDocument { + private static final POILogger LOG = POILogFactory.getLogger(TestEmptyDocument.class); + @Test public void testSingleEmptyDocument() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dir = fs.getRoot(); @@ -42,24 +40,28 @@ public final class TestEmptyDocument extends TestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close(); + fs.close(); } + @Test public void testSingleEmptyDocumentEvent() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dir = fs.getRoot(); dir.createDocument("Foo", 0, new POIFSWriterListener() { @Override public void processPOIFSWriterEvent(POIFSWriterEvent event) { - _logger.log(POILogger.WARN, "written"); + LOG.log(POILogger.WARN, "written"); } }); ByteArrayOutputStream out = new ByteArrayOutputStream(); fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close(); + fs.close(); } + @Test public void testEmptyDocumentWithFriend() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dir = fs.getRoot(); @@ -68,9 +70,11 @@ public final class TestEmptyDocument extends TestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close(); + fs.close(); } + @Test public void testEmptyDocumentEventWithFriend() throws IOException { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry dir = fs.getRoot(); @@ -92,9 +96,11 @@ public final class TestEmptyDocument extends TestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); fs.writeFilesystem(out); - new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); + new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())).close(); + fs.close(); } + @Test public void testEmptyDocumentBug11744() throws Exception { byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -104,6 +110,7 @@ public final class TestEmptyDocument extends TestCase { ByteArrayOutputStream out = new ByteArrayOutputStream(); fs.writeFilesystem(out); out.toByteArray(); + fs.close(); // This line caused the error. fs = new POIFSFileSystem(new ByteArrayInputStream(out.toByteArray())); @@ -117,7 +124,7 @@ public final class TestEmptyDocument extends TestCase { entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty"); actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry)); assertEquals("Expected size was wrong", testData.length, entry.getSize()); - assertTrue("Expected different data read from stream", Arrays.equals(testData, - actualReadbackData)); + assertArrayEquals("Expected same data read from stream", testData, actualReadbackData); + fs.close(); } } -- 2.39.5