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 [35/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/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Sat May 22 20:56:44 2021
@@ -477,15 +477,15 @@ public final class TestHSSFWorkbook exte
//
}
@Override
- public short getSid() {
+ public short getSid() {
return 0x777;
}
@Override
- public int serialize(int offset, byte[] data) {
+ public int serialize(int offset, byte[] data) {
return 4;
}
@Override
- public int getRecordSize() {
+ public int getRecordSize() {
return 8;
}
@Override
@@ -876,142 +876,142 @@ public final class TestHSSFWorkbook exte
}
@Test
- void bug50298() throws Exception {
- HSSFWorkbook wb = openSampleWorkbook("50298.xls");
+ void bug50298() throws Exception {
+ HSSFWorkbook wb = openSampleWorkbook("50298.xls");
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- HSSFSheet sheet = wb.cloneSheet(0);
+ HSSFSheet sheet = wb.cloneSheet(0);
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice (2)");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice (2)");
- wb.setSheetName(wb.getSheetIndex(sheet), "copy");
+ wb.setSheetName(wb.getSheetIndex(sheet), "copy");
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
- wb.setSheetOrder("copy", 0);
+ wb.setSheetOrder("copy", 0);
- assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- wb.removeSheetAt(0);
+ wb.removeSheetAt(0);
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- // check that the overall workbook serializes with its correct size
- int expected = wb.getWorkbook().getSize();
- int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
+ // check that the overall workbook serializes with its correct size
+ int expected = wb.getWorkbook().getSize();
+ int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
- assertEquals(expected, written, "Did not have the expected size when writing the workbook");
+ assertEquals(expected, written, "Did not have the expected size when writing the workbook");
- HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
- assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- read.close();
- wb.close();
- }
+ HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertSheetOrder(read, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ read.close();
+ wb.close();
+ }
@Test
- void bug50298a() throws Exception {
- HSSFWorkbook wb = openSampleWorkbook("50298.xls");
+ void bug50298a() throws Exception {
+ HSSFWorkbook wb = openSampleWorkbook("50298.xls");
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- HSSFSheet sheet = wb.cloneSheet(0);
+ HSSFSheet sheet = wb.cloneSheet(0);
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice (2)");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "Invoice (2)");
- wb.setSheetName(wb.getSheetIndex(sheet), "copy");
+ wb.setSheetName(wb.getSheetIndex(sheet), "copy");
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received", "copy");
- wb.setSheetOrder("copy", 0);
+ wb.setSheetOrder("copy", 0);
- assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "copy", "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- wb.removeSheetAt(0);
+ wb.removeSheetAt(0);
- assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "Invoice", "Invoice1", "Digest", "Deferred", "Received");
- wb.removeSheetAt(1);
+ wb.removeSheetAt(1);
- assertSheetOrder(wb, "Invoice", "Digest", "Deferred", "Received");
+ assertSheetOrder(wb, "Invoice", "Digest", "Deferred", "Received");
- wb.setSheetOrder("Digest", 3);
+ wb.setSheetOrder("Digest", 3);
- assertSheetOrder(wb, "Invoice", "Deferred", "Received", "Digest");
+ assertSheetOrder(wb, "Invoice", "Deferred", "Received", "Digest");
- // check that the overall workbook serializes with its correct size
- int expected = wb.getWorkbook().getSize();
- int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
+ // check that the overall workbook serializes with its correct size
+ int expected = wb.getWorkbook().getSize();
+ int written = wb.getWorkbook().serialize(0, new byte[expected*2]);
- assertEquals(expected, written, "Did not have the expected size when writing the workbook");
+ assertEquals(expected, written, "Did not have the expected size when writing the workbook");
- HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
- assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
- read.close();
- wb.close();
- }
+ HSSFWorkbook read = HSSFTestDataSamples.writeOutAndReadBack(wb);
+ assertSheetOrder(read, "Invoice", "Deferred", "Received", "Digest");
+ read.close();
+ wb.close();
+ }
@Test
- void bug54500() throws Exception {
- String nameName = "AName";
- String sheetName = "ASheet";
- HSSFWorkbook wb = openSampleWorkbook("54500.xls");
+ void bug54500() throws Exception {
+ String nameName = "AName";
+ String sheetName = "ASheet";
+ HSSFWorkbook wb = openSampleWorkbook("54500.xls");
- assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3");
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3");
- wb.createSheet(sheetName);
+ wb.createSheet(sheetName);
- assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
- Name n = wb.createName();
- n.setNameName(nameName);
- n.setSheetIndex(3);
- n.setRefersToFormula(sheetName + "!A1");
+ Name n = wb.createName();
+ n.setNameName(nameName);
+ n.setSheetIndex(3);
+ n.setRefersToFormula(sheetName + "!A1");
- assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
final HSSFName name = wb.getName(nameName);
assertNotNull(name);
assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
- wb.write(stream);
+ UnsynchronizedByteArrayOutputStream stream = new UnsynchronizedByteArrayOutputStream();
+ wb.write(stream);
- assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
- assertEquals("ASheet!A1", name.getRefersToFormula());
+ assertSheetOrder(wb, "Sheet1", "Sheet2", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", name.getRefersToFormula());
- wb.removeSheetAt(1);
+ wb.removeSheetAt(1);
- assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
- assertEquals("ASheet!A1", name.getRefersToFormula());
+ assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", name.getRefersToFormula());
- UnsynchronizedByteArrayOutputStream stream2 = new UnsynchronizedByteArrayOutputStream();
- wb.write(stream2);
+ UnsynchronizedByteArrayOutputStream stream2 = new UnsynchronizedByteArrayOutputStream();
+ wb.write(stream2);
- assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
- assertEquals("ASheet!A1", name.getRefersToFormula());
+ assertSheetOrder(wb, "Sheet1", "Sheet3", "ASheet");
+ assertEquals("ASheet!A1", name.getRefersToFormula());
- HSSFWorkbook wb2 = new HSSFWorkbook(stream.toInputStream());
- expectName(wb2, nameName, "ASheet!A1");
- HSSFWorkbook wb3 = new HSSFWorkbook(stream2.toInputStream());
- expectName(wb3, nameName, "ASheet!A1");
- wb3.close();
- wb2.close();
- wb.close();
- }
+ HSSFWorkbook wb2 = new HSSFWorkbook(stream.toInputStream());
+ expectName(wb2, nameName, "ASheet!A1");
+ HSSFWorkbook wb3 = new HSSFWorkbook(stream2.toInputStream());
+ expectName(wb3, nameName, "ASheet!A1");
+ wb3.close();
+ wb2.close();
+ wb.close();
+ }
- @SuppressWarnings("SameParameterValue")
+ @SuppressWarnings("SameParameterValue")
private void expectName(HSSFWorkbook wb, String name, String expect) {
final HSSFName hssfName = wb.getName(name);
assertNotNull(hssfName);
assertEquals(expect, hssfName.getRefersToFormula());
- }
+ }
- @Test
- void test49423() throws Exception
+ @Test
+ void test49423() throws Exception
{
- HSSFWorkbook workbook = openSampleWorkbook("49423.xls");
+ HSSFWorkbook workbook = openSampleWorkbook("49423.xls");
- boolean found = false;
+ boolean found = false;
int numSheets = workbook.getNumberOfSheets();
for (int i = 0; i < numSheets; i++) {
HSSFSheet sheet = workbook.getSheetAt(i);
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java Sat May 22 20:56:44 2021
@@ -34,29 +34,29 @@ import org.junit.jupiter.api.Test;
* the more usual, Workbook)
*/
final class TestNonStandardWorkbookStreamNames {
- private final String xlsA = "WORKBOOK_in_capitals.xls";
+ private final String xlsA = "WORKBOOK_in_capitals.xls";
private final String xlsB = "BOOK_in_capitals.xls";
- /**
- * Test that we can open a file with WORKBOOK
- */
+ /**
+ * Test that we can open a file with WORKBOOK
+ */
@Test
- void testOpenWORKBOOK() throws IOException {
+ void testOpenWORKBOOK() throws IOException {
// Try to open the workbook
- InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
- HSSFWorkbook wb = new HSSFWorkbook(is);
- is.close();
- DirectoryNode root = wb.getDirectory();
-
- // Ensure that we have a WORKBOOK entry and a summary
- assertTrue(root.hasEntry("WORKBOOK"));
- assertTrue(root.hasEntry(SummaryInformation.DEFAULT_STREAM_NAME));
+ InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
+ HSSFWorkbook wb = new HSSFWorkbook(is);
+ is.close();
+ DirectoryNode root = wb.getDirectory();
+
+ // Ensure that we have a WORKBOOK entry and a summary
+ assertTrue(root.hasEntry("WORKBOOK"));
+ assertTrue(root.hasEntry(SummaryInformation.DEFAULT_STREAM_NAME));
- // But not a Workbook one
- assertFalse(root.hasEntry("Workbook"));
+ // But not a Workbook one
+ assertFalse(root.hasEntry("Workbook"));
- wb.close();
- }
+ wb.close();
+ }
/**
* Test that we can open a file with BOOK
@@ -79,15 +79,15 @@ final class TestNonStandardWorkbookStrea
wb.close();
}
- /**
- * Test that when we write out, we go back to the correct case
- */
+ /**
+ * Test that when we write out, we go back to the correct case
+ */
@Test
- void testWrite() throws IOException {
- for (String file : new String[] {xlsA, xlsB}) {
+ void testWrite() throws IOException {
+ for (String file : new String[] {xlsA, xlsB}) {
// Open the workbook, not preserving nodes
- InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
- HSSFWorkbook wb = new HSSFWorkbook(is, false);
+ InputStream is = HSSFTestDataSamples.openSampleFileStream(file);
+ HSSFWorkbook wb = new HSSFWorkbook(is, false);
is.close();
// Check now it can be opened
@@ -103,16 +103,16 @@ final class TestNonStandardWorkbookStrea
wb2.close();
}
- }
+ }
- /**
- * Test that when we write out preserving nodes, we go back to the
- * correct case
- */
+ /**
+ * Test that when we write out preserving nodes, we go back to the
+ * correct case
+ */
@Test
- void testWritePreserve() throws IOException {
+ void testWritePreserve() throws IOException {
// Open the workbook, not preserving nodes
- InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
+ InputStream is = HSSFTestDataSamples.openSampleFileStream(xlsA);
HSSFWorkbook wb = new HSSFWorkbook(is,true);
is.close();
@@ -130,5 +130,5 @@ final class TestNonStandardWorkbookStrea
// As we preserved, should also have a few other streams
assertTrue(root.hasEntry(SummaryInformation.DEFAULT_STREAM_NAME));
wb2.close();
- }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestOLE2Embeding.java Sat May 22 20:56:44 2021
@@ -59,7 +59,7 @@ final class TestOLE2Embeding {
@Test
void testReallyEmbedSomething() throws Exception {
- try (HSSFWorkbook wb1 = new HSSFWorkbook();
+ try (HSSFWorkbook wb1 = new HSSFWorkbook();
POIFSFileSystem pptPoifs = getSamplePPT();
POIFSFileSystem xlsPoifs = getSampleXLS()) {
HSSFSheet sheet = wb1.createSheet();
@@ -126,10 +126,10 @@ final class TestOLE2Embeding {
}
static POIFSFileSystem getSamplePPT() throws IOException {
- // scratchpad classes are not available, so we use something pre-cooked
- InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("with_textbox.ppt");
- POIFSFileSystem poifs = new POIFSFileSystem(is);
- is.close();
+ // scratchpad classes are not available, so we use something pre-cooked
+ InputStream is = POIDataSamples.getSlideShowInstance().openResourceAsStream("with_textbox.ppt");
+ POIFSFileSystem poifs = new POIFSFileSystem(is);
+ is.close();
return poifs;
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestSanityChecker.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestSanityChecker.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestSanityChecker.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestSanityChecker.java Sat May 22 20:56:44 2021
@@ -37,90 +37,90 @@ import org.junit.jupiter.api.Test;
* Okay, this may seem strange but I need to test my test logic.
*/
final class TestSanityChecker {
- private static final Record INTERFACEHDR = new InterfaceHdrRecord(InterfaceHdrRecord.CODEPAGE);
- private static BoundSheetRecord createBoundSheetRec() {
- return new BoundSheetRecord("Sheet1");
- }
-
- @Test
- void testCheckRecordOrder() {
- final SanityChecker c = new SanityChecker();
- List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
- records.add(new BOFRecord());
- records.add(INTERFACEHDR);
- records.add(createBoundSheetRec());
- records.add(EOFRecord.instance);
- CheckRecord[] check = {
- new CheckRecord(BOFRecord.class, '1'),
- new CheckRecord(InterfaceHdrRecord.class, '0'),
- new CheckRecord(BoundSheetRecord.class, 'M'),
- new CheckRecord(NameRecord.class, '*'),
- new CheckRecord(EOFRecord.class, '1'),
- };
- // check pass
- c.checkRecordOrder(records, check);
- records.add(2, createBoundSheetRec());
- c.checkRecordOrder(records, check);
- records.remove(1); // optional record missing
- c.checkRecordOrder(records, check);
- records.add(3, new NameRecord());
- records.add(3, new NameRecord()); // optional multiple record occurs more than one time
- c.checkRecordOrder(records, check);
-
- // check fail
- confirmBadRecordOrder(check, new Record[] {
- new BOFRecord(),
- createBoundSheetRec(),
- INTERFACEHDR,
- EOFRecord.instance,
- });
-
- confirmBadRecordOrder(check, new Record[] {
- new BOFRecord(),
- INTERFACEHDR,
- createBoundSheetRec(),
- INTERFACEHDR,
- EOFRecord.instance,
- });
-
- confirmBadRecordOrder(check, new Record[] {
- new BOFRecord(),
- createBoundSheetRec(),
- new NameRecord(),
- EOFRecord.instance,
- new NameRecord(),
- });
-
- confirmBadRecordOrder(check, new Record[] {
- INTERFACEHDR,
- createBoundSheetRec(),
- EOFRecord.instance,
- });
-
- confirmBadRecordOrder(check, new Record[] {
- new BOFRecord(),
- INTERFACEHDR,
- EOFRecord.instance,
- });
-
- confirmBadRecordOrder(check, new Record[] {
- INTERFACEHDR,
- createBoundSheetRec(),
- new BOFRecord(),
- EOFRecord.instance,
- });
-
- confirmBadRecordOrder(check, new Record[] {
- new BOFRecord(),
- createBoundSheetRec(),
- INTERFACEHDR,
- EOFRecord.instance,
- });
- }
-
- private static void confirmBadRecordOrder(final SanityChecker.CheckRecord[] check, Record[] recs) {
- final SanityChecker c = new SanityChecker();
- final List<org.apache.poi.hssf.record.Record> records = Arrays.asList(recs);
- assertThrows(AssertionError.class, () -> c.checkRecordOrder(records, check));
- }
+ private static final Record INTERFACEHDR = new InterfaceHdrRecord(InterfaceHdrRecord.CODEPAGE);
+ private static BoundSheetRecord createBoundSheetRec() {
+ return new BoundSheetRecord("Sheet1");
+ }
+
+ @Test
+ void testCheckRecordOrder() {
+ final SanityChecker c = new SanityChecker();
+ List<org.apache.poi.hssf.record.Record> records = new ArrayList<>();
+ records.add(new BOFRecord());
+ records.add(INTERFACEHDR);
+ records.add(createBoundSheetRec());
+ records.add(EOFRecord.instance);
+ CheckRecord[] check = {
+ new CheckRecord(BOFRecord.class, '1'),
+ new CheckRecord(InterfaceHdrRecord.class, '0'),
+ new CheckRecord(BoundSheetRecord.class, 'M'),
+ new CheckRecord(NameRecord.class, '*'),
+ new CheckRecord(EOFRecord.class, '1'),
+ };
+ // check pass
+ c.checkRecordOrder(records, check);
+ records.add(2, createBoundSheetRec());
+ c.checkRecordOrder(records, check);
+ records.remove(1); // optional record missing
+ c.checkRecordOrder(records, check);
+ records.add(3, new NameRecord());
+ records.add(3, new NameRecord()); // optional multiple record occurs more than one time
+ c.checkRecordOrder(records, check);
+
+ // check fail
+ confirmBadRecordOrder(check, new Record[] {
+ new BOFRecord(),
+ createBoundSheetRec(),
+ INTERFACEHDR,
+ EOFRecord.instance,
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ new BOFRecord(),
+ INTERFACEHDR,
+ createBoundSheetRec(),
+ INTERFACEHDR,
+ EOFRecord.instance,
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ new BOFRecord(),
+ createBoundSheetRec(),
+ new NameRecord(),
+ EOFRecord.instance,
+ new NameRecord(),
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ INTERFACEHDR,
+ createBoundSheetRec(),
+ EOFRecord.instance,
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ new BOFRecord(),
+ INTERFACEHDR,
+ EOFRecord.instance,
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ INTERFACEHDR,
+ createBoundSheetRec(),
+ new BOFRecord(),
+ EOFRecord.instance,
+ });
+
+ confirmBadRecordOrder(check, new Record[] {
+ new BOFRecord(),
+ createBoundSheetRec(),
+ INTERFACEHDR,
+ EOFRecord.instance,
+ });
+ }
+
+ private static void confirmBadRecordOrder(final SanityChecker.CheckRecord[] check, Record[] recs) {
+ final SanityChecker c = new SanityChecker();
+ final List<org.apache.poi.hssf.record.Record> records = Arrays.asList(recs);
+ assertThrows(AssertionError.class, () -> c.checkRecordOrder(records, check));
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestWorkbook.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestWorkbook.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/usermodel/TestWorkbook.java Sat May 22 20:56:44 2021
@@ -437,8 +437,8 @@ final class TestWorkbook {
@Test
void testBackupRecord() throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
- wb.createSheet();
- InternalWorkbook workbook = wb.getWorkbook();
+ wb.createSheet();
+ InternalWorkbook workbook = wb.getWorkbook();
BackupRecord record = workbook.getBackupRecord();
assertEquals(0, record.getBackup());
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestHSSFColor.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestHSSFColor.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestHSSFColor.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestHSSFColor.java Sat May 22 20:56:44 2021
@@ -28,32 +28,32 @@ import org.junit.jupiter.api.Test;
final class TestHSSFColor {
@Test
void testBasics() {
- assertTrue(HSSFColorPredefined.YELLOW.getIndex() > 0);
- assertTrue(HSSFColorPredefined.YELLOW.getIndex2() > 0);
- }
+ assertTrue(HSSFColorPredefined.YELLOW.getIndex() > 0);
+ assertTrue(HSSFColorPredefined.YELLOW.getIndex2() > 0);
+ }
@Test
- void testContents() {
- short[] triplet = HSSFColorPredefined.YELLOW.getTriplet();
- assertEquals(3, triplet.length);
- assertEquals(255, triplet[0]);
- assertEquals(255, triplet[1]);
- assertEquals(0, triplet[2]);
+ void testContents() {
+ short[] triplet = HSSFColorPredefined.YELLOW.getTriplet();
+ assertEquals(3, triplet.length);
+ assertEquals(255, triplet[0]);
+ assertEquals(255, triplet[1]);
+ assertEquals(0, triplet[2]);
- assertEquals("FFFF:FFFF:0", HSSFColorPredefined.YELLOW.getHexString());
- }
+ assertEquals("FFFF:FFFF:0", HSSFColorPredefined.YELLOW.getHexString());
+ }
@Test
- void testTripletHash() {
- Map<String, HSSFColor> triplets = HSSFColor.getTripletHash();
+ void testTripletHash() {
+ Map<String, HSSFColor> triplets = HSSFColor.getTripletHash();
- assertEquals(
- HSSFColorPredefined.MAROON.getColor(),
- triplets.get(HSSFColorPredefined.MAROON.getHexString())
- );
- assertEquals(
- HSSFColorPredefined.YELLOW.getColor(),
- triplets.get(HSSFColorPredefined.YELLOW.getHexString())
- );
- }
+ assertEquals(
+ HSSFColorPredefined.MAROON.getColor(),
+ triplets.get(HSSFColorPredefined.MAROON.getHexString())
+ );
+ assertEquals(
+ HSSFColorPredefined.YELLOW.getColor(),
+ triplets.get(HSSFColorPredefined.YELLOW.getHexString())
+ );
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestRKUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestRKUtil.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestRKUtil.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/hssf/util/TestRKUtil.java Sat May 22 20:56:44 2021
@@ -26,25 +26,25 @@ import org.junit.jupiter.api.Test;
*/
final class TestRKUtil {
- /**
- * Check we can decode correctly.
- */
- @Test
- void testDecode() {
+ /**
+ * Check we can decode correctly.
+ */
+ @Test
+ void testDecode() {
- int[] values = { 1074266112, 1081384961, 1081397249,
- 0x3FF00000, 0x405EC001, 0x02F1853A, 0x02F1853B, 0xFCDD699A,
- };
- double[] rvalues = { 3.0, 3.3, 3.33,
- 1, 1.23, 12345678, 123456.78, -13149594,
- };
+ int[] values = { 1074266112, 1081384961, 1081397249,
+ 0x3FF00000, 0x405EC001, 0x02F1853A, 0x02F1853B, 0xFCDD699A,
+ };
+ double[] rvalues = { 3.0, 3.3, 3.33,
+ 1, 1.23, 12345678, 123456.78, -13149594,
+ };
- for (int j = 0; j < values.length; j++) {
+ for (int j = 0; j < values.length; j++) {
- int intBits = values[j];
- double expectedValue = rvalues[j];
- double actualValue = RKUtil.decodeNumber(intBits);
- assertEquals(expectedValue, actualValue, 0);
- }
- }
+ int intBits = values[j];
+ double expectedValue = rvalues[j];
+ double actualValue = RKUtil.decodeNumber(intBits);
+ assertEquals(expectedValue, actualValue, 0);
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/poifs/crypt/TestBiff8DecryptingStream.java Sat May 22 20:56:44 2021
@@ -34,64 +34,64 @@ import org.junit.jupiter.api.Test;
*/
final class TestBiff8DecryptingStream {
- /**
- * A mock {@link InputStream} that keeps track of position and also produces
- * slightly interesting data. Each successive data byte value is one greater
- * than the previous.
- */
- private static final class MockStream extends InputStream {
- private final int _initialValue;
- private int _position;
-
- public MockStream(int initialValue) {
- _initialValue = initialValue;
- }
+ /**
+ * A mock {@link InputStream} that keeps track of position and also produces
+ * slightly interesting data. Each successive data byte value is one greater
+ * than the previous.
+ */
+ private static final class MockStream extends InputStream {
+ private final int _initialValue;
+ private int _position;
- @Override
+ public MockStream(int initialValue) {
+ _initialValue = initialValue;
+ }
+
+ @Override
public int read() {
- return (_initialValue+_position++) & 0xFF;
- }
- }
-
- private static final class StreamTester {
- private final Biff8DecryptingStream _bds;
-
- /**
- * @param expectedFirstInt expected value of the first int read from the decrypted stream
- */
- public StreamTester(MockStream ms, String keyDigestHex, int expectedFirstInt) {
- byte[] keyDigest = HexRead.readFromString(keyDigestHex);
- EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
- Decryptor dec = ei.getDecryptor();
- dec.setSecretKey(new SecretKeySpec(keyDigest, "RC4"));
-
- _bds = new Biff8DecryptingStream(ms, 0, ei);
- assertEquals(expectedFirstInt, _bds.readInt());
- }
-
- public Biff8DecryptingStream getBDS() {
- return _bds;
- }
-
- /**
- * Used to 'skip over' the uninteresting middle bits of the key blocks.
- * Also confirms that read position of the underlying stream is aligned.
- */
- void rollForward(int fromPosition, int toPosition) {
- assertEquals(fromPosition, _bds.getPosition());
- for (int i = fromPosition; i < toPosition; i++) {
- _bds.readByte();
- }
- assertEquals(toPosition, _bds.getPosition());
- }
-
- void confirmByte(int expVal) {
- assertEquals(expVal, _bds.readUByte());
- }
-
- void confirmShort(int expVal) {
- assertEquals((short)expVal, _bds.readShort());
- }
+ return (_initialValue+_position++) & 0xFF;
+ }
+ }
+
+ private static final class StreamTester {
+ private final Biff8DecryptingStream _bds;
+
+ /**
+ * @param expectedFirstInt expected value of the first int read from the decrypted stream
+ */
+ public StreamTester(MockStream ms, String keyDigestHex, int expectedFirstInt) {
+ byte[] keyDigest = HexRead.readFromString(keyDigestHex);
+ EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
+ Decryptor dec = ei.getDecryptor();
+ dec.setSecretKey(new SecretKeySpec(keyDigest, "RC4"));
+
+ _bds = new Biff8DecryptingStream(ms, 0, ei);
+ assertEquals(expectedFirstInt, _bds.readInt());
+ }
+
+ public Biff8DecryptingStream getBDS() {
+ return _bds;
+ }
+
+ /**
+ * Used to 'skip over' the uninteresting middle bits of the key blocks.
+ * Also confirms that read position of the underlying stream is aligned.
+ */
+ void rollForward(int fromPosition, int toPosition) {
+ assertEquals(fromPosition, _bds.getPosition());
+ for (int i = fromPosition; i < toPosition; i++) {
+ _bds.readByte();
+ }
+ assertEquals(toPosition, _bds.getPosition());
+ }
+
+ void confirmByte(int expVal) {
+ assertEquals(expVal, _bds.readUByte());
+ }
+
+ void confirmShort(int expVal) {
+ assertEquals((short)expVal, _bds.readShort());
+ }
void confirmUShort(int expVal) {
assertEquals(expVal, _bds.readUShort());
@@ -105,107 +105,107 @@ final class TestBiff8DecryptingStream {
return _bds.readUShort();
}
- void confirmInt(int expVal) {
- assertEquals(expVal, _bds.readInt());
- }
-
- void confirmLong(long expVal) {
- assertEquals(expVal, _bds.readLong());
- }
-
- void confirmData(String expHexData) {
-
- byte[] expData = HexRead.readFromString(expHexData);
- byte[] actData = new byte[expData.length];
- _bds.readFully(actData);
- assertArrayEquals(expData, actData, "Data mismatch");
- }
- }
-
- /**
- * Tests reading of 64,32,16 and 8 bit integers aligned with key changing boundaries
- */
- @Test
- void readsAlignedWithBoundary() {
- StreamTester st = createStreamTester();
-
- st.rollForward(0x0004, 0x03FF);
- st.confirmByte(0x3E);
- st.confirmByte(0x28);
- st.rollForward(0x0401, 0x07FE);
- st.confirmShort(0x76CC);
- st.confirmShort(0xD83E);
- st.rollForward(0x0802, 0x0BFC);
- st.confirmInt(0x25F280EB);
- st.confirmInt(0xB549E99B);
- st.rollForward(0x0C04, 0x0FF8);
- st.confirmLong(0x6AA2D5F6B975D10CL);
- st.confirmLong(0x34248ADF7ED4F029L);
- // check for signed/unsigned shorts #58069
- st.rollForward(0x1008, 0x7213);
- st.confirmUShort(0xFFFF);
- st.rollForward(0x7215, 0x1B9AD);
+ void confirmInt(int expVal) {
+ assertEquals(expVal, _bds.readInt());
+ }
+
+ void confirmLong(long expVal) {
+ assertEquals(expVal, _bds.readLong());
+ }
+
+ void confirmData(String expHexData) {
+
+ byte[] expData = HexRead.readFromString(expHexData);
+ byte[] actData = new byte[expData.length];
+ _bds.readFully(actData);
+ assertArrayEquals(expData, actData, "Data mismatch");
+ }
+ }
+
+ /**
+ * Tests reading of 64,32,16 and 8 bit integers aligned with key changing boundaries
+ */
+ @Test
+ void readsAlignedWithBoundary() {
+ StreamTester st = createStreamTester();
+
+ st.rollForward(0x0004, 0x03FF);
+ st.confirmByte(0x3E);
+ st.confirmByte(0x28);
+ st.rollForward(0x0401, 0x07FE);
+ st.confirmShort(0x76CC);
+ st.confirmShort(0xD83E);
+ st.rollForward(0x0802, 0x0BFC);
+ st.confirmInt(0x25F280EB);
+ st.confirmInt(0xB549E99B);
+ st.rollForward(0x0C04, 0x0FF8);
+ st.confirmLong(0x6AA2D5F6B975D10CL);
+ st.confirmLong(0x34248ADF7ED4F029L);
+ // check for signed/unsigned shorts #58069
+ st.rollForward(0x1008, 0x7213);
+ st.confirmUShort(0xFFFF);
+ st.rollForward(0x7215, 0x1B9AD);
st.confirmShort(-1);
st.rollForward(0x1B9AF, 0x37D99);
assertEquals(0xFFFF, st.readUShort());
st.rollForward(0x37D9B, 0x4A6F2);
assertEquals(-1, st.readShort());
- }
+ }
- /**
- * Tests reading of 64,32 and 16 bit integers <i>across</i> key changing boundaries
- */
+ /**
+ * Tests reading of 64,32 and 16 bit integers <i>across</i> key changing boundaries
+ */
@Test
- void readsSpanningBoundary() {
- StreamTester st = createStreamTester();
+ void readsSpanningBoundary() {
+ StreamTester st = createStreamTester();
- st.rollForward(0x0004, 0x03FC);
- st.confirmLong(0x885243283E2A5EEFL);
- st.rollForward(0x0404, 0x07FE);
- st.confirmInt(0xD83E76CC);
- st.rollForward(0x0802, 0x0BFF);
- st.confirmShort(0x9B25);
- }
-
- /**
- * Checks that the BIFF header fields (sid, size) get read without applying decryption,
- * and that the RC4 stream stays aligned during these calls
- */
+ st.rollForward(0x0004, 0x03FC);
+ st.confirmLong(0x885243283E2A5EEFL);
+ st.rollForward(0x0404, 0x07FE);
+ st.confirmInt(0xD83E76CC);
+ st.rollForward(0x0802, 0x0BFF);
+ st.confirmShort(0x9B25);
+ }
+
+ /**
+ * Checks that the BIFF header fields (sid, size) get read without applying decryption,
+ * and that the RC4 stream stays aligned during these calls
+ */
@Test
- void readHeaderUShort() {
- StreamTester st = createStreamTester();
+ void readHeaderUShort() {
+ StreamTester st = createStreamTester();
- st.rollForward(0x0004, 0x03FF);
+ st.rollForward(0x0004, 0x03FF);
- Biff8DecryptingStream bds = st.getBDS();
- int hval = bds.readDataSize(); // unencrypted
- int nextInt = bds.readInt();
- assertNotEquals(0x8F534029, nextInt, "Indentified bug in key alignment after call to readHeaderUShort()");
- assertEquals(0x16885243, nextInt);
- assertNotEquals(0x283E, hval, "readHeaderUShort() incorrectly decrypted result");
- assertEquals(0x504F, hval);
-
- // confirm next key change
- st.rollForward(0x0405, 0x07FC);
- st.confirmInt(0x76CC1223);
- st.confirmInt(0x4842D83E);
- }
-
- /**
- * Tests reading of byte sequences <i>across</i> and <i>aligned with</i> key changing boundaries
- */
+ Biff8DecryptingStream bds = st.getBDS();
+ int hval = bds.readDataSize(); // unencrypted
+ int nextInt = bds.readInt();
+ assertNotEquals(0x8F534029, nextInt, "Indentified bug in key alignment after call to readHeaderUShort()");
+ assertEquals(0x16885243, nextInt);
+ assertNotEquals(0x283E, hval, "readHeaderUShort() incorrectly decrypted result");
+ assertEquals(0x504F, hval);
+
+ // confirm next key change
+ st.rollForward(0x0405, 0x07FC);
+ st.confirmInt(0x76CC1223);
+ st.confirmInt(0x4842D83E);
+ }
+
+ /**
+ * Tests reading of byte sequences <i>across</i> and <i>aligned with</i> key changing boundaries
+ */
@Test
- void readByteArrays() {
- StreamTester st = createStreamTester();
+ void readByteArrays() {
+ StreamTester st = createStreamTester();
- st.rollForward(0x0004, 0x2FFC);
- st.confirmData("66 A1 20 B1 04 A3 35 F5"); // 4 bytes on either side of boundary
- st.rollForward(0x3004, 0x33F8);
- st.confirmData("F8 97 59 36"); // last 4 bytes in block
- st.confirmData("01 C2 4E 55"); // first 4 bytes in next block
- }
-
- private static StreamTester createStreamTester() {
- return new StreamTester(new MockStream(0x50), "BA AD F0 0D 00", 0x96C66829);
- }
+ st.rollForward(0x0004, 0x2FFC);
+ st.confirmData("66 A1 20 B1 04 A3 35 F5"); // 4 bytes on either side of boundary
+ st.rollForward(0x3004, 0x33F8);
+ st.confirmData("F8 97 59 36"); // last 4 bytes in block
+ st.confirmData("01 C2 4E 55"); // first 4 bytes in next block
+ }
+
+ private static StreamTester createStreamTester() {
+ return new StreamTester(new MockStream(0x50), "BA AD F0 0D 00", 0x96C66829);
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestEmptyDocument.java Sat May 22 20:56:44 2021
@@ -37,80 +37,80 @@ import org.junit.jupiter.params.provider
final class TestEmptyDocument {
private static final Logger LOG = LogManager.getLogger(TestEmptyDocument.class);
- private interface EmptyDoc {
- void handle(DirectoryEntry dir) throws IOException;
- }
+ private interface EmptyDoc {
+ void handle(DirectoryEntry dir) throws IOException;
+ }
public static Stream<Arguments> emptySupplier() {
- return Stream.of(
- Arguments.of("SingleEmptyDocument", (EmptyDoc)TestEmptyDocument::SingleEmptyDocument),
- Arguments.of("SingleEmptyDocumentEvent", (EmptyDoc)TestEmptyDocument::SingleEmptyDocumentEvent),
- Arguments.of("EmptyDocumentWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentWithFriend),
- Arguments.of("EmptyDocumentEventWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentEventWithFriend)
- );
- }
-
- private static void SingleEmptyDocument(DirectoryEntry dir) throws IOException {
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
- }
-
- private static void SingleEmptyDocumentEvent(DirectoryEntry dir) throws IOException {
- dir.createDocument("Foo", 0, event -> LOG.atWarn().log("written"));
- }
-
- private static void EmptyDocumentWithFriend(DirectoryEntry dir) throws IOException {
- dir.createDocument("Bar", new ByteArrayInputStream(new byte[]{0}));
- dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
- }
-
- private static void EmptyDocumentEventWithFriend(DirectoryEntry dir) throws IOException {
- dir.createDocument("Bar", 1, event -> {
- try {
- event.getStream().write(0);
- } catch (IOException exception) {
- throw new RuntimeException("exception on write: " + exception);
- }
- });
- dir.createDocument("Foo", 0, event -> {});
- }
-
-
- @ParameterizedTest(name = "{index} {0}")
- @MethodSource("emptySupplier")
- void testFoo(String testName, EmptyDoc emptyDoc) throws IOException {
- try (POIFSFileSystem fs = new POIFSFileSystem()) {
- DirectoryEntry dir = fs.getRoot();
- emptyDoc.handle(dir);
-
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
- fs.writeFilesystem(out);
- assertDoesNotThrow(() -> new POIFSFileSystem(out.toInputStream()));
- }
- }
+ return Stream.of(
+ Arguments.of("SingleEmptyDocument", (EmptyDoc)TestEmptyDocument::SingleEmptyDocument),
+ Arguments.of("SingleEmptyDocumentEvent", (EmptyDoc)TestEmptyDocument::SingleEmptyDocumentEvent),
+ Arguments.of("EmptyDocumentWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentWithFriend),
+ Arguments.of("EmptyDocumentEventWithFriend", (EmptyDoc)TestEmptyDocument::EmptyDocumentEventWithFriend)
+ );
+ }
+
+ private static void SingleEmptyDocument(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
+ }
+
+ private static void SingleEmptyDocumentEvent(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Foo", 0, event -> LOG.atWarn().log("written"));
+ }
+
+ private static void EmptyDocumentWithFriend(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Bar", new ByteArrayInputStream(new byte[]{0}));
+ dir.createDocument("Foo", new ByteArrayInputStream(new byte[]{}));
+ }
+
+ private static void EmptyDocumentEventWithFriend(DirectoryEntry dir) throws IOException {
+ dir.createDocument("Bar", 1, event -> {
+ try {
+ event.getStream().write(0);
+ } catch (IOException exception) {
+ throw new RuntimeException("exception on write: " + exception);
+ }
+ });
+ dir.createDocument("Foo", 0, event -> {});
+ }
+
+
+ @ParameterizedTest(name = "{index} {0}")
+ @MethodSource("emptySupplier")
+ void testFoo(String testName, EmptyDoc emptyDoc) throws IOException {
+ try (POIFSFileSystem fs = new POIFSFileSystem()) {
+ DirectoryEntry dir = fs.getRoot();
+ emptyDoc.handle(dir);
+
+ UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ fs.writeFilesystem(out);
+ assertDoesNotThrow(() -> new POIFSFileSystem(out.toInputStream()));
+ }
+ }
@Test
- void testEmptyDocumentBug11744() throws Exception {
- byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+ void testEmptyDocumentBug11744() throws Exception {
+ byte[] testData = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
- UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
- try (POIFSFileSystem fs = new POIFSFileSystem()) {
- fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
- fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
- fs.writeFilesystem(out);
- }
-
- // This line caused the error.
- try (POIFSFileSystem fs = new POIFSFileSystem(out.toInputStream())) {
- DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
- assertEquals(0, entry.getSize(), "Expected zero size");
- byte[] actualReadbackData;
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals(0, actualReadbackData.length, "Expected zero read from stream");
-
- entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
- actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
- assertEquals(testData.length, entry.getSize(), "Expected size was wrong");
- assertArrayEquals(testData, actualReadbackData, "Expected same data read from stream");
- }
- }
+ UnsynchronizedByteArrayOutputStream out = new UnsynchronizedByteArrayOutputStream();
+ try (POIFSFileSystem fs = new POIFSFileSystem()) {
+ fs.createDocument(new ByteArrayInputStream(new byte[0]), "Empty");
+ fs.createDocument(new ByteArrayInputStream(testData), "NotEmpty");
+ fs.writeFilesystem(out);
+ }
+
+ // This line caused the error.
+ try (POIFSFileSystem fs = new POIFSFileSystem(out.toInputStream())) {
+ DocumentEntry entry = (DocumentEntry) fs.getRoot().getEntry("Empty");
+ assertEquals(0, entry.getSize(), "Expected zero size");
+ byte[] actualReadbackData;
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals(0, actualReadbackData.length, "Expected zero read from stream");
+
+ entry = (DocumentEntry) fs.getRoot().getEntry("NotEmpty");
+ actualReadbackData = IOUtils.toByteArray(new DocumentInputStream(entry));
+ assertEquals(testData.length, entry.getSize(), "Expected size was wrong");
+ assertArrayEquals(testData, actualReadbackData, "Expected same data read from stream");
+ }
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestNotOLE2Exception.java Sat May 22 20:56:44 2021
@@ -34,15 +34,15 @@ import org.junit.jupiter.api.Test;
* checks
*/
class TestNotOLE2Exception {
- private static InputStream openXLSSampleStream(String sampleFileName) {
- return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
- }
+ private static InputStream openXLSSampleStream(String sampleFileName) {
+ return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ }
private static InputStream openDOCSampleStream(String sampleFileName) {
return POIDataSamples.getDocumentInstance().openResourceAsStream(sampleFileName);
}
@Test
- void testRawXMLException() throws IOException {
+ void testRawXMLException() throws IOException {
try (InputStream in = openXLSSampleStream("SampleSS.xml")) {
NotOLE2FileException e = assertThrows(NotOLE2FileException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be a raw XML file");
@@ -60,13 +60,13 @@ class TestNotOLE2Exception {
}
@Test
- void testBiff3Exception() throws IOException {
+ void testBiff3Exception() throws IOException {
try (InputStream in = openXLSSampleStream("testEXCEL_3.xls")) {
OldExcelFormatException e = assertThrows(OldExcelFormatException.class, () -> new POIFSFileSystem(in));
assertContains(e.getMessage(), "The supplied data appears to be in BIFF3 format");
assertContains(e.getMessage(), "try OldExcelExtractor");
}
- }
+ }
@Test
void testBiff4Exception() throws IOException {
Modified: poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Sat May 22 20:56:44 2021
@@ -51,299 +51,299 @@ import org.junit.jupiter.params.provider
final class TestPOIFSFileSystem {
private final POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
- /**
- * Mock exception used to ensure correct error handling
- */
- private static final class MyEx extends RuntimeException {
- MyEx() {
- // no fields to initialise
- }
- }
- /**
- * Helps facilitate testing. Keeps track of whether close() was called.
- * Also can throw an exception at a specific point in the stream.
- */
- private static final class TestIS extends InputStream {
-
- private final InputStream _is;
- private final int _failIndex;
- private int _currentIx;
- private boolean _isClosed;
-
- TestIS(InputStream is, int failIndex) {
- _is = is;
- _failIndex = failIndex;
- _currentIx = 0;
- _isClosed = false;
- }
-
- @Override
- public int read() throws IOException {
- int result = _is.read();
- if(result >=0) {
- checkRead(1);
- }
- return result;
- }
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int result = _is.read(b, off, len);
- checkRead(result);
- return result;
- }
-
- private void checkRead(int nBytes) {
- _currentIx += nBytes;
- if(_failIndex > 0 && _currentIx > _failIndex) {
- throw new MyEx();
- }
- }
- @Override
+ /**
+ * Mock exception used to ensure correct error handling
+ */
+ private static final class MyEx extends RuntimeException {
+ MyEx() {
+ // no fields to initialise
+ }
+ }
+ /**
+ * Helps facilitate testing. Keeps track of whether close() was called.
+ * Also can throw an exception at a specific point in the stream.
+ */
+ private static final class TestIS extends InputStream {
+
+ private final InputStream _is;
+ private final int _failIndex;
+ private int _currentIx;
+ private boolean _isClosed;
+
+ TestIS(InputStream is, int failIndex) {
+ _is = is;
+ _failIndex = failIndex;
+ _currentIx = 0;
+ _isClosed = false;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int result = _is.read();
+ if(result >=0) {
+ checkRead(1);
+ }
+ return result;
+ }
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int result = _is.read(b, off, len);
+ checkRead(result);
+ return result;
+ }
+
+ private void checkRead(int nBytes) {
+ _currentIx += nBytes;
+ if(_failIndex > 0 && _currentIx > _failIndex) {
+ throw new MyEx();
+ }
+ }
+ @Override
public void close() throws IOException {
- _isClosed = true;
- _is.close();
- }
- boolean isClosed() {
- return _isClosed;
- }
- }
-
- /**
- * Test for undesired behaviour observable as of svn revision 618865 (5-Feb-2008).
- * POIFSFileSystem was not closing the input stream.
- */
- @Test
- void testAlwaysClose() throws IOException {
- // Normal case - read until EOF and close
- try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), -1);
- POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
- assertTrue(testIS.isClosed(), "input stream was not closed");
- }
-
- // intended to crash after reading 10000 bytes
- try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), 10000)){
- assertThrows(MyEx.class, () -> new POIFSFileSystem(testIS));
- // but still should close
- assertTrue(testIS.isClosed(), "input stream was not closed");
- }
- }
-
- /**
- * Test for bug # 48898 - problem opening an OLE2
- * file where the last block is short (i.e. not a full
- * multiple of 512 bytes)
- *
- * As yet, this problem remains. One school of thought is
- * not not issue an EOF when we discover the last block
- * is short, but this seems a bit wrong.
- * The other is to fix the handling of the last block in
- * POIFS, since it seems to be slight wrong
- */
- @ParameterizedTest
- @CsvSource({ "ShortLastBlock.qwp, 1303681", "ShortLastBlock.wps, 140787" })
- void testShortLastBlock(String file, int size) throws Exception {
- // Open the file up
- try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) {
-
- // Write it into a temp output array
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
- fs.writeFilesystem(baos);
-
- // Check sizes
- assertEquals(size, baos.size());
- }
- }
-
- /**
- * Check that we do the right thing when the list of which
- * sectors are BAT blocks points off the list of
- * sectors that exist in the file.
- */
- @Test
- void testFATandDIFATsectors() throws Exception {
- try (InputStream stream = _samples.openResourceAsStream("ReferencesInvalidSectors.mpp")) {
- IndexOutOfBoundsException ex = assertThrows(
- IndexOutOfBoundsException.class,
- () -> new POIFSFileSystem(stream),
- "File is corrupt and shouldn't have been opened"
- );
- assertTrue(ex.getMessage().contains("Block 1148 not found"));
- }
- }
-
- /**
- * Tests that we can write and read a file that contains XBATs
- * as well as regular BATs.
- * However, because a file needs to be at least 6.875mb big
- * to have an XBAT in it, we don't have a test one. So, generate it.
- */
- @Test
- void testBATandXBAT() throws Exception {
- byte[] hugeStream = new byte[8*1024*1024];
- POIFSFileSystem fs = new POIFSFileSystem();
- fs.getRoot().createDocument(
- "BIG", new ByteArrayInputStream(hugeStream)
- );
-
- UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
- fs.writeFilesystem(baos);
- byte[] fsData = baos.toByteArray();
-
-
- // Check the header was written properly
- InputStream inp = new ByteArrayInputStream(fsData);
- HeaderBlock header = new HeaderBlock(inp);
- assertEquals(109+21, header.getBATCount());
- assertEquals(1, header.getXBATCount());
-
-
- // We should have 21 BATs in the XBAT
- ByteBuffer xbatData = ByteBuffer.allocate(512);
- xbatData.put(fsData, (1+header.getXBATIndex())*512, 512);
- xbatData.position(0);
- BATBlock xbat = BATBlock.createBATBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, xbatData);
- for(int i=0; i<21; i++) {
- assertTrue(xbat.getValueAt(i) != POIFSConstants.UNUSED_BLOCK);
- }
- for(int i=21; i<127; i++) {
- assertEquals(POIFSConstants.UNUSED_BLOCK, xbat.getValueAt(i));
- }
- assertEquals(POIFSConstants.END_OF_CHAIN, xbat.getValueAt(127));
-
-
- // Now load it and check
- fs = new POIFSFileSystem(
- new ByteArrayInputStream(fsData)
- );
-
- DirectoryNode root = fs.getRoot();
- assertEquals(1, root.getEntryCount());
- DocumentNode big = (DocumentNode)root.getEntry("BIG");
- assertEquals(hugeStream.length, big.getSize());
- }
-
- /**
- * Most OLE2 files use 512byte blocks. However, a small number
- * use 4k blocks. Check that we can open these.
- */
- @Test
- void test4KBlocks() throws Exception {
+ _isClosed = true;
+ _is.close();
+ }
+ boolean isClosed() {
+ return _isClosed;
+ }
+ }
+
+ /**
+ * Test for undesired behaviour observable as of svn revision 618865 (5-Feb-2008).
+ * POIFSFileSystem was not closing the input stream.
+ */
+ @Test
+ void testAlwaysClose() throws IOException {
+ // Normal case - read until EOF and close
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), -1);
+ POIFSFileSystem ignored = new POIFSFileSystem(testIS)){
+ assertTrue(testIS.isClosed(), "input stream was not closed");
+ }
+
+ // intended to crash after reading 10000 bytes
+ try (TestIS testIS = new TestIS(openSampleStream("13224.xls"), 10000)){
+ assertThrows(MyEx.class, () -> new POIFSFileSystem(testIS));
+ // but still should close
+ assertTrue(testIS.isClosed(), "input stream was not closed");
+ }
+ }
+
+ /**
+ * Test for bug # 48898 - problem opening an OLE2
+ * file where the last block is short (i.e. not a full
+ * multiple of 512 bytes)
+ *
+ * As yet, this problem remains. One school of thought is
+ * not not issue an EOF when we discover the last block
+ * is short, but this seems a bit wrong.
+ * The other is to fix the handling of the last block in
+ * POIFS, since it seems to be slight wrong
+ */
+ @ParameterizedTest
+ @CsvSource({ "ShortLastBlock.qwp, 1303681", "ShortLastBlock.wps, 140787" })
+ void testShortLastBlock(String file, int size) throws Exception {
+ // Open the file up
+ try (POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream(file))) {
+
+ // Write it into a temp output array
+ UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ fs.writeFilesystem(baos);
+
+ // Check sizes
+ assertEquals(size, baos.size());
+ }
+ }
+
+ /**
+ * Check that we do the right thing when the list of which
+ * sectors are BAT blocks points off the list of
+ * sectors that exist in the file.
+ */
+ @Test
+ void testFATandDIFATsectors() throws Exception {
+ try (InputStream stream = _samples.openResourceAsStream("ReferencesInvalidSectors.mpp")) {
+ IndexOutOfBoundsException ex = assertThrows(
+ IndexOutOfBoundsException.class,
+ () -> new POIFSFileSystem(stream),
+ "File is corrupt and shouldn't have been opened"
+ );
+ assertTrue(ex.getMessage().contains("Block 1148 not found"));
+ }
+ }
+
+ /**
+ * Tests that we can write and read a file that contains XBATs
+ * as well as regular BATs.
+ * However, because a file needs to be at least 6.875mb big
+ * to have an XBAT in it, we don't have a test one. So, generate it.
+ */
+ @Test
+ void testBATandXBAT() throws Exception {
+ byte[] hugeStream = new byte[8*1024*1024];
+ POIFSFileSystem fs = new POIFSFileSystem();
+ fs.getRoot().createDocument(
+ "BIG", new ByteArrayInputStream(hugeStream)
+ );
+
+ UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream();
+ fs.writeFilesystem(baos);
+ byte[] fsData = baos.toByteArray();
+
+
+ // Check the header was written properly
+ InputStream inp = new ByteArrayInputStream(fsData);
+ HeaderBlock header = new HeaderBlock(inp);
+ assertEquals(109+21, header.getBATCount());
+ assertEquals(1, header.getXBATCount());
+
+
+ // We should have 21 BATs in the XBAT
+ ByteBuffer xbatData = ByteBuffer.allocate(512);
+ xbatData.put(fsData, (1+header.getXBATIndex())*512, 512);
+ xbatData.position(0);
+ BATBlock xbat = BATBlock.createBATBlock(POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS, xbatData);
+ for(int i=0; i<21; i++) {
+ assertTrue(xbat.getValueAt(i) != POIFSConstants.UNUSED_BLOCK);
+ }
+ for(int i=21; i<127; i++) {
+ assertEquals(POIFSConstants.UNUSED_BLOCK, xbat.getValueAt(i));
+ }
+ assertEquals(POIFSConstants.END_OF_CHAIN, xbat.getValueAt(127));
+
+
+ // Now load it and check
+ fs = new POIFSFileSystem(
+ new ByteArrayInputStream(fsData)
+ );
+
+ DirectoryNode root = fs.getRoot();
+ assertEquals(1, root.getEntryCount());
+ DocumentNode big = (DocumentNode)root.getEntry("BIG");
+ assertEquals(hugeStream.length, big.getSize());
+ }
+
+ /**
+ * Most OLE2 files use 512byte blocks. However, a small number
+ * use 4k blocks. Check that we can open these.
+ */
+ @Test
+ void test4KBlocks() throws Exception {
POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
- try (InputStream inp = _samples.openResourceAsStream("BlockSize4096.zvi")) {
- // First up, check that we can process the header properly
- HeaderBlock header_block = new HeaderBlock(inp);
- POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
- assertEquals(4096, bigBlockSize.getBigBlockSize());
-
- // Check the fat info looks sane
- assertEquals(1, header_block.getBATArray().length);
- assertEquals(1, header_block.getBATCount());
- assertEquals(0, header_block.getXBATCount());
-
- // Now try and open properly
- POIFSFileSystem fs = new POIFSFileSystem(
- _samples.openResourceAsStream("BlockSize4096.zvi"));
- assertTrue(fs.getRoot().getEntryCount() > 3);
-
- // Check we can get at all the contents
- checkAllDirectoryContents(fs.getRoot());
-
- // Finally, check we can do a similar 512byte one too
- fs = new POIFSFileSystem(
- _samples.openResourceAsStream("BlockSize512.zvi"));
- assertTrue(fs.getRoot().getEntryCount() > 3);
- checkAllDirectoryContents(fs.getRoot());
- }
- }
- private void checkAllDirectoryContents(DirectoryEntry dir) throws IOException {
- for(Entry entry : dir) {
- if(entry instanceof DirectoryEntry) {
- checkAllDirectoryContents((DirectoryEntry)entry);
- } else {
- DocumentNode doc = (DocumentNode) entry;
- try (DocumentInputStream dis = new DocumentInputStream(doc)) {
- IOUtils.toByteArray(dis);
- }
- }
- }
- }
-
- @SuppressWarnings("SameParameterValue")
- private static InputStream openSampleStream(String sampleFileName) {
- return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
- }
-
- @Test
- public void fileMagics() {
- for (FileMagic fm : FileMagic.values()) {
- if (fm == FileMagic.UNKNOWN) {
- continue;
- }
- for (byte[] b : fm.magic) {
- assertEquals(fm, FileMagic.valueOf(b));
- }
- }
-
- assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf("foobaa".getBytes(UTF_8)));
- }
-
- @Test
- void test64322() throws NoPropertySetStreamException, IOException {
- try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.getFile("64322.ole2"))) {
- int count = recurseDir(poiFS.getRoot());
-
- assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
- }
- }
-
- @Test
- void test64322a() throws NoPropertySetStreamException, IOException {
- try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.openResourceAsStream("64322.ole2"))) {
- int count = recurseDir(poiFS.getRoot());
-
- assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
- }
- }
-
- private static int recurseDir(DirectoryEntry dir) throws IOException, NoPropertySetStreamException {
- int count = 0;
- for (Entry entry : dir) {
- count++;
- if (entry instanceof DirectoryEntry) {
- count += recurseDir((DirectoryEntry) entry);
- }
- if (entry instanceof DocumentEntry) {
- DocumentEntry de = (DocumentEntry) entry;
- HashMap<String, String> props = new HashMap<>();
- try (DocumentInputStream dis = new DocumentInputStream(de)) {
- props.put("name", de.getName());
-
- if (PropertySet.isPropertySetStream(dis)) {
- dis.mark(10000000);
- PropertySet ps = null;
- try {
- ps = new PropertySet(dis);
-
- } catch (UnsupportedEncodingException e) {
- // ignore
- }
- if (ps != null) {
- for (Section section : ps.getSections()) {
- for (Property p : section.getProperties()) {
- String prop = section.getDictionary() != null
- ? section.getDictionary().get(p.getID())
- : String.valueOf(p.getID());
- if (p.getValue() != null)
- props.put("property_" + prop, p.getValue().toString());
- }
- }
- }
- dis.reset();
- }
- }
- assertTrue(props.size() > 0);
- }
- }
- return count;
- }
+ try (InputStream inp = _samples.openResourceAsStream("BlockSize4096.zvi")) {
+ // First up, check that we can process the header properly
+ HeaderBlock header_block = new HeaderBlock(inp);
+ POIFSBigBlockSize bigBlockSize = header_block.getBigBlockSize();
+ assertEquals(4096, bigBlockSize.getBigBlockSize());
+
+ // Check the fat info looks sane
+ assertEquals(1, header_block.getBATArray().length);
+ assertEquals(1, header_block.getBATCount());
+ assertEquals(0, header_block.getXBATCount());
+
+ // Now try and open properly
+ POIFSFileSystem fs = new POIFSFileSystem(
+ _samples.openResourceAsStream("BlockSize4096.zvi"));
+ assertTrue(fs.getRoot().getEntryCount() > 3);
+
+ // Check we can get at all the contents
+ checkAllDirectoryContents(fs.getRoot());
+
+ // Finally, check we can do a similar 512byte one too
+ fs = new POIFSFileSystem(
+ _samples.openResourceAsStream("BlockSize512.zvi"));
+ assertTrue(fs.getRoot().getEntryCount() > 3);
+ checkAllDirectoryContents(fs.getRoot());
+ }
+ }
+ private void checkAllDirectoryContents(DirectoryEntry dir) throws IOException {
+ for(Entry entry : dir) {
+ if(entry instanceof DirectoryEntry) {
+ checkAllDirectoryContents((DirectoryEntry)entry);
+ } else {
+ DocumentNode doc = (DocumentNode) entry;
+ try (DocumentInputStream dis = new DocumentInputStream(doc)) {
+ IOUtils.toByteArray(dis);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("SameParameterValue")
+ private static InputStream openSampleStream(String sampleFileName) {
+ return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
+ }
+
+ @Test
+ public void fileMagics() {
+ for (FileMagic fm : FileMagic.values()) {
+ if (fm == FileMagic.UNKNOWN) {
+ continue;
+ }
+ for (byte[] b : fm.magic) {
+ assertEquals(fm, FileMagic.valueOf(b));
+ }
+ }
+
+ assertEquals(FileMagic.UNKNOWN, FileMagic.valueOf("foobaa".getBytes(UTF_8)));
+ }
+
+ @Test
+ void test64322() throws NoPropertySetStreamException, IOException {
+ try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.getFile("64322.ole2"))) {
+ int count = recurseDir(poiFS.getRoot());
+
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
+ }
+ }
+
+ @Test
+ void test64322a() throws NoPropertySetStreamException, IOException {
+ try (POIFSFileSystem poiFS = new POIFSFileSystem(_samples.openResourceAsStream("64322.ole2"))) {
+ int count = recurseDir(poiFS.getRoot());
+
+ assertEquals(1285, count, "Expecting a fixed number of entries being found in the test-document");
+ }
+ }
+
+ private static int recurseDir(DirectoryEntry dir) throws IOException, NoPropertySetStreamException {
+ int count = 0;
+ for (Entry entry : dir) {
+ count++;
+ if (entry instanceof DirectoryEntry) {
+ count += recurseDir((DirectoryEntry) entry);
+ }
+ if (entry instanceof DocumentEntry) {
+ DocumentEntry de = (DocumentEntry) entry;
+ HashMap<String, String> props = new HashMap<>();
+ try (DocumentInputStream dis = new DocumentInputStream(de)) {
+ props.put("name", de.getName());
+
+ if (PropertySet.isPropertySetStream(dis)) {
+ dis.mark(10000000);
+ PropertySet ps = null;
+ try {
+ ps = new PropertySet(dis);
+
+ } catch (UnsupportedEncodingException e) {
+ // ignore
+ }
+ if (ps != null) {
+ for (Section section : ps.getSections()) {
+ for (Property p : section.getProperties()) {
+ String prop = section.getDictionary() != null
+ ? section.getDictionary().get(p.getID())
+ : String.valueOf(p.getID());
+ if (p.getValue() != null)
+ props.put("property_" + prop, p.getValue().toString());
+ }
+ }
+ }
+ dis.reset();
+ }
+ }
+ assertTrue(props.size() > 0);
+ }
+ }
+ return count;
+ }
}
Modified: poi/trunk/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyFactory.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyFactory.java (original)
+++ poi/trunk/poi/src/test/java/org/apache/poi/poifs/property/TestPropertyFactory.java Sat May 22 20:56:44 2021
@@ -39,126 +39,126 @@ final class TestPropertyFactory {
@Test
void testConvertToProperties() throws IOException {
- // real data from a real file!
- String hexData =
- "H4sIAAAAAAAAANWZ624TRxTHxymXcm2ahjRNUrJAoCGESxFCCPEB22lSqoRECbGE+slxNvEqcYx2bUQ/lUfphz5BnwBegw88" +
- "Ac8A/M/ZWe/E3svMbKjEseIdbyz/zpk5cy6z66KNV0c44jdxgKsv/hImMiaOi09SzuV8983Sv+8/uG9L32D8+Gx4bwH0huiK" +
- "lnCZ7+COi2tdeGJfBLn8y0KUPimS9J1//r7+7fPa29Ib51e+qv+rwmIXtA54bWjgiKf4RNroyZQGv18+4nvzqfwF/vSl+afl" +
- "eBm0gOd9A6OX4G4b6eAU5EckRyzyihPfRMYK8/v9r4aRjzkJ1yNPdPwviX9Mjiuwv4FXEzoE0vvrmAfyQ9Jqi7VJl9mC/EH7" +
- "l/nOnuZKOEfOj2fgGWLRixwvvGbJP5HKL+PTNla/o/NT4qIGP4o7r39/OBB/NrHqtMIqlyz3ZQTME1v/q8hxlb28w7wGs5d4" +
- "Jly+E0elJ3jfwbhf7mrwI7uT7I9XOyL4WIuYnG9/qcf/KeU7Pf5/6xl8GgWYAx/kFwb8IYpB5IdCd/4p9pyS4w2mu7z3yzIX" +
- "OLwq25rxd6g0guucAf8M/uL9F9lfhf/5rMEBZkG3CpgCf5L10OdT6j8px6ugdhDl2rgecO4JfZ8y0b6SidIqgXnwr+L6iwGf" +
- "6pRLcryC33+FtW5xDKAsSLWHfg00Af4orsMG/PP4O57Dd8Qa70GPPSFdZuF/47heMeB/J5LWXyfaDsoo+BdYD33+sMLfgN1b" +
- "StQ3lRHM/y1cpw343yt82mktvDx4WNCLdjXWpasxG9j/xvF3ROEvguRz/WM//6b8Hw7xNzH3FPXJ18Laz5PZMJqPrCp81sL+" +
- "0Uy+WR6YA5/8eULor/9H5XsLHHm2OAbHXuiBuCt1oZzcYE3aCZXYXfDJny4Z8C8o9le47vM44wacBcz8YMpi/ccU/ibXmD5H" +
- "233OPcuszR7rUpcxeY27hIC9YlfWx6E8suCr81/m36MKJDDuvUjGLfg/KvarVbaDFd7JtHZQ5iz44wq/jPmuKhk/v+M9LDb7" +
- "X53/qtzh5Nu01+qGujiF+U2uc7d7Ga8h/aHOcx/dbXFl3BnoSu5j/80IqgP09x/VidH8JzNDP3gOpsu6pcushf0TQvU/l6vu" +
- "dVxbsvrPtniAX7ouuA/Qtn9S4YfRtt7rvTyugcNqTEeXe+DflGxd/pQBPy8TU/2HHkzcNrD/Z4X/DDNfwy607z+GSneEmf0X" +
- "RVb8/4PvEH+nl3nSdbllkX+nxeH6y+fzB6pDdm3qjxLFU5pTXb4jVP8n+7qyBgr3XY118bRWwWb/Ua5ek+NVMJoy+tMe3FH6" +
- "EBeVed4pwAzsp3qeaipdPtXqcf1Z534ryr9xx72Ie25KVIzlgYX9M0Z8Opd7Jc8FB3fjQ9h/Q4R7Wpd/1Yif3Zfes7CfevWo" +
- "/wzjLvnbnnHuJRkumP9U/6uyHj5nHZ97QZfPZNoZFci8BZ965Tj/+fz70Sls1A9FNVmeXC5oP+W/XX4C4Ymk86a8aHxH5/xJ" +
- "nvsknf+sc9zt8Kw3ZIbrXwmKytdkb97fDd0veP5ZBi889QstjM5idFeh6Pkv2f+SOV1e/xXej2GUic9E0/V58L/ww8js9qKA" +
- "Gn+K8Vc49xY5/ynGj5//hJ5XMX7+ZseflONV3m0V0Jvse5R/V/GuK0Xtj8+f1nrVd5nPBJvKs4is/suOPyzHSxz/uui4Y26b" +
- "d35wdOffMu48fvfnQPyJn7894fqvK/1A1SvrSZAOP8n+6PlHGkc3F9o+f9T8eS0x5R+1fM38zxmfK1AAIAAA";
-
- final byte[] testdata = RawDataUtil.decompress(hexData);
- final ByteArrayInputStream stream = new ByteArrayInputStream(testdata);
- final List<Property> properties = new ArrayList<>();
-
- final byte[] buf = new byte[512];
- for (int readBytes; (readBytes = stream.read(buf)) != -1; ) {
- byte[] bbuf = buf;
- if (readBytes < 512) {
- bbuf = Arrays.copyOf(buf, readBytes);
- }
-
- PropertyFactory.convertToProperties(bbuf, properties);
- }
-
- assertEquals(64, properties.size());
- String[] names = {
- "Root Entry", null, null, null, null, null, null, null, null,
- null, null, null, null, "Deal Information", "Deal Description",
- "Sales Area Code", "Deal Currency", "Outbound Travel Dates",
- "Maximum Stay", "Maximum Stay Period", "Deal Type", "Sub Deal",
- "Commission Value", "Fare Type", "FUD Grid Dimensions",
- "FUD Grid Information", "Double Dealing Indicator",
- "Business Type", "Umbrella Links and Passengers", "Agents Name",
- "Number of Passengers", "ALC Codes", "Consortia Codes",
- "Child Percentage Permitted", "Percentage of Yield",
- "Net Remit Permitted", "Infant Discount Permitted",
- "Infant Discount Value", "TRVA Information",
- "Business Justification", "Surcharge", "Nature of Variation",
- "Other Refund Text", "Cancellation Fee Percentage",
- "Cancellation Fee Fixed Value", "Cancellation Fee Currency",
- "Remarks", "Other Carrier Sectors", "Prorate Comments", null,
- null, null, null, null, null, null, null, null, null, null, null,
- null, null, null
- };
- assertEquals(64, names.length);
-
- boolean[] isRoot = {
- true, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false
- };
- assertEquals(64, isRoot.length);
-
- boolean[] isDocument = {
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false
- };
- assertEquals(64, isDocument.length);
-
- boolean[] isDirectory = {
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, true, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false
- };
- assertEquals(64, isDirectory.length);
-
- boolean[] isNull = {
- false, true, true, true, true, true, true, true, true, true, true,
- true, true, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false,
- false, false, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true
- };
- assertEquals(64, isNull.length);
-
- for (int j = 0; j < 64; j++) {
- if (isNull[j]) {
- assertNull(properties.get(j), "Checking property " + j);
- } else {
- assertNotNull(properties.get(j), "Checking property " + j);
- if (isRoot[j]) {
- assertTrue(properties.get(j) instanceof RootProperty, "Checking property " + j);
- }
- if (isDirectory[j]) {
- assertTrue(properties.get(j) instanceof DirectoryProperty, "Checking property " + j);
- }
- if (isDocument[j]) {
- assertTrue(properties.get(j) instanceof DocumentProperty, "Checking property " + j);
- }
- assertEquals(names[j], properties.get(j).getName(), "Checking property " + j);
- }
- }
- }
+ // real data from a real file!
+ String hexData =
+ "H4sIAAAAAAAAANWZ624TRxTHxymXcm2ahjRNUrJAoCGESxFCCPEB22lSqoRECbGE+slxNvEqcYx2bUQ/lUfphz5BnwBegw88" +
+ "Ac8A/M/ZWe/E3svMbKjEseIdbyz/zpk5cy6z66KNV0c44jdxgKsv/hImMiaOi09SzuV8983Sv+8/uG9L32D8+Gx4bwH0huiK" +
+ "lnCZ7+COi2tdeGJfBLn8y0KUPimS9J1//r7+7fPa29Ib51e+qv+rwmIXtA54bWjgiKf4RNroyZQGv18+4nvzqfwF/vSl+afl" +
+ "eBm0gOd9A6OX4G4b6eAU5EckRyzyihPfRMYK8/v9r4aRjzkJ1yNPdPwviX9Mjiuwv4FXEzoE0vvrmAfyQ9Jqi7VJl9mC/EH7" +
+ "l/nOnuZKOEfOj2fgGWLRixwvvGbJP5HKL+PTNla/o/NT4qIGP4o7r39/OBB/NrHqtMIqlyz3ZQTME1v/q8hxlb28w7wGs5d4" +
+ "Jly+E0elJ3jfwbhf7mrwI7uT7I9XOyL4WIuYnG9/qcf/KeU7Pf5/6xl8GgWYAx/kFwb8IYpB5IdCd/4p9pyS4w2mu7z3yzIX" +
+ "OLwq25rxd6g0guucAf8M/uL9F9lfhf/5rMEBZkG3CpgCf5L10OdT6j8px6ugdhDl2rgecO4JfZ8y0b6SidIqgXnwr+L6iwGf" +
+ "6pRLcryC33+FtW5xDKAsSLWHfg00Af4orsMG/PP4O57Dd8Qa70GPPSFdZuF/47heMeB/J5LWXyfaDsoo+BdYD33+sMLfgN1b" +
+ "StQ3lRHM/y1cpw343yt82mktvDx4WNCLdjXWpasxG9j/xvF3ROEvguRz/WM//6b8Hw7xNzH3FPXJ18Laz5PZMJqPrCp81sL+" +
+ "0Uy+WR6YA5/8eULor/9H5XsLHHm2OAbHXuiBuCt1oZzcYE3aCZXYXfDJny4Z8C8o9le47vM44wacBcz8YMpi/ccU/ibXmD5H" +
+ "233OPcuszR7rUpcxeY27hIC9YlfWx6E8suCr81/m36MKJDDuvUjGLfg/KvarVbaDFd7JtHZQ5iz44wq/jPmuKhk/v+M9LDb7" +
+ "X53/qtzh5Nu01+qGujiF+U2uc7d7Ga8h/aHOcx/dbXFl3BnoSu5j/80IqgP09x/VidH8JzNDP3gOpsu6pcushf0TQvU/l6vu" +
+ "dVxbsvrPtniAX7ouuA/Qtn9S4YfRtt7rvTyugcNqTEeXe+DflGxd/pQBPy8TU/2HHkzcNrD/Z4X/DDNfwy607z+GSneEmf0X" +
+ "RVb8/4PvEH+nl3nSdbllkX+nxeH6y+fzB6pDdm3qjxLFU5pTXb4jVP8n+7qyBgr3XY118bRWwWb/Ua5ek+NVMJoy+tMe3FH6" +
+ "EBeVed4pwAzsp3qeaipdPtXqcf1Z534ryr9xx72Ie25KVIzlgYX9M0Z8Opd7Jc8FB3fjQ9h/Q4R7Wpd/1Yif3Zfes7CfevWo" +
+ "/wzjLvnbnnHuJRkumP9U/6uyHj5nHZ97QZfPZNoZFci8BZ965Tj/+fz70Sls1A9FNVmeXC5oP+W/XX4C4Ymk86a8aHxH5/xJ" +
+ "nvsknf+sc9zt8Kw3ZIbrXwmKytdkb97fDd0veP5ZBi889QstjM5idFeh6Pkv2f+SOV1e/xXej2GUic9E0/V58L/ww8js9qKA" +
+ "Gn+K8Vc49xY5/ynGj5//hJ5XMX7+ZseflONV3m0V0Jvse5R/V/GuK0Xtj8+f1nrVd5nPBJvKs4is/suOPyzHSxz/uui4Y26b" +
+ "d35wdOffMu48fvfnQPyJn7894fqvK/1A1SvrSZAOP8n+6PlHGkc3F9o+f9T8eS0x5R+1fM38zxmfK1AAIAAA";
+
+ final byte[] testdata = RawDataUtil.decompress(hexData);
+ final ByteArrayInputStream stream = new ByteArrayInputStream(testdata);
+ final List<Property> properties = new ArrayList<>();
+
+ final byte[] buf = new byte[512];
+ for (int readBytes; (readBytes = stream.read(buf)) != -1; ) {
+ byte[] bbuf = buf;
+ if (readBytes < 512) {
+ bbuf = Arrays.copyOf(buf, readBytes);
+ }
+
+ PropertyFactory.convertToProperties(bbuf, properties);
+ }
+
+ assertEquals(64, properties.size());
+ String[] names = {
+ "Root Entry", null, null, null, null, null, null, null, null,
+ null, null, null, null, "Deal Information", "Deal Description",
+ "Sales Area Code", "Deal Currency", "Outbound Travel Dates",
+ "Maximum Stay", "Maximum Stay Period", "Deal Type", "Sub Deal",
+ "Commission Value", "Fare Type", "FUD Grid Dimensions",
+ "FUD Grid Information", "Double Dealing Indicator",
+ "Business Type", "Umbrella Links and Passengers", "Agents Name",
+ "Number of Passengers", "ALC Codes", "Consortia Codes",
+ "Child Percentage Permitted", "Percentage of Yield",
+ "Net Remit Permitted", "Infant Discount Permitted",
+ "Infant Discount Value", "TRVA Information",
+ "Business Justification", "Surcharge", "Nature of Variation",
+ "Other Refund Text", "Cancellation Fee Percentage",
+ "Cancellation Fee Fixed Value", "Cancellation Fee Currency",
+ "Remarks", "Other Carrier Sectors", "Prorate Comments", null,
+ null, null, null, null, null, null, null, null, null, null, null,
+ null, null, null
+ };
+ assertEquals(64, names.length);
+
+ boolean[] isRoot = {
+ true, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false
+ };
+ assertEquals(64, isRoot.length);
+
+ boolean[] isDocument = {
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false
+ };
+ assertEquals(64, isDocument.length);
+
+ boolean[] isDirectory = {
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, true, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false
+ };
+ assertEquals(64, isDirectory.length);
+
+ boolean[] isNull = {
+ false, true, true, true, true, true, true, true, true, true, true,
+ true, true, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false,
+ false, false, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true
+ };
+ assertEquals(64, isNull.length);
+
+ for (int j = 0; j < 64; j++) {
+ if (isNull[j]) {
+ assertNull(properties.get(j), "Checking property " + j);
+ } else {
+ assertNotNull(properties.get(j), "Checking property " + j);
+ if (isRoot[j]) {
+ assertTrue(properties.get(j) instanceof RootProperty, "Checking property " + j);
+ }
+ if (isDirectory[j]) {
+ assertTrue(properties.get(j) instanceof DirectoryProperty, "Checking property " + j);
+ }
+ if (isDocument[j]) {
+ assertTrue(properties.get(j) instanceof DocumentProperty, "Checking property " + j);
+ }
+ assertEquals(names[j], properties.get(j).getName(), "Checking property " + j);
+ }
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org