You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [30/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestEmbeddedObjectRefSubRecord.java Sat May 22 20:56:44 2021
@@ -30,125 +30,125 @@ import org.junit.jupiter.api.Test;
*/
final class TestEmbeddedObjectRefSubRecord {
- private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid;
+ private static final short EORSR_SID = EmbeddedObjectRefSubRecord.sid;
- @Test
- void testStore() {
- String data1
- = "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 "
- + "00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E "
- + "31 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 "
- + "00 00";
-
- byte[] src = hr(data1);
-
- RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, src);
-
- EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length);
-
- byte[] ser = record1.serialize();
-
- RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
- EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
- confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, src, ser);
- assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
-
- byte[] ser2 = record1.serialize();
- assertArrayEquals(ser, ser2);
- }
-
- @Test
- void testCreate() {
- EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
-
- byte[] ser = record1.serialize();
- RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
- EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
-
- assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
- assertEquals(record1.getStreamId(), record2.getStreamId());
-
- byte[] ser2 = record1.serialize();
- assertArrayEquals(ser, ser2);
- }
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testCameraTool_bug45912() {
- /*
- * taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
- */
- byte[] data45912 = hr(
- "12 00 0B 00 F8 02 88 04 3B 00 " +
- "00 00 00 01 00 00 00 01 " +
- "00 00");
- RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data45912);
-
- EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length);
- byte[] ser2 = rec.serialize();
- confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, data45912, ser2);
- }
-
- private static byte[] hr(String string) {
- return HexRead.readFromString(string);
- }
-
- /**
- * tests various examples of OLE controls
- */
- @SuppressWarnings("squid:S2699")
- @Test
- void testVarious() {
- String[] rawData = {
- "12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18",
- "12 00 0B 00 B0 4D 3E 03 3B 00 00 00 00 01 00 00 80 01 C0 00",
- "0C 00 05 00 60 AF 3B 03 24 FD FF FE C0 FE",
- "24 00 05 00 40 42 3E 03 02 80 CD B4 04 03 15 00 00 46 6F 72 6D 73 2E 43 6F 6D 6D 61 6E 64 42 75 74 74 6F 6E 2E 31 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
- "22 00 05 00 10 4E 3E 03 02 00 4C CC 04 03 12 00 00 46 6F 72 6D 73 2E 53 70 69 6E 42 75 74 74 6F 6E 2E 31 00 54 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
- "20 00 05 00 E0 41 3E 03 02 00 FC 0B 05 03 10 00 00 46 6F 72 6D 73 2E 43 6F 6D 62 6F 42 6F 78 2E 31 00 74 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00",
- "24 00 05 00 00 4C AF 03 02 80 E1 93 05 03 14 00 00 46 6F 72 6D 73 2E 4F 70 74 69 6F 6E 42 75 74 74 6F 6E 2E 31 00 C0 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00",
- "20 00 05 00 E0 A4 28 04 02 80 EA 93 05 03 10 00 00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E 31 00 30 01 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
- "1C 00 05 00 30 40 3E 03 02 00 CC B4 04 03 0D 00 00 46 6F 72 6D 73 2E 4C 61 62 65 6C 2E 31 9C 01 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
- "1E 00 05 00 B0 A4 28 04 02 00 D0 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 4C 69 73 74 42 6F 78 2E 31 F0 01 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
- "24 00 05 00 C0 AF 3B 03 02 80 D1 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 38 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
- "1E 00 05 00 90 AF 3B 03 02 80 D4 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 54 65 78 74 42 6F 78 2E 31 A4 02 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
- "24 00 05 00 60 40 3E 03 02 00 D6 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 EC 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
- "20 00 05 00 20 4D 3E 03 02 00 D9 0A 05 03 11 00 00 46 6F 72 6D 73 2E 53 63 72 6F 6C 6C 42 61 72 2E 31 58 03 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
- "20 00 05 00 00 AF 28 04 02 80 31 AC 04 03 10 00 00 53 68 65 6C 6C 2E 45 78 70 6C 6F 72 65 72 2E 32 00 78 03 00 00 AC 00 00 00 00 00 00 00 00 00 00 00",
- };
-
- for (int i = 0; i < rawData.length; i++) {
- confirmRead(hr(rawData[i]), i);
- }
- }
-
- private static void confirmRead(byte[] data, int i) {
- RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data);
-
- EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
- byte[] ser2 = rec.serialize();
- confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
- }
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testVisioDrawing_bug46199() {
- /*
- * taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br>
- * Note that the since the string length is zero, there is no unicode flag byte
- */
- byte[] data46199 = hr(
- "0E 00 "
- + "05 00 "
- + "28 25 A3 01 "
- + "02 6C D1 34 02 "
- + "03 00 00 "
- + "0F CB E8 00");
- RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199);
-
- // bug 22860 - Not enough data (3) to read requested (4) bytes
- EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
- byte[] ser2 = rec.serialize();
- confirmRecordEncoding(EORSR_SID, data46199, ser2);
- }
+ @Test
+ void testStore() {
+ String data1
+ = "20 00 05 00 FC 10 76 01 02 24 14 DF 00 03 10 00 "
+ + "00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E "
+ + "31 00 00 00 00 00 70 00 00 00 00 00 00 00 00 00 "
+ + "00 00";
+
+ byte[] src = hr(data1);
+
+ RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, src);
+
+ EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord(in, src.length);
+
+ byte[] ser = record1.serialize();
+
+ RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
+ EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
+ confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, src, ser);
+ assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
+
+ byte[] ser2 = record1.serialize();
+ assertArrayEquals(ser, ser2);
+ }
+
+ @Test
+ void testCreate() {
+ EmbeddedObjectRefSubRecord record1 = new EmbeddedObjectRefSubRecord();
+
+ byte[] ser = record1.serialize();
+ RecordInputStream in2 = TestcaseRecordInputStream.create(ser);
+ EmbeddedObjectRefSubRecord record2 = new EmbeddedObjectRefSubRecord(in2, ser.length-4);
+
+ assertEquals(record1.getOLEClassName(), record2.getOLEClassName());
+ assertEquals(record1.getStreamId(), record2.getStreamId());
+
+ byte[] ser2 = record1.serialize();
+ assertArrayEquals(ser, ser2);
+ }
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testCameraTool_bug45912() {
+ /*
+ * taken from ftPictFmla sub-record in attachment 22645 (offset 0x40AB).
+ */
+ byte[] data45912 = hr(
+ "12 00 0B 00 F8 02 88 04 3B 00 " +
+ "00 00 00 01 00 00 00 01 " +
+ "00 00");
+ RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data45912);
+
+ EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data45912.length);
+ byte[] ser2 = rec.serialize();
+ confirmRecordEncoding(EmbeddedObjectRefSubRecord.sid, data45912, ser2);
+ }
+
+ private static byte[] hr(String string) {
+ return HexRead.readFromString(string);
+ }
+
+ /**
+ * tests various examples of OLE controls
+ */
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testVarious() {
+ String[] rawData = {
+ "12 00 0B 00 70 95 0B 05 3B 01 00 36 00 40 00 18 00 19 00 18",
+ "12 00 0B 00 B0 4D 3E 03 3B 00 00 00 00 01 00 00 80 01 C0 00",
+ "0C 00 05 00 60 AF 3B 03 24 FD FF FE C0 FE",
+ "24 00 05 00 40 42 3E 03 02 80 CD B4 04 03 15 00 00 46 6F 72 6D 73 2E 43 6F 6D 6D 61 6E 64 42 75 74 74 6F 6E 2E 31 00 00 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
+ "22 00 05 00 10 4E 3E 03 02 00 4C CC 04 03 12 00 00 46 6F 72 6D 73 2E 53 70 69 6E 42 75 74 74 6F 6E 2E 31 00 54 00 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
+ "20 00 05 00 E0 41 3E 03 02 00 FC 0B 05 03 10 00 00 46 6F 72 6D 73 2E 43 6F 6D 62 6F 42 6F 78 2E 31 00 74 00 00 00 4C 00 00 00 00 00 00 00 00 00 00 00",
+ "24 00 05 00 00 4C AF 03 02 80 E1 93 05 03 14 00 00 46 6F 72 6D 73 2E 4F 70 74 69 6F 6E 42 75 74 74 6F 6E 2E 31 00 C0 00 00 00 70 00 00 00 00 00 00 00 00 00 00 00",
+ "20 00 05 00 E0 A4 28 04 02 80 EA 93 05 03 10 00 00 46 6F 72 6D 73 2E 43 68 65 63 6B 42 6F 78 2E 31 00 30 01 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
+ "1C 00 05 00 30 40 3E 03 02 00 CC B4 04 03 0D 00 00 46 6F 72 6D 73 2E 4C 61 62 65 6C 2E 31 9C 01 00 00 54 00 00 00 00 00 00 00 00 00 00 00",
+ "1E 00 05 00 B0 A4 28 04 02 00 D0 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 4C 69 73 74 42 6F 78 2E 31 F0 01 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
+ "24 00 05 00 C0 AF 3B 03 02 80 D1 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 38 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
+ "1E 00 05 00 90 AF 3B 03 02 80 D4 0A 05 03 0F 00 00 46 6F 72 6D 73 2E 54 65 78 74 42 6F 78 2E 31 A4 02 00 00 48 00 00 00 00 00 00 00 00 00 00 00",
+ "24 00 05 00 60 40 3E 03 02 00 D6 0A 05 03 14 00 00 46 6F 72 6D 73 2E 54 6F 67 67 6C 65 42 75 74 74 6F 6E 2E 31 00 EC 02 00 00 6C 00 00 00 00 00 00 00 00 00 00 00",
+ "20 00 05 00 20 4D 3E 03 02 00 D9 0A 05 03 11 00 00 46 6F 72 6D 73 2E 53 63 72 6F 6C 6C 42 61 72 2E 31 58 03 00 00 20 00 00 00 00 00 00 00 00 00 00 00",
+ "20 00 05 00 00 AF 28 04 02 80 31 AC 04 03 10 00 00 53 68 65 6C 6C 2E 45 78 70 6C 6F 72 65 72 2E 32 00 78 03 00 00 AC 00 00 00 00 00 00 00 00 00 00 00",
+ };
+
+ for (int i = 0; i < rawData.length; i++) {
+ confirmRead(hr(rawData[i]), i);
+ }
+ }
+
+ private static void confirmRead(byte[] data, int i) {
+ RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data);
+
+ EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data.length);
+ byte[] ser2 = rec.serialize();
+ confirmRecordEncoding("Test record " + i, EORSR_SID, data, ser2);
+ }
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testVisioDrawing_bug46199() {
+ /*
+ * taken from ftPictFmla sub-record in attachment 22860 (stream offset 0x768F).<br>
+ * Note that the since the string length is zero, there is no unicode flag byte
+ */
+ byte[] data46199 = hr(
+ "0E 00 "
+ + "05 00 "
+ + "28 25 A3 01 "
+ + "02 6C D1 34 02 "
+ + "03 00 00 "
+ + "0F CB E8 00");
+ RecordInputStream in = TestcaseRecordInputStream.create(EORSR_SID, data46199);
+
+ // bug 22860 - Not enough data (3) to read requested (4) bytes
+ EmbeddedObjectRefSubRecord rec = new EmbeddedObjectRefSubRecord(in, data46199.length);
+ byte[] ser2 = rec.serialize();
+ confirmRecordEncoding(EORSR_SID, data46199, ser2);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExtendedFormatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExtendedFormatRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExtendedFormatRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExtendedFormatRecord.java Sat May 22 20:56:44 2021
@@ -24,42 +24,42 @@ import org.junit.jupiter.api.Test;
final class TestExtendedFormatRecord {
- private static final byte[] data = {
- 0, 0, // Font 0
- 0, 0, // Format 0
- 0xF5 - 256, 0xFF - 256, // Cell opts ...
- 0x20, 0, // Alignment 20
- 0, 0, // Ident 0
- 0, 0, // Border 0
- 0, 0, // Palette 0
- 0, 0, 0, 0, // ADTL Palette 0
- 0xC0 - 256, 0x20 // Fill Palette 20c0
- };
-
- private static ExtendedFormatRecord createEFR() {
- return new ExtendedFormatRecord(TestcaseRecordInputStream.create(0x00E0, data));
- }
-
- @Test
- void testLoad() {
- ExtendedFormatRecord record = createEFR();
- assertEquals(0, record.getFontIndex());
- assertEquals(0, record.getFormatIndex());
- assertEquals(0xF5 - 256, record.getCellOptions());
- assertEquals(0x20, record.getAlignmentOptions());
- assertEquals(0, record.getIndentionOptions());
- assertEquals(0, record.getBorderOptions());
- assertEquals(0, record.getPaletteOptions());
- assertEquals(0, record.getAdtlPaletteOptions());
- assertEquals(0x20c0, record.getFillPaletteOptions());
-
- assertEquals(20 + 4, record.getRecordSize());
- }
-
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testStore() {
+ private static final byte[] data = {
+ 0, 0, // Font 0
+ 0, 0, // Format 0
+ 0xF5 - 256, 0xFF - 256, // Cell opts ...
+ 0x20, 0, // Alignment 20
+ 0, 0, // Ident 0
+ 0, 0, // Border 0
+ 0, 0, // Palette 0
+ 0, 0, 0, 0, // ADTL Palette 0
+ 0xC0 - 256, 0x20 // Fill Palette 20c0
+ };
+
+ private static ExtendedFormatRecord createEFR() {
+ return new ExtendedFormatRecord(TestcaseRecordInputStream.create(0x00E0, data));
+ }
+
+ @Test
+ void testLoad() {
+ ExtendedFormatRecord record = createEFR();
+ assertEquals(0, record.getFontIndex());
+ assertEquals(0, record.getFormatIndex());
+ assertEquals(0xF5 - 256, record.getCellOptions());
+ assertEquals(0x20, record.getAlignmentOptions());
+ assertEquals(0, record.getIndentionOptions());
+ assertEquals(0, record.getBorderOptions());
+ assertEquals(0, record.getPaletteOptions());
+ assertEquals(0, record.getAdtlPaletteOptions());
+ assertEquals(0x20c0, record.getFillPaletteOptions());
+
+ assertEquals(20 + 4, record.getRecordSize());
+ }
+
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testStore() {
// .fontindex = 0
// .formatindex = 0
// .celloptions = fffffff5
@@ -103,40 +103,40 @@ final class TestExtendedFormatRecord {
// .foreground= 40
// .background= 41
- ExtendedFormatRecord record = new ExtendedFormatRecord();
- record.setFontIndex((short) 0);
- record.setFormatIndex((short) 0);
+ ExtendedFormatRecord record = new ExtendedFormatRecord();
+ record.setFontIndex((short) 0);
+ record.setFormatIndex((short) 0);
- record.setLocked(true);
- record.setHidden(false);
- record.setXFType((short) 1);
- record.setParentIndex((short) 0xfff);
+ record.setLocked(true);
+ record.setHidden(false);
+ record.setXFType((short) 1);
+ record.setParentIndex((short) 0xfff);
- record.setVerticalAlignment((short) 2);
+ record.setVerticalAlignment((short) 2);
- record.setFillForeground((short) 0x40);
- record.setFillBackground((short) 0x41);
+ record.setFillForeground((short) 0x40);
+ record.setFillBackground((short) 0x41);
- byte[] recordBytes = record.serialize();
- confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes);
- }
+ byte[] recordBytes = record.serialize();
+ confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes);
+ }
- @SuppressWarnings("squid:S2699")
- @Test
- void testCloneOnto() {
- ExtendedFormatRecord base = createEFR();
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testCloneOnto() {
+ ExtendedFormatRecord base = createEFR();
- ExtendedFormatRecord other = new ExtendedFormatRecord();
- other.cloneStyleFrom(base);
+ ExtendedFormatRecord other = new ExtendedFormatRecord();
+ other.cloneStyleFrom(base);
- byte[] recordBytes = other.serialize();
- confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes);
- }
+ byte[] recordBytes = other.serialize();
+ confirmRecordEncoding(ExtendedFormatRecord.sid, data, recordBytes);
+ }
- @Test
- void testRotation() {
+ @Test
+ void testRotation() {
ExtendedFormatRecord record = createEFR();
assertEquals(0, record.getRotation());
@@ -158,5 +158,5 @@ final class TestExtendedFormatRecord {
record.setRotation((short)-90);
assertEquals(-76, 90-record.getRotation());
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExternalNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExternalNameRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExternalNameRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestExternalNameRecord.java Sat May 22 20:56:44 2021
@@ -30,119 +30,119 @@ import org.junit.jupiter.api.Test;
final class TestExternalNameRecord {
- private static final byte[] dataFDS = {
- 0, 0, 0, 0, 0, 0, 3, 0, 70, 68, 83, 0, 0,
- };
-
- // data taken from bugzilla 44774 att 21790
- private static final byte[] dataAutoDocName = {
- -22, 127, 0, 0, 0, 0, 29, 0, 39, 49, 57, 49, 50, 49, 57, 65, 87, 52, 32, 67, 111, 114,
- 112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39,
- };
-
- // data taken from bugzilla 44774 att 21790
- private static final byte[] dataPlainName = {
- 0, 0, 0, 0, 0, 0, 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101, 9, 0, 58, 0, 0, 0, 0, 4, 0, 8, 0
- // TODO - the last 2 bytes of formula data (8,0) seem weird. They encode to ConcatPtg, UnknownPtg
- // UnknownPtg is otherwise not created by any other test cases
- };
-
- private static ExternalNameRecord createSimpleENR(byte[] data) {
- return new ExternalNameRecord(TestcaseRecordInputStream.create(0x0023, data));
- }
-
- @Test
- void testBasicDeserializeReserialize() {
-
- ExternalNameRecord enr = createSimpleENR(dataFDS);
- assertEquals("FDS", enr.getText());
-
- // bug 44695
- confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
- }
-
- @Test
- void testBasicSize() {
- ExternalNameRecord enr = createSimpleENR(dataFDS);
- assertNotEquals(13, enr.getRecordSize(), "Identified bug 44695");
- assertEquals(17, enr.getRecordSize());
-
- assertNotNull(enr.serialize());
- }
-
- @Test
- void testAutoStdDocName() {
-
- ExternalNameRecord enr = createSimpleENR(dataAutoDocName);
- assertEquals("'191219AW4 Corp,[WORKOUT_PX]'", enr.getText());
- assertTrue(enr.isAutomaticLink());
- assertFalse(enr.isBuiltInName());
- assertFalse(enr.isIconifiedPictureLink());
- assertFalse(enr.isOLELink());
- assertFalse(enr.isPicureLink());
- assertTrue(enr.isStdDocumentNameIdentifier());
-
- confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
- }
-
- @Test
- void testPlainName() {
-
- ExternalNameRecord enr = createSimpleENR(dataPlainName);
- assertEquals("Rate_Date", enr.getText());
- assertFalse(enr.isAutomaticLink());
- assertFalse(enr.isBuiltInName());
- assertFalse(enr.isIconifiedPictureLink());
- assertFalse(enr.isOLELink());
- assertFalse(enr.isPicureLink());
- assertFalse(enr.isStdDocumentNameIdentifier());
-
- confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
- }
-
- @Test
- void testDDELink_bug47229() {
- /*
- * Hex dump read directly from text of bugzilla 47229
- */
- final byte[] dataDDE = HexRead.readFromString(
- "E2 7F 00 00 00 00 " +
- "37 00 " + // text len
- // 010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]
- "30 31 30 36 37 32 41 54 30 20 4D 55 4E 49 2C " +
- "5B 52 54 47 5F 4D 4F 4F 44 59 5F 55 4E 44 45 52 4C 59 49 4E 47 2C " +
- "52 54 47 5F 53 50 5F 55 4E 44 45 52 4C 59 49 4E 47 5D " +
- // constant array { { "#N/A N.A.", "#N/A N.A.", }, }
- " 01 00 00 " +
- "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E " +
- "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E");
-
- // actual msg reported in bugzilla 47229 is different
- // because that seems to be using a version from before svn r646666
- ExternalNameRecord enr = createSimpleENR(dataDDE);
- assertEquals("010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]", enr.getText());
-
- confirmRecordEncoding(0x0023, dataDDE, enr.serialize());
- }
-
- @Test
- void testUnicodeName_bug47384() {
- // data taken from bugzilla 47384 att 23830 at offset 0x13A0
- byte[] dataUN = HexRead.readFromString(
- "23 00 22 00" +
- "00 00 00 00 00 00 " +
- "0C 01 " +
- "59 01 61 00 7A 00 65 00 6E 00 ED 00 5F 00 42 00 69 00 6C 00 6C 00 61 00" +
- "00 00");
-
- RecordInputStream in = TestcaseRecordInputStream.create(dataUN);
- ExternalNameRecord enr = new ExternalNameRecord(in);
- assertEquals("\u0159azen\u00ED_Billa", enr.getText());
+ private static final byte[] dataFDS = {
+ 0, 0, 0, 0, 0, 0, 3, 0, 70, 68, 83, 0, 0,
+ };
+
+ // data taken from bugzilla 44774 att 21790
+ private static final byte[] dataAutoDocName = {
+ -22, 127, 0, 0, 0, 0, 29, 0, 39, 49, 57, 49, 50, 49, 57, 65, 87, 52, 32, 67, 111, 114,
+ 112, 44, 91, 87, 79, 82, 75, 79, 85, 84, 95, 80, 88, 93, 39,
+ };
+
+ // data taken from bugzilla 44774 att 21790
+ private static final byte[] dataPlainName = {
+ 0, 0, 0, 0, 0, 0, 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101, 9, 0, 58, 0, 0, 0, 0, 4, 0, 8, 0
+ // TODO - the last 2 bytes of formula data (8,0) seem weird. They encode to ConcatPtg, UnknownPtg
+ // UnknownPtg is otherwise not created by any other test cases
+ };
+
+ private static ExternalNameRecord createSimpleENR(byte[] data) {
+ return new ExternalNameRecord(TestcaseRecordInputStream.create(0x0023, data));
+ }
+
+ @Test
+ void testBasicDeserializeReserialize() {
+
+ ExternalNameRecord enr = createSimpleENR(dataFDS);
+ assertEquals("FDS", enr.getText());
+
+ // bug 44695
+ confirmRecordEncoding(0x0023, dataFDS, enr.serialize());
+ }
+
+ @Test
+ void testBasicSize() {
+ ExternalNameRecord enr = createSimpleENR(dataFDS);
+ assertNotEquals(13, enr.getRecordSize(), "Identified bug 44695");
+ assertEquals(17, enr.getRecordSize());
+
+ assertNotNull(enr.serialize());
+ }
+
+ @Test
+ void testAutoStdDocName() {
+
+ ExternalNameRecord enr = createSimpleENR(dataAutoDocName);
+ assertEquals("'191219AW4 Corp,[WORKOUT_PX]'", enr.getText());
+ assertTrue(enr.isAutomaticLink());
+ assertFalse(enr.isBuiltInName());
+ assertFalse(enr.isIconifiedPictureLink());
+ assertFalse(enr.isOLELink());
+ assertFalse(enr.isPicureLink());
+ assertTrue(enr.isStdDocumentNameIdentifier());
+
+ confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
+ }
+
+ @Test
+ void testPlainName() {
+
+ ExternalNameRecord enr = createSimpleENR(dataPlainName);
+ assertEquals("Rate_Date", enr.getText());
+ assertFalse(enr.isAutomaticLink());
+ assertFalse(enr.isBuiltInName());
+ assertFalse(enr.isIconifiedPictureLink());
+ assertFalse(enr.isOLELink());
+ assertFalse(enr.isPicureLink());
+ assertFalse(enr.isStdDocumentNameIdentifier());
+
+ confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
+ }
+
+ @Test
+ void testDDELink_bug47229() {
+ /*
+ * Hex dump read directly from text of bugzilla 47229
+ */
+ final byte[] dataDDE = HexRead.readFromString(
+ "E2 7F 00 00 00 00 " +
+ "37 00 " + // text len
+ // 010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]
+ "30 31 30 36 37 32 41 54 30 20 4D 55 4E 49 2C " +
+ "5B 52 54 47 5F 4D 4F 4F 44 59 5F 55 4E 44 45 52 4C 59 49 4E 47 2C " +
+ "52 54 47 5F 53 50 5F 55 4E 44 45 52 4C 59 49 4E 47 5D " +
+ // constant array { { "#N/A N.A.", "#N/A N.A.", }, }
+ " 01 00 00 " +
+ "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E " +
+ "02 09 00 00 23 4E 2F 41 20 4E 2E 41 2E");
+
+ // actual msg reported in bugzilla 47229 is different
+ // because that seems to be using a version from before svn r646666
+ ExternalNameRecord enr = createSimpleENR(dataDDE);
+ assertEquals("010672AT0 MUNI,[RTG_MOODY_UNDERLYING,RTG_SP_UNDERLYING]", enr.getText());
+
+ confirmRecordEncoding(0x0023, dataDDE, enr.serialize());
+ }
+
+ @Test
+ void testUnicodeName_bug47384() {
+ // data taken from bugzilla 47384 att 23830 at offset 0x13A0
+ byte[] dataUN = HexRead.readFromString(
+ "23 00 22 00" +
+ "00 00 00 00 00 00 " +
+ "0C 01 " +
+ "59 01 61 00 7A 00 65 00 6E 00 ED 00 5F 00 42 00 69 00 6C 00 6C 00 61 00" +
+ "00 00");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(dataUN);
+ ExternalNameRecord enr = new ExternalNameRecord(in);
+ assertEquals("\u0159azen\u00ED_Billa", enr.getText());
byte[] ser = enr.serialize();
assertEquals(HexDump.toHex(dataUN), HexDump.toHex(ser));
- }
+ }
- @Test
+ @Test
void test48339() {
// data taken from bugzilla 48339
byte[] data = HexRead.readFromString(
@@ -155,18 +155,18 @@ final class TestExternalNameRecord {
assertEquals(HexDump.toHex(data), HexDump.toHex(ser));
}
- @Test
+ @Test
void testNPEWithFileFrom49219() {
// the file at test-data/spreadsheet/49219.xls has ExternalNameRecords without actual data,
- // we did handle this during reading, but failed during serializing this out, ensure it works now
+ // we did handle this during reading, but failed during serializing this out, ensure it works now
byte[] data = new byte[] {
- 2, 127, 0, 0, 0, 0,
- 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101};
+ 2, 127, 0, 0, 0, 0,
+ 9, 0, 82, 97, 116, 101, 95, 68, 97, 116, 101};
- ExternalNameRecord enr = createSimpleENR(data);
+ ExternalNameRecord enr = createSimpleENR(data);
byte[] ser = enr.serialize();
assertEquals("[23, 00, 11, 00, 02, 7F, 00, 00, 00, 00, 09, 00, 52, 61, 74, 65, 5F, 44, 61, 74, 65]",
- HexDump.toHex(ser));
+ HexDump.toHex(ser));
}
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFeatRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFeatRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFeatRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFeatRecord.java Sat May 22 20:56:44 2021
@@ -38,161 +38,161 @@ import org.junit.jupiter.api.Test;
* Tests for {@code FeatRecord}
*/
final class TestFeatRecord {
- @Test
- void testWithoutFeatRecord() throws Exception {
- HSSFWorkbook hssf =
- HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
- InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
-
- assertEquals(1, hssf.getNumberOfSheets());
-
- int countFR = 0;
- int countFRH = 0;
-
- // Check on the workbook, but shouldn't be there!
- for(org.apache.poi.hssf.record.Record r : wb.getRecords()) {
- if(r instanceof FeatRecord) {
- countFR++;
- } else if (r.getSid() == FeatRecord.sid) {
- countFR++;
- }
- if(r instanceof FeatHdrRecord) {
- countFRH++;
- } else if (r.getSid() == FeatHdrRecord.sid) {
- countFRH++;
- }
- }
-
- assertEquals(0, countFR);
- assertEquals(0, countFRH);
-
- // Now check on the sheet
- HSSFSheet s = hssf.getSheetAt(0);
- InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
-
- for(RecordBase rb : sheet.getRecords()) {
- if(rb instanceof Record) {
- Record r = (org.apache.poi.hssf.record.Record)rb;
- if(r instanceof FeatRecord) {
- countFR++;
- } else if (r.getSid() == FeatRecord.sid) {
- countFR++;
- }
- if(r instanceof FeatHdrRecord) {
- countFRH++;
- } else if (r.getSid() == FeatHdrRecord.sid) {
- countFRH++;
- }
- }
- }
-
- assertEquals(0, countFR);
- assertEquals(0, countFRH);
- }
-
- @Test
- void testReadFeatRecord() {
- HSSFWorkbook hssf =
- HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
- InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
-
- FeatRecord fr = null;
- FeatHdrRecord fhr = null;
-
- assertEquals(1, hssf.getNumberOfSheets());
-
- // First check it isn't on the Workbook
- int countFR = 0;
- int countFRH = 0;
- for(org.apache.poi.hssf.record.Record r : wb.getRecords()) {
- if(r instanceof FeatRecord) {
- fr = (FeatRecord)r;
- countFR++;
- } else if (r.getSid() == FeatRecord.sid) {
- fail("FeatRecord SID found but not created correctly!");
- }
- if(r instanceof FeatHdrRecord) {
- countFRH++;
- } else if (r.getSid() == FeatHdrRecord.sid) {
- fail("FeatHdrRecord SID found but not created correctly!");
- }
- }
-
- assertEquals(0, countFR);
- assertEquals(0, countFRH);
-
- // Now find it on our sheet
- HSSFSheet s = hssf.getSheetAt(0);
- InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
-
- for(RecordBase rb : sheet.getRecords()) {
- if(rb instanceof Record) {
- Record r = (org.apache.poi.hssf.record.Record)rb;
- if(r instanceof FeatRecord) {
- fr = (FeatRecord)r;
- countFR++;
- } else if (r.getSid() == FeatRecord.sid) {
- countFR++;
- }
- if(r instanceof FeatHdrRecord) {
- fhr = (FeatHdrRecord)r;
- countFRH++;
- } else if (r.getSid() == FeatHdrRecord.sid) {
- countFRH++;
- }
- }
- }
-
- assertEquals(1, countFR);
- assertEquals(1, countFRH);
- assertNotNull(fr);
- assertNotNull(fhr);
-
- // Now check the contents are as expected
- assertEquals(
- FeatHdrRecord.SHAREDFEATURES_ISFFEC2,
- fr.getIsf_sharedFeatureType()
- );
-
- // Applies to one cell only
- assertEquals(1, fr.getCellRefs().length);
- assertEquals(0, fr.getCellRefs()[0].getFirstRow());
- assertEquals(0, fr.getCellRefs()[0].getLastRow());
- assertEquals(0, fr.getCellRefs()[0].getFirstColumn());
- assertEquals(0, fr.getCellRefs()[0].getLastColumn());
-
- // More checking of shared features stuff
- assertEquals(4, fr.getCbFeatData());
- assertEquals(4, fr.getSharedFeature().getDataSize());
- assertEquals(FeatFormulaErr2.class, fr.getSharedFeature().getClass());
-
- FeatFormulaErr2 fferr2 = (FeatFormulaErr2)fr.getSharedFeature();
- assertEquals(0x04, fferr2._getRawErrorCheckValue());
-
- assertFalse(fferr2.getCheckCalculationErrors());
- assertFalse(fferr2.getCheckDateTimeFormats());
- assertFalse(fferr2.getCheckEmptyCellRef());
- assertFalse(fferr2.getCheckInconsistentFormulas());
- assertFalse(fferr2.getCheckInconsistentRanges());
- assertTrue(fferr2.getCheckNumbersAsText());
- assertFalse(fferr2.getCheckUnprotectedFormulas());
- assertFalse(fferr2.getPerformDataValidation());
- }
+ @Test
+ void testWithoutFeatRecord() throws Exception {
+ HSSFWorkbook hssf =
+ HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls");
+ InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
+
+ assertEquals(1, hssf.getNumberOfSheets());
+
+ int countFR = 0;
+ int countFRH = 0;
+
+ // Check on the workbook, but shouldn't be there!
+ for(org.apache.poi.hssf.record.Record r : wb.getRecords()) {
+ if(r instanceof FeatRecord) {
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ countFR++;
+ }
+ if(r instanceof FeatHdrRecord) {
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ countFRH++;
+ }
+ }
+
+ assertEquals(0, countFR);
+ assertEquals(0, countFRH);
+
+ // Now check on the sheet
+ HSSFSheet s = hssf.getSheetAt(0);
+ InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
+
+ for(RecordBase rb : sheet.getRecords()) {
+ if(rb instanceof Record) {
+ Record r = (org.apache.poi.hssf.record.Record)rb;
+ if(r instanceof FeatRecord) {
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ countFR++;
+ }
+ if(r instanceof FeatHdrRecord) {
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ countFRH++;
+ }
+ }
+ }
+
+ assertEquals(0, countFR);
+ assertEquals(0, countFRH);
+ }
+
+ @Test
+ void testReadFeatRecord() {
+ HSSFWorkbook hssf =
+ HSSFTestDataSamples.openSampleWorkbook("46136-NoWarnings.xls");
+ InternalWorkbook wb = HSSFTestHelper.getWorkbookForTest(hssf);
+
+ FeatRecord fr = null;
+ FeatHdrRecord fhr = null;
+
+ assertEquals(1, hssf.getNumberOfSheets());
+
+ // First check it isn't on the Workbook
+ int countFR = 0;
+ int countFRH = 0;
+ for(org.apache.poi.hssf.record.Record r : wb.getRecords()) {
+ if(r instanceof FeatRecord) {
+ fr = (FeatRecord)r;
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ fail("FeatRecord SID found but not created correctly!");
+ }
+ if(r instanceof FeatHdrRecord) {
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ fail("FeatHdrRecord SID found but not created correctly!");
+ }
+ }
+
+ assertEquals(0, countFR);
+ assertEquals(0, countFRH);
+
+ // Now find it on our sheet
+ HSSFSheet s = hssf.getSheetAt(0);
+ InternalSheet sheet = HSSFTestHelper.getSheetForTest(s);
+
+ for(RecordBase rb : sheet.getRecords()) {
+ if(rb instanceof Record) {
+ Record r = (org.apache.poi.hssf.record.Record)rb;
+ if(r instanceof FeatRecord) {
+ fr = (FeatRecord)r;
+ countFR++;
+ } else if (r.getSid() == FeatRecord.sid) {
+ countFR++;
+ }
+ if(r instanceof FeatHdrRecord) {
+ fhr = (FeatHdrRecord)r;
+ countFRH++;
+ } else if (r.getSid() == FeatHdrRecord.sid) {
+ countFRH++;
+ }
+ }
+ }
+
+ assertEquals(1, countFR);
+ assertEquals(1, countFRH);
+ assertNotNull(fr);
+ assertNotNull(fhr);
+
+ // Now check the contents are as expected
+ assertEquals(
+ FeatHdrRecord.SHAREDFEATURES_ISFFEC2,
+ fr.getIsf_sharedFeatureType()
+ );
+
+ // Applies to one cell only
+ assertEquals(1, fr.getCellRefs().length);
+ assertEquals(0, fr.getCellRefs()[0].getFirstRow());
+ assertEquals(0, fr.getCellRefs()[0].getLastRow());
+ assertEquals(0, fr.getCellRefs()[0].getFirstColumn());
+ assertEquals(0, fr.getCellRefs()[0].getLastColumn());
+
+ // More checking of shared features stuff
+ assertEquals(4, fr.getCbFeatData());
+ assertEquals(4, fr.getSharedFeature().getDataSize());
+ assertEquals(FeatFormulaErr2.class, fr.getSharedFeature().getClass());
+
+ FeatFormulaErr2 fferr2 = (FeatFormulaErr2)fr.getSharedFeature();
+ assertEquals(0x04, fferr2._getRawErrorCheckValue());
+
+ assertFalse(fferr2.getCheckCalculationErrors());
+ assertFalse(fferr2.getCheckDateTimeFormats());
+ assertFalse(fferr2.getCheckEmptyCellRef());
+ assertFalse(fferr2.getCheckInconsistentFormulas());
+ assertFalse(fferr2.getCheckInconsistentRanges());
+ assertTrue(fferr2.getCheckNumbersAsText());
+ assertFalse(fferr2.getCheckUnprotectedFormulas());
+ assertFalse(fferr2.getPerformDataValidation());
+ }
/**
* cloning sheets with feat records
*/
- @Test
+ @Test
void testCloneSheetWithFeatRecord() throws IOException {
try (HSSFWorkbook wb =
HSSFTestDataSamples.openSampleWorkbook("46136-WithWarnings.xls")) {
- HSSFSheet src = wb.getSheetAt(0);
- HSSFSheet dst = wb.cloneSheet(0);
+ HSSFSheet src = wb.getSheetAt(0);
+ HSSFSheet dst = wb.cloneSheet(0);
- InternalSheet isrc = HSSFTestHelper.getSheetForTest(src);
- InternalSheet idst = HSSFTestHelper.getSheetForTest(dst);
+ InternalSheet isrc = HSSFTestHelper.getSheetForTest(src);
+ InternalSheet idst = HSSFTestHelper.getSheetForTest(dst);
- assertEquals(isrc.getRecords().size(), idst.getRecords().size());
- }
+ assertEquals(isrc.getRecords().size(), idst.getRecords().size());
+ }
}
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestFormulaRecord.java Sat May 22 20:56:44 2021
@@ -35,166 +35,166 @@ import org.junit.jupiter.api.Test;
*/
final class TestFormulaRecord {
- @Test
- void testCreateFormulaRecord () {
- FormulaRecord record = new FormulaRecord();
- record.setColumn((short)0);
- record.setRow(1);
- record.setXFIndex((short)4);
-
- assertEquals(record.getColumn(),0);
- assertEquals(record.getRow(), 1);
- assertEquals(record.getXFIndex(),4);
- }
-
- /**
- * Make sure a NAN value is preserved
- * This formula record is a representation of =1/0 at row 0, column 0
- */
- @Test
- void testCheckNanPreserve() {
- byte[] formulaByte = {
- 0, 0, 0, 0,
- 0x0F, 0x00,
-
- // 8 bytes cached number is a 'special value' in this case
- 0x02, // special cached value type 'error'
- 0x00,
- FormulaError.DIV0.getCode(),
- 0x00,
- 0x00,
- 0x00,
- (byte)0xFF,
- (byte)0xFF,
-
- 0x00,
- 0x00,
- 0x00,
- 0x00,
-
- (byte)0xE0, //18
- (byte)0xFC,
- // Ptgs
- 0x07, 0x00, // encoded length
- 0x1E, 0x01, 0x00, // IntPtg(1)
- 0x1E, 0x00, 0x00, // IntPtg(0)
- 0x06, // DividePtg
-
- };
-
- FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
- assertEquals(0, record.getRow(), "Row");
- assertEquals(0, record.getColumn(), "Column");
- //noinspection deprecation
- assertEquals(CellType.ERROR.getCode(), record.getCachedResultType());
- assertEquals(CellType.ERROR, record.getCachedResultTypeEnum());
-
- byte[] output = record.serialize();
- // includes sid+recordlength
- assertEquals(33, output.length, "Output size");
-
- for (int i = 5; i < 13;i++) {
- assertEquals(formulaByte[i], output[i+4], "FormulaByte NaN doesn't match");
- }
- }
-
- /**
- * Tests to see if the shared formula cells properly reserialize the expPtg
- */
- @Test
- void testExpFormula() {
- byte[] formulaByte = new byte[27];
-
- formulaByte[4] =(byte)0x0F;
- formulaByte[14]=(byte)0x08;
- formulaByte[18]=(byte)0xE0;
- formulaByte[19]=(byte)0xFD;
- formulaByte[20]=(byte)0x05;
- formulaByte[22]=(byte)0x01;
- FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
- assertEquals(0, record.getRow(), "Row");
- assertEquals(0, record.getColumn(), "Column");
- byte[] output = record.serialize();
- // includes sid+recordlength
- assertEquals(31, output.length, "Output size");
- assertEquals(1, output[26], "Offset 22");
- }
-
- @Test
- void testWithConcat() {
- // =CHOOSE(2,A2,A3,A4)
- byte[] data = {
- 1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
- 64, 0, 0, 12, 0, 12, -4, 46, 0,
- 30, 2, 0, // Int - 2
- 25, 4, 3, 0, // Attr
- 8, 0, 17, 0, 26, 0, // jumpTable
- 35, 0, // chooseOffset
- 36, 1, 0, 0, -64, // Ref - A2
- 25, 8, 21, 0, // Attr
- 36, 2, 0, 0, -64, // Ref - A3
- 25, 8, 12, 0, // Attr
- 36, 3, 0, 0, -64, // Ref - A4
- 25, 8, 3, 0, // Attr
- 66, 4, 100, 0 // CHOOSE
- };
- RecordInputStream inp = TestcaseRecordInputStream.create(FormatRecord.sid, data);
-
- FormulaRecord fr = new FormulaRecord(inp);
-
- Ptg[] ptgs = fr.getParsedExpression();
- assertEquals(9, ptgs.length);
- assertEquals(IntPtg.class, ptgs[0].getClass());
- assertEquals(AttrPtg.class, ptgs[1].getClass());
- assertEquals(RefPtg.class, ptgs[2].getClass());
- assertEquals(AttrPtg.class, ptgs[3].getClass());
- assertEquals(RefPtg.class, ptgs[4].getClass());
- assertEquals(AttrPtg.class, ptgs[5].getClass());
- assertEquals(RefPtg.class, ptgs[6].getClass());
- assertEquals(AttrPtg.class, ptgs[7].getClass());
- assertEquals(FuncVarPtg.class, ptgs[8].getClass());
-
- FuncVarPtg choose = (FuncVarPtg)ptgs[8];
- assertEquals("CHOOSE", choose.getName());
- }
-
- @Test
- void testReserialize() {
- FormulaRecord formulaRecord = new FormulaRecord();
- formulaRecord.setRow(1);
- formulaRecord.setColumn((short) 1);
- formulaRecord.setParsedExpression(new Ptg[] { new RefPtg("B$5"), });
- formulaRecord.setValue(3.3);
- byte[] ser = formulaRecord.serialize();
- assertEquals(31, ser.length);
-
- RecordInputStream in = TestcaseRecordInputStream.create(ser);
- FormulaRecord fr2 = new FormulaRecord(in);
- assertEquals(3.3, fr2.getValue(), 0.0);
- Ptg[] ptgs = fr2.getParsedExpression();
- assertEquals(1, ptgs.length);
- RefPtg rp = (RefPtg) ptgs[0];
- assertEquals("B$5", rp.toFormulaString());
- }
-
- /**
- * Bug noticed while fixing 46479. Operands of conditional operator ( ? : ) were swapped
- * inside {@link FormulaRecord}
- */
- @Test
- void testCachedValue_bug46479() {
- FormulaRecord fr0 = new FormulaRecord();
- FormulaRecord fr1 = new FormulaRecord();
- // test some other cached value types
- fr0.setValue(3.5);
- assertEquals(3.5, fr0.getValue(), 0.0);
- fr0.setCachedResultErrorCode(FormulaError.REF.getCode());
- assertEquals(FormulaError.REF.getCode(), fr0.getCachedErrorValue());
-
- fr0.setCachedResultBoolean(false);
- fr1.setCachedResultBoolean(true);
- assertFalse(fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue(), "Identified bug 46479c");
+ @Test
+ void testCreateFormulaRecord () {
+ FormulaRecord record = new FormulaRecord();
+ record.setColumn((short)0);
+ record.setRow(1);
+ record.setXFIndex((short)4);
+
+ assertEquals(record.getColumn(),0);
+ assertEquals(record.getRow(), 1);
+ assertEquals(record.getXFIndex(),4);
+ }
+
+ /**
+ * Make sure a NAN value is preserved
+ * This formula record is a representation of =1/0 at row 0, column 0
+ */
+ @Test
+ void testCheckNanPreserve() {
+ byte[] formulaByte = {
+ 0, 0, 0, 0,
+ 0x0F, 0x00,
+
+ // 8 bytes cached number is a 'special value' in this case
+ 0x02, // special cached value type 'error'
+ 0x00,
+ FormulaError.DIV0.getCode(),
+ 0x00,
+ 0x00,
+ 0x00,
+ (byte)0xFF,
+ (byte)0xFF,
+
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+
+ (byte)0xE0, //18
+ (byte)0xFC,
+ // Ptgs
+ 0x07, 0x00, // encoded length
+ 0x1E, 0x01, 0x00, // IntPtg(1)
+ 0x1E, 0x00, 0x00, // IntPtg(0)
+ 0x06, // DividePtg
+
+ };
+
+ FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
+ assertEquals(0, record.getRow(), "Row");
+ assertEquals(0, record.getColumn(), "Column");
+ //noinspection deprecation
+ assertEquals(CellType.ERROR.getCode(), record.getCachedResultType());
+ assertEquals(CellType.ERROR, record.getCachedResultTypeEnum());
+
+ byte[] output = record.serialize();
+ // includes sid+recordlength
+ assertEquals(33, output.length, "Output size");
+
+ for (int i = 5; i < 13;i++) {
+ assertEquals(formulaByte[i], output[i+4], "FormulaByte NaN doesn't match");
+ }
+ }
+
+ /**
+ * Tests to see if the shared formula cells properly reserialize the expPtg
+ */
+ @Test
+ void testExpFormula() {
+ byte[] formulaByte = new byte[27];
+
+ formulaByte[4] =(byte)0x0F;
+ formulaByte[14]=(byte)0x08;
+ formulaByte[18]=(byte)0xE0;
+ formulaByte[19]=(byte)0xFD;
+ formulaByte[20]=(byte)0x05;
+ formulaByte[22]=(byte)0x01;
+ FormulaRecord record = new FormulaRecord(TestcaseRecordInputStream.create(FormulaRecord.sid, formulaByte));
+ assertEquals(0, record.getRow(), "Row");
+ assertEquals(0, record.getColumn(), "Column");
+ byte[] output = record.serialize();
+ // includes sid+recordlength
+ assertEquals(31, output.length, "Output size");
+ assertEquals(1, output[26], "Offset 22");
+ }
+
+ @Test
+ void testWithConcat() {
+ // =CHOOSE(2,A2,A3,A4)
+ byte[] data = {
+ 1, 0, 1, 0, 15, 0, 0, 0, 0, 0, 0, 0, 57,
+ 64, 0, 0, 12, 0, 12, -4, 46, 0,
+ 30, 2, 0, // Int - 2
+ 25, 4, 3, 0, // Attr
+ 8, 0, 17, 0, 26, 0, // jumpTable
+ 35, 0, // chooseOffset
+ 36, 1, 0, 0, -64, // Ref - A2
+ 25, 8, 21, 0, // Attr
+ 36, 2, 0, 0, -64, // Ref - A3
+ 25, 8, 12, 0, // Attr
+ 36, 3, 0, 0, -64, // Ref - A4
+ 25, 8, 3, 0, // Attr
+ 66, 4, 100, 0 // CHOOSE
+ };
+ RecordInputStream inp = TestcaseRecordInputStream.create(FormatRecord.sid, data);
+
+ FormulaRecord fr = new FormulaRecord(inp);
+
+ Ptg[] ptgs = fr.getParsedExpression();
+ assertEquals(9, ptgs.length);
+ assertEquals(IntPtg.class, ptgs[0].getClass());
+ assertEquals(AttrPtg.class, ptgs[1].getClass());
+ assertEquals(RefPtg.class, ptgs[2].getClass());
+ assertEquals(AttrPtg.class, ptgs[3].getClass());
+ assertEquals(RefPtg.class, ptgs[4].getClass());
+ assertEquals(AttrPtg.class, ptgs[5].getClass());
+ assertEquals(RefPtg.class, ptgs[6].getClass());
+ assertEquals(AttrPtg.class, ptgs[7].getClass());
+ assertEquals(FuncVarPtg.class, ptgs[8].getClass());
+
+ FuncVarPtg choose = (FuncVarPtg)ptgs[8];
+ assertEquals("CHOOSE", choose.getName());
+ }
+
+ @Test
+ void testReserialize() {
+ FormulaRecord formulaRecord = new FormulaRecord();
+ formulaRecord.setRow(1);
+ formulaRecord.setColumn((short) 1);
+ formulaRecord.setParsedExpression(new Ptg[] { new RefPtg("B$5"), });
+ formulaRecord.setValue(3.3);
+ byte[] ser = formulaRecord.serialize();
+ assertEquals(31, ser.length);
+
+ RecordInputStream in = TestcaseRecordInputStream.create(ser);
+ FormulaRecord fr2 = new FormulaRecord(in);
+ assertEquals(3.3, fr2.getValue(), 0.0);
+ Ptg[] ptgs = fr2.getParsedExpression();
+ assertEquals(1, ptgs.length);
+ RefPtg rp = (RefPtg) ptgs[0];
+ assertEquals("B$5", rp.toFormulaString());
+ }
+
+ /**
+ * Bug noticed while fixing 46479. Operands of conditional operator ( ? : ) were swapped
+ * inside {@link FormulaRecord}
+ */
+ @Test
+ void testCachedValue_bug46479() {
+ FormulaRecord fr0 = new FormulaRecord();
+ FormulaRecord fr1 = new FormulaRecord();
+ // test some other cached value types
+ fr0.setValue(3.5);
+ assertEquals(3.5, fr0.getValue(), 0.0);
+ fr0.setCachedResultErrorCode(FormulaError.REF.getCode());
+ assertEquals(FormulaError.REF.getCode(), fr0.getCachedErrorValue());
+
+ fr0.setCachedResultBoolean(false);
+ fr1.setCachedResultBoolean(true);
+ assertFalse(fr0.getCachedBooleanValue() && !fr1.getCachedBooleanValue(), "Identified bug 46479c");
assertFalse(fr0.getCachedBooleanValue());
assertTrue(fr1.getCachedBooleanValue());
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestHyperlinkRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestHyperlinkRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestHyperlinkRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestHyperlinkRecord.java Sat May 22 20:56:44 2021
@@ -183,7 +183,7 @@ final class TestHyperlinkRecord {
0x00, 0x41, 0x00, 0x31, 0x00, 0x00, 0x00
};
- private static final byte[] dataLinkToWorkbook = HexRead.readFromString(
+ 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 " +
@@ -214,7 +214,7 @@ final class TestHyperlinkRecord {
"36 00 00 00"
);
- private static final byte[] dataTargetFrame = HexRead.readFromString(
+ 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 " +
@@ -239,25 +239,25 @@ final class TestHyperlinkRecord {
);
- private static final byte[] dataUNC = HexRead.readFromString(
+ 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"
- );
+ "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"
+ );
/**
@@ -279,8 +279,8 @@ final class TestHyperlinkRecord {
private void confirmGUID(ClassID expectedGuid, ClassID actualGuid) {
- assertEquals(expectedGuid, actualGuid);
- }
+ assertEquals(expectedGuid, actualGuid);
+ }
@Test
void testReadURLLink(){
@@ -454,74 +454,74 @@ final class TestHyperlinkRecord {
@SuppressWarnings("squid:S2699")
@Test
void testReserializeTargetFrame() {
- RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataTargetFrame);
- HyperlinkRecord hr = new HyperlinkRecord(in);
- byte[] ser = hr.serialize();
- confirmRecordEncoding(HyperlinkRecord.sid, dataTargetFrame, ser);
- }
-
- @Test
- void testReserializeLinkToWorkbook() {
-
- RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataLinkToWorkbook);
- HyperlinkRecord hr = new HyperlinkRecord(in);
- byte[] ser = hr.serialize();
- confirmRecordEncoding(HyperlinkRecord.sid, dataLinkToWorkbook, ser);
- assertNotEquals("Identified bug in reading workbook link", "YEARFR~1.XLS", hr.getAddress());
- assertEquals("yearfracExamples.xls", hr.getAddress());
- }
+ RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataTargetFrame);
+ HyperlinkRecord hr = new HyperlinkRecord(in);
+ byte[] ser = hr.serialize();
+ confirmRecordEncoding(HyperlinkRecord.sid, dataTargetFrame, ser);
+ }
+
+ @Test
+ void testReserializeLinkToWorkbook() {
+
+ RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataLinkToWorkbook);
+ HyperlinkRecord hr = new HyperlinkRecord(in);
+ byte[] ser = hr.serialize();
+ confirmRecordEncoding(HyperlinkRecord.sid, dataLinkToWorkbook, ser);
+ assertNotEquals("Identified bug in reading workbook link", "YEARFR~1.XLS", hr.getAddress());
+ assertEquals("yearfracExamples.xls", hr.getAddress());
+ }
@Test
void testReserializeUNC() {
- RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataUNC);
- HyperlinkRecord hr = new HyperlinkRecord(in);
- byte[] ser = hr.serialize();
- confirmRecordEncoding(HyperlinkRecord.sid, dataUNC, ser);
+ RecordInputStream in = TestcaseRecordInputStream.create(HyperlinkRecord.sid, dataUNC);
+ HyperlinkRecord hr = new HyperlinkRecord(in);
+ byte[] ser = hr.serialize();
+ confirmRecordEncoding(HyperlinkRecord.sid, dataUNC, ser);
assertNotNull(hr.toString());
- }
+ }
@Test
- void testGUID() throws IOException {
- ClassID g;
- g = new ClassID("3F2504E0-4F89-11D3-9A0C-0305E82C3301");
- confirmGUID(g, 0x3F2504E0, 0x4F89, 0x11D3, 0x9A0C0305E82C3301L);
- assertEquals("{3F2504E0-4F89-11D3-9A0C-0305E82C3301}", g.toString());
-
- g = new ClassID("13579BDF-0246-8ACE-0123-456789ABCDEF");
- confirmGUID(g, 0x13579BDF, 0x0246, 0x8ACE, 0x0123456789ABCDEFL);
- assertEquals("{13579BDF-0246-8ACE-0123-456789ABCDEF}", g.toString());
-
- byte[] buf = new byte[16];
- g.write(new LittleEndianByteArrayOutputStream(buf, 0));
- String expectedDump = "[DF, 9B, 57, 13, 46, 02, CE, 8A, 01, 23, 45, 67, 89, AB, CD, EF]";
- assertEquals(expectedDump, HexDump.toHex(buf));
-
- // STD Moniker
- g = createFromStreamDump("[D0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
- assertEquals("{79EAC9D0-BAF9-11CE-8C82-00AA004BA90B}", g.toString());
- // URL Moniker
- g = createFromStreamDump("[E0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
- assertEquals("{79EAC9E0-BAF9-11CE-8C82-00AA004BA90B}", g.toString());
- // File Moniker
- g = createFromStreamDump("[03, 03, 00, 00, 00, 00, 00, 00, C0, 00, 00, 00, 00, 00, 00, 46]");
- assertEquals("{00000303-0000-0000-C000-000000000046}", g.toString());
- }
-
- private static ClassID createFromStreamDump(String s) {
- return new ClassID(new LittleEndianByteArrayInputStream(HexRead.readFromString(s)));
- }
+ void testGUID() throws IOException {
+ ClassID g;
+ g = new ClassID("3F2504E0-4F89-11D3-9A0C-0305E82C3301");
+ confirmGUID(g, 0x3F2504E0, 0x4F89, 0x11D3, 0x9A0C0305E82C3301L);
+ assertEquals("{3F2504E0-4F89-11D3-9A0C-0305E82C3301}", g.toString());
+
+ g = new ClassID("13579BDF-0246-8ACE-0123-456789ABCDEF");
+ confirmGUID(g, 0x13579BDF, 0x0246, 0x8ACE, 0x0123456789ABCDEFL);
+ assertEquals("{13579BDF-0246-8ACE-0123-456789ABCDEF}", g.toString());
+
+ byte[] buf = new byte[16];
+ g.write(new LittleEndianByteArrayOutputStream(buf, 0));
+ String expectedDump = "[DF, 9B, 57, 13, 46, 02, CE, 8A, 01, 23, 45, 67, 89, AB, CD, EF]";
+ assertEquals(expectedDump, HexDump.toHex(buf));
+
+ // STD Moniker
+ g = createFromStreamDump("[D0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
+ assertEquals("{79EAC9D0-BAF9-11CE-8C82-00AA004BA90B}", g.toString());
+ // URL Moniker
+ g = createFromStreamDump("[E0, C9, EA, 79, F9, BA, CE, 11, 8C, 82, 00, AA, 00, 4B, A9, 0B]");
+ assertEquals("{79EAC9E0-BAF9-11CE-8C82-00AA004BA90B}", g.toString());
+ // File Moniker
+ g = createFromStreamDump("[03, 03, 00, 00, 00, 00, 00, 00, C0, 00, 00, 00, 00, 00, 00, 46]");
+ assertEquals("{00000303-0000-0000-C000-000000000046}", g.toString());
+ }
- private void confirmGUID(ClassID g, int d1, int d2, int d3, long d4) throws IOException {
+ private static ClassID createFromStreamDump(String s) {
+ return new ClassID(new LittleEndianByteArrayInputStream(HexRead.readFromString(s)));
+ }
+
+ private void confirmGUID(ClassID g, int d1, int d2, int d3, long d4) throws IOException {
try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(g.getBytes()))) {
assertEquals(d1, dis.readInt());
assertEquals(d2, dis.readShort() & 0xFFFF);
assertEquals(d3, dis.readShort() & 0xFFFF);
assertEquals(d4, dis.readLong());
}
- }
+ }
- @Test
+ @Test
void test47498(){
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data_47498);
HyperlinkRecord link = new HyperlinkRecord(is);
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestLabelRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestLabelRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestLabelRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestLabelRecord.java Sat May 22 20:56:44 2021
@@ -31,17 +31,17 @@ import org.junit.jupiter.api.Test;
*/
final class TestLabelRecord {
- @Test
- void testEmptyString() throws IOException {
- try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("ex42570-20305.xls");
- HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
- HSSFSheet s1 = wb1.getSheetAt(0);
- HSSFSheet s2 = wb2.getSheetAt(0);
- for (int c=0; c<2; c++) {
- for (int r=0; r<146; r++) {
- assertEquals(s1.getRow(r).getCell(c).getNumericCellValue(), s2.getRow(r).getCell(c).getNumericCellValue(), 0);
- }
- }
- }
- }
+ @Test
+ void testEmptyString() throws IOException {
+ try (HSSFWorkbook wb1 = HSSFTestDataSamples.openSampleWorkbook("ex42570-20305.xls");
+ HSSFWorkbook wb2 = HSSFTestDataSamples.writeOutAndReadBack(wb1)) {
+ HSSFSheet s1 = wb1.getSheetAt(0);
+ HSSFSheet s2 = wb2.getSheetAt(0);
+ for (int c=0; c<2; c++) {
+ for (int r=0; r<146; r++) {
+ assertEquals(s1.getRow(r).getCell(c).getNumericCellValue(), s2.getRow(r).getCell(c).getNumericCellValue(), 0);
+ }
+ }
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestMergeCellsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestMergeCellsRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestMergeCellsRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestMergeCellsRecord.java Sat May 22 20:56:44 2021
@@ -34,40 +34,40 @@ import org.junit.jupiter.api.Test;
*/
final class TestMergeCellsRecord {
- /**
- * Make sure when a clone is called, we actually clone it.
- */
- @Test
- void testCloneReferences() {
- CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
- MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
- MergeCellsRecord clone = merge.copy();
+ /**
+ * Make sure when a clone is called, we actually clone it.
+ */
+ @Test
+ void testCloneReferences() {
+ CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
+ MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
+ MergeCellsRecord clone = merge.copy();
- assertNotSame(merge, clone, "Merged and cloned objects are the same");
+ assertNotSame(merge, clone, "Merged and cloned objects are the same");
- CellRangeAddress mergeRegion = merge.getAreaAt(0);
- CellRangeAddress cloneRegion = clone.getAreaAt(0);
- assertNotSame(mergeRegion, cloneRegion, "Should not point to same objects when cloning");
- assertEquals(mergeRegion.getFirstRow(), cloneRegion.getFirstRow(), "New Clone Row From doesnt match");
- assertEquals(mergeRegion.getLastRow(), cloneRegion.getLastRow(), "New Clone Row To doesnt match");
- assertEquals(mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn(), "New Clone Col From doesnt match");
- assertEquals(mergeRegion.getLastColumn(), cloneRegion.getLastColumn(), "New Clone Col To doesnt match");
+ CellRangeAddress mergeRegion = merge.getAreaAt(0);
+ CellRangeAddress cloneRegion = clone.getAreaAt(0);
+ assertNotSame(mergeRegion, cloneRegion, "Should not point to same objects when cloning");
+ assertEquals(mergeRegion.getFirstRow(), cloneRegion.getFirstRow(), "New Clone Row From doesnt match");
+ assertEquals(mergeRegion.getLastRow(), cloneRegion.getLastRow(), "New Clone Row To doesnt match");
+ assertEquals(mergeRegion.getFirstColumn(), cloneRegion.getFirstColumn(), "New Clone Col From doesnt match");
+ assertEquals(mergeRegion.getLastColumn(), cloneRegion.getLastColumn(), "New Clone Col To doesnt match");
assertNotSame(merge.getAreaAt(0), clone.getAreaAt(0));
- }
+ }
- @Test
- void testMCTable_bug46009() {
- MergedCellsTable mct = new MergedCellsTable();
- CellRangeAddress[] cras = { new CellRangeAddress(0, 0, 0, 3) };
- MergeCellsRecord mcr1 = new MergeCellsRecord(cras, 0, 1);
- RecordStream rs = new RecordStream(Collections.singletonList(mcr1), 0);
- mct.read(rs);
- mct.visitContainedRecords(r -> {
- assertTrue(r instanceof MergeCellsRecord);
- MergeCellsRecord mcr2 = (MergeCellsRecord)r;
- assertEquals(mcr1.getNumAreas(), mcr2.getNumAreas());
- assertEquals(mcr1.getAreaAt(0), mcr2.getAreaAt(0));
- });
- }
+ @Test
+ void testMCTable_bug46009() {
+ MergedCellsTable mct = new MergedCellsTable();
+ CellRangeAddress[] cras = { new CellRangeAddress(0, 0, 0, 3) };
+ MergeCellsRecord mcr1 = new MergeCellsRecord(cras, 0, 1);
+ RecordStream rs = new RecordStream(Collections.singletonList(mcr1), 0);
+ mct.read(rs);
+ mct.visitContainedRecords(r -> {
+ assertTrue(r instanceof MergeCellsRecord);
+ MergeCellsRecord mcr2 = (MergeCellsRecord)r;
+ assertEquals(mcr1.getNumAreas(), mcr2.getNumAreas());
+ assertEquals(mcr1.getAreaAt(0), mcr2.getAreaAt(0));
+ });
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameCommentRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameCommentRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameCommentRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameCommentRecord.java Sat May 22 20:56:44 2021
@@ -27,17 +27,17 @@ import org.junit.jupiter.api.Test;
* Tests the NameCommentRecord serializes/deserializes correctly
*/
final class TestNameCommentRecord {
- @Test
- void testReserialize() {
- final byte[] data = HexRead
- .readFromString(""
- + "94 08 00 00 00 00 00 00 00 00 00 00 04 00 07 00 00 6E 61 6D 65 00 63 6F 6D 6D 65 6E 74]");
- final RecordInputStream in = TestcaseRecordInputStream.create(NameCommentRecord.sid, data);
- final NameCommentRecord ncr = new NameCommentRecord(in);
- assertEquals(0x0894, ncr.getRecordType());
- assertEquals("name", ncr.getNameText());
- assertEquals("comment", ncr.getCommentText());
- final byte[] data2 = ncr.serialize();
- confirmRecordEncoding(NameCommentRecord.sid, data, data2);
- }
+ @Test
+ void testReserialize() {
+ final byte[] data = HexRead
+ .readFromString(""
+ + "94 08 00 00 00 00 00 00 00 00 00 00 04 00 07 00 00 6E 61 6D 65 00 63 6F 6D 6D 65 6E 74]");
+ final RecordInputStream in = TestcaseRecordInputStream.create(NameCommentRecord.sid, data);
+ final NameCommentRecord ncr = new NameCommentRecord(in);
+ assertEquals(0x0894, ncr.getRecordType());
+ assertEquals("name", ncr.getNameText());
+ assertEquals("comment", ncr.getCommentText());
+ final byte[] data2 = ncr.serialize();
+ confirmRecordEncoding(NameCommentRecord.sid, data, data2);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestNameRecord.java Sat May 22 20:56:44 2021
@@ -41,78 +41,78 @@ import org.junit.jupiter.api.Test;
*/
final class TestNameRecord {
- /**
- * Makes sure that additional name information is parsed properly such as menu/description
- */
- @Test
- void testFillExtras() {
-
- byte[] examples = HexRead.readFromString(""
- + "88 03 67 06 07 00 00 00 00 00 00 23 00 00 00 4D "
- + "61 63 72 6F 31 3A 01 00 00 00 11 00 00 4D 61 63 "
- + "72 6F 20 72 65 63 6F 72 64 65 64 20 32 37 2D 53 "
- + "65 70 2D 39 33 20 62 79 20 41 4C 4C 57 4F 52");
-
- NameRecord name = new NameRecord(TestcaseRecordInputStream.create(NameRecord.sid, examples));
- String description = name.getDescriptionText();
- assertNotNull(description);
- assertTrue(description.endsWith("Macro recorded 27-Sep-93 by ALLWOR"));
- }
-
- @Test
- void testReserialize() {
- byte[] data = HexRead
- .readFromString(""
- + "20 00 00 01 0B 00 00 00 01 00 00 00 00 00 00 06 3B 00 00 00 00 02 00 00 00 09 00]");
- RecordInputStream in = TestcaseRecordInputStream.create(NameRecord.sid, data);
- NameRecord nr = new NameRecord(in);
- assertEquals(0x0020, nr.getOptionFlag());
- byte[] data2 = nr.serialize();
- confirmRecordEncoding(NameRecord.sid, data, data2);
- }
-
- @Test
- void testFormulaRelAbs_bug46174() throws IOException {
- // perhaps this testcase belongs on TestHSSFName
- try (HSSFWorkbook wb = new HSSFWorkbook()) {
- HSSFName name = wb.createName();
- wb.createSheet("Sheet1");
- name.setNameName("test");
- name.setRefersToFormula("Sheet1!$B$3");
- assertNotEquals("Sheet1!B3", name.getRefersToFormula());
- assertEquals("Sheet1!$B$3", name.getRefersToFormula());
- }
- }
-
- @Test
- void testFormulaGeneral() throws IOException {
- // perhaps this testcase belongs on TestHSSFName
- HSSFWorkbook wb = new HSSFWorkbook();
- HSSFName name = wb.createName();
- wb.createSheet("Sheet1");
- name.setNameName("test");
- name.setRefersToFormula("Sheet1!A1+Sheet1!A2");
- assertEquals("Sheet1!A1+Sheet1!A2", name.getRefersToFormula());
- name.setRefersToFormula("5*6");
- assertEquals("5*6", name.getRefersToFormula());
+ /**
+ * Makes sure that additional name information is parsed properly such as menu/description
+ */
+ @Test
+ void testFillExtras() {
+
+ byte[] examples = HexRead.readFromString(""
+ + "88 03 67 06 07 00 00 00 00 00 00 23 00 00 00 4D "
+ + "61 63 72 6F 31 3A 01 00 00 00 11 00 00 4D 61 63 "
+ + "72 6F 20 72 65 63 6F 72 64 65 64 20 32 37 2D 53 "
+ + "65 70 2D 39 33 20 62 79 20 41 4C 4C 57 4F 52");
+
+ NameRecord name = new NameRecord(TestcaseRecordInputStream.create(NameRecord.sid, examples));
+ String description = name.getDescriptionText();
+ assertNotNull(description);
+ assertTrue(description.endsWith("Macro recorded 27-Sep-93 by ALLWOR"));
+ }
+
+ @Test
+ void testReserialize() {
+ byte[] data = HexRead
+ .readFromString(""
+ + "20 00 00 01 0B 00 00 00 01 00 00 00 00 00 00 06 3B 00 00 00 00 02 00 00 00 09 00]");
+ RecordInputStream in = TestcaseRecordInputStream.create(NameRecord.sid, data);
+ NameRecord nr = new NameRecord(in);
+ assertEquals(0x0020, nr.getOptionFlag());
+ byte[] data2 = nr.serialize();
+ confirmRecordEncoding(NameRecord.sid, data, data2);
+ }
+
+ @Test
+ void testFormulaRelAbs_bug46174() throws IOException {
+ // perhaps this testcase belongs on TestHSSFName
+ try (HSSFWorkbook wb = new HSSFWorkbook()) {
+ HSSFName name = wb.createName();
+ wb.createSheet("Sheet1");
+ name.setNameName("test");
+ name.setRefersToFormula("Sheet1!$B$3");
+ assertNotEquals("Sheet1!B3", name.getRefersToFormula());
+ assertEquals("Sheet1!$B$3", name.getRefersToFormula());
+ }
+ }
- wb.close();
- }
+ @Test
+ void testFormulaGeneral() throws IOException {
+ // perhaps this testcase belongs on TestHSSFName
+ HSSFWorkbook wb = new HSSFWorkbook();
+ HSSFName name = wb.createName();
+ wb.createSheet("Sheet1");
+ name.setNameName("test");
+ name.setRefersToFormula("Sheet1!A1+Sheet1!A2");
+ assertEquals("Sheet1!A1+Sheet1!A2", name.getRefersToFormula());
+ name.setRefersToFormula("5*6");
+ assertEquals("5*6", name.getRefersToFormula());
+
+ wb.close();
+ }
/**
* A NameRecord followed by a ContinueRecord. See Bugzilla 50244
*/
- @Test
+ @Test
void test50244() throws IOException {
byte[] data1 = RawDataUtil.decompress(
- "H4sIAAAAAAAAAI3Zu2qWQRAA0I8EQcHGzkrwBcLO7B0sBR9AwdYIKdKFoPhovp7xLyQWyX+m2OWw7TIX5u3x/t1xHG9ePhyXxyl+" +
- "fbz+cf3p/ufd3c3nm/vbm6tvx++L18fXy4fr4tVxxNWXLFelhCENlRCIZuiERAzDJFTEMmxCM/RiCMJApKESJqIZOmEhhmESNmIZ" +
- "tiCKIYohCIlIQyVURDN0QkMMwyR0xDJswjDMYoizGH9Lzib8+6NnEIREpKESKqIZOqEhhmESOmIZNmEUQje0bViEipiGQUhENzRC" +
- "IKohCQURZ3FKT0kYiDAUQjc87iCfwyJUxDQMQiK6oRECUQ1JKIgwFEHZhrUNizAR0zAIA9ENjdAR1ZCEhghDIVRDbsMiBGIaBqEg" +
- "uqEZpmEZNiEMWQxBqIg0VEJDNEMndMQwTMJALMMmTMMqhiBsRBqqIAqiGTohEMMwCYlYhk2ohlYMQeiINFTCQDRDP4vT/FMNzdAJ" +
- "gRiGSUjEMmxCNbRiCEJHpKEahqEbGqEhqiEJFRGGQkhDbMMiFMQ0jLM4padlmIZB6IhuaIT2Pz4c3188+VoNSaiIMBRCGh7PGc9h" +
- "EQpiGoagbEQ3NMJCVEMSJiIMhTAMjxdcz2ERGmIaBqEiuqERElENSQhEGMrT+APX2vm3iyMAAA=="
- );
+ "H4sIAAAAAAAAAI3Zu2qWQRAA0I8EQcHGzkrwBcLO7B0sBR9AwdYIKdKFoPhovp7xLyQWyX+m2OWw7TIX5u3x/t1xHG9ePhyXxyl+" +
+ "fbz+cf3p/ufd3c3nm/vbm6tvx++L18fXy4fr4tVxxNWXLFelhCENlRCIZuiERAzDJFTEMmxCM/RiCMJApKESJqIZOmEhhmESNmIZ" +
+ "tiCKIYohCIlIQyVURDN0QkMMwyR0xDJswjDMYoizGH9Lzib8+6NnEIREpKESKqIZOqEhhmESOmIZNmEUQje0bViEipiGQUhENzRC" +
+ "IKohCQURZ3FKT0kYiDAUQjc87iCfwyJUxDQMQiK6oRECUQ1JKIgwFEHZhrUNizAR0zAIA9ENjdAR1ZCEhghDIVRDbsMiBGIaBqEg" +
+ "uqEZpmEZNiEMWQxBqIg0VEJDNEMndMQwTMJALMMmTMMqhiBsRBqqIAqiGTohEMMwCYlYhk2ohlYMQeiINFTCQDRDP4vT/FMNzdAJ" +
+ "gRiGSUjEMmxCNbRiCEJHpKEahqEbGqEhqiEJFRGGQkhDbMMiFMQ0jLM4padlmIZB6IhuaIT2Pz4c3188+VoNSaiIMBRCGh7PGc9h" +
+ "EQpiGoagbEQ3NMJCVEMSJiIMhTAMjxdcz2ERGmIaBqEiuqERElENSQhEGMrT+APX2vm3iyMAAA=="
+ );
RecordInputStream in1 = TestcaseRecordInputStream.create(data1);
NameRecord nr1 = new NameRecord(in1);
@@ -138,7 +138,7 @@ final class TestNameRecord {
assertEquals("1.T20.010", vals[vals.length - 1][0]);
}
- @Test
+ @Test
void testBug57923() {
NameRecord record = new NameRecord();
assertEquals(0, record.getExternSheetNumber());
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestRecalcIdRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestRecalcIdRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestRecalcIdRecord.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/record/TestRecalcIdRecord.java Sat May 22 20:56:44 2021
@@ -26,43 +26,43 @@ import org.junit.jupiter.api.Test;
final class TestRecalcIdRecord {
- private static RecalcIdRecord create(byte[] data) {
- RecordInputStream in = TestcaseRecordInputStream.create(RecalcIdRecord.sid, data);
- RecalcIdRecord result = new RecalcIdRecord(in);
- assertEquals(0, in.remaining());
- return result;
- }
-
- @SuppressWarnings("squid:S2699")
- @Test
- void testBasicDeserializeReserialize() {
-
- byte[] data = HexRead.readFromString(
- "C1 01" + // rt
- "00 00" + // reserved
- "1D EB 01 00"); // engine id
-
- RecalcIdRecord r = create(data);
- confirmRecordEncoding(RecalcIdRecord.sid, data, r.serialize());
- }
-
- @Test
- void testBadFirstField_bug48096() {
- /*
- * Data taken from the sample file referenced in Bugzilla 48096, file offset 0x0D45.
- * The apparent problem is that the first data short field has been written with the
- * wrong <i>endianness</n>. Excel seems to ignore whatever value is present in this
- * field, and always rewrites it as (C1, 01). POI now does the same.
- */
- byte[] badData = HexRead.readFromString("C1 01 08 00 01 C1 00 00 00 01 69 61");
- byte[] goodData = HexRead.readFromString("C1 01 08 00 C1 01 00 00 00 01 69 61");
-
- RecordInputStream in = TestcaseRecordInputStream.create(badData);
-
- // bug 48096 - expected 449 but got 49409
- RecalcIdRecord r = new RecalcIdRecord(in);
-
- assertEquals(0, in.remaining());
- assertArrayEquals(r.serialize(), goodData);
- }
+ private static RecalcIdRecord create(byte[] data) {
+ RecordInputStream in = TestcaseRecordInputStream.create(RecalcIdRecord.sid, data);
+ RecalcIdRecord result = new RecalcIdRecord(in);
+ assertEquals(0, in.remaining());
+ return result;
+ }
+
+ @SuppressWarnings("squid:S2699")
+ @Test
+ void testBasicDeserializeReserialize() {
+
+ byte[] data = HexRead.readFromString(
+ "C1 01" + // rt
+ "00 00" + // reserved
+ "1D EB 01 00"); // engine id
+
+ RecalcIdRecord r = create(data);
+ confirmRecordEncoding(RecalcIdRecord.sid, data, r.serialize());
+ }
+
+ @Test
+ void testBadFirstField_bug48096() {
+ /*
+ * Data taken from the sample file referenced in Bugzilla 48096, file offset 0x0D45.
+ * The apparent problem is that the first data short field has been written with the
+ * wrong <i>endianness</n>. Excel seems to ignore whatever value is present in this
+ * field, and always rewrites it as (C1, 01). POI now does the same.
+ */
+ byte[] badData = HexRead.readFromString("C1 01 08 00 01 C1 00 00 00 01 69 61");
+ byte[] goodData = HexRead.readFromString("C1 01 08 00 C1 01 00 00 00 01 69 61");
+
+ RecordInputStream in = TestcaseRecordInputStream.create(badData);
+
+ // bug 48096 - expected 449 but got 49409
+ RecalcIdRecord r = new RecalcIdRecord(in);
+
+ assertEquals(0, in.remaining());
+ assertArrayEquals(r.serialize(), goodData);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org