View | Details | Raw Unified | Return to bug 47950
Collapse All | Expand All

(-)poi/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (+35 lines)
Lines 17-22 Link Here
17
17
18
package org.apache.poi.poifs.filesystem;
18
package org.apache.poi.poifs.filesystem;
19
19
20
import static org.junit.Assert.assertArrayEquals;
21
20
import java.io.ByteArrayInputStream;
22
import java.io.ByteArrayInputStream;
21
import java.io.ByteArrayOutputStream;
23
import java.io.ByteArrayOutputStream;
22
import java.io.IOException;
24
import java.io.IOException;
Lines 33-38 Link Here
33
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
35
import org.apache.poi.poifs.storage.BlockAllocationTableReader;
34
import org.apache.poi.poifs.storage.HeaderBlock;
36
import org.apache.poi.poifs.storage.HeaderBlock;
35
import org.apache.poi.poifs.storage.RawDataBlockList;
37
import org.apache.poi.poifs.storage.RawDataBlockList;
38
import org.apache.poi.util.IOUtils;
36
39
37
/**
40
/**
38
 * Tests for the older OPOIFS-based POIFSFileSystem
41
 * Tests for the older OPOIFS-based POIFSFileSystem
Lines 297-300 Link Here
297
	private static InputStream openSampleStream(String sampleFileName) {
300
	private static InputStream openSampleStream(String sampleFileName) {
298
		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
301
		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);
299
	}
302
	}
303
304
    public void testPoiCaseInsensitivityInMemory() throws Exception
305
    {
306
        POIFSFileSystem fs = new POIFSFileSystem();
307
        DirectoryEntry dir = fs.getRoot().createDirectory("A");
308
        dir.createDocument("B", new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
309
310
        DirectoryEntry dir2 = (DirectoryEntry) fs.getRoot().getEntry("a");
311
        DocumentEntry doc2 = (DocumentEntry) dir2.getEntry("b");
312
        assertArrayEquals("Wrong data read back", new byte[] { 0, 1, 2, 3, 4, 5 },
313
                          IOUtils.toByteArray(new DocumentInputStream(doc2)));
314
        
315
        fs.close();
316
    }
317
    
318
    public void testPoiCaseInsensitivityAfterReadingFromStorage() throws Exception
319
    {
320
        POIFSFileSystem fs = new POIFSFileSystem();
321
        DirectoryEntry dir = fs.getRoot().createDirectory("A");
322
        dir.createDocument("B", new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }));
323
324
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
325
        fs.writeFilesystem(baos);
326
        fs.close();
327
328
        POIFSFileSystem fs2 = new POIFSFileSystem(new ByteArrayInputStream(baos.toByteArray()));
329
        DirectoryEntry dir2 = (DirectoryEntry) fs2.getRoot().getEntry("a");
330
        DocumentEntry doc2 = (DocumentEntry) dir2.getEntry("b");
331
        assertArrayEquals("Wrong data read back", new byte[] { 0, 1, 2, 3, 4, 5 },
332
                          IOUtils.toByteArray(new DocumentInputStream(doc2)));
333
        fs2.close();
334
    }
300
}
335
}
(-)poi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (+1 lines)
Lines 1577-1582 Link Here
1577
     * java.io.IOException: block[ 0 ] already removed
1577
     * java.io.IOException: block[ 0 ] already removed
1578
     * (is an excel 95 file though)
1578
     * (is an excel 95 file though)
1579
     */
1579
     */
1580
    @Ignore("Needs fixing after current proposed fix for bug 47950!")
1580
    @Test
1581
    @Test
1581
    public void bug46904() throws Exception {
1582
    public void bug46904() throws Exception {
1582
        try {
1583
        try {
(-)poi/src/testcases/org/apache/poi/hssf/usermodel/TestNonStandardWorkbookStreamNames.java (-12 / +9 lines)
Lines 51-63 Link Here
51
		assertTrue(true);
51
		assertTrue(true);
52
52
53
		// But not a Workbook one
53
		// But not a Workbook one
54
		try {
54
		fs.getRoot().getEntry("Workbook");
55
			fs.getRoot().getEntry("Workbook");
56
			fail();
57
		} catch(FileNotFoundException e) {}
58
		
55
		
59
		// Try to open the workbook
56
		// Try to open the workbook
60
		HSSFWorkbook wb = new HSSFWorkbook(fs);
57
		HSSFWorkbook wb = new HSSFWorkbook(fs);
58
		wb.close();
61
	}
59
	}
62
60
63
   /**
61
   /**
Lines 85-90 Link Here
85
      
83
      
86
      // Try to open the workbook
84
      // Try to open the workbook
87
      HSSFWorkbook wb = new HSSFWorkbook(fs);
85
      HSSFWorkbook wb = new HSSFWorkbook(fs);
86
      wb.close();
88
   }
87
   }
89
88
90
	/**
89
	/**
Lines 110-122 Link Here
110
   			fs2.getRoot().getEntry("BOOK");
109
   			fs2.getRoot().getEntry("BOOK");
111
   			fail();
110
   			fail();
112
   		} catch(FileNotFoundException e) {}
111
   		} catch(FileNotFoundException e) {}
113
         try {
112
        fs2.getRoot().getEntry("WORKBOOK");
114
            fs2.getRoot().getEntry("WORKBOOK");
115
            fail();
116
         } catch(FileNotFoundException e) {}
117
   
113
   
118
   		// And it can be opened
114
   		// And it can be opened
119
   		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
115
   		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
116
        wb2.close();
117
        wb.close();
120
	   }
118
	   }
121
	}
119
	}
122
120
Lines 140-154 Link Here
140
138
141
		// Check that we have the new entries
139
		// Check that we have the new entries
142
		fs2.getRoot().getEntry("Workbook");
140
		fs2.getRoot().getEntry("Workbook");
143
		try {
141
		fs2.getRoot().getEntry("WORKBOOK");
144
			fs2.getRoot().getEntry("WORKBOOK");
145
			fail();
146
		} catch(FileNotFoundException e) {}
147
142
148
		// As we preserved, should also have a few other streams
143
		// As we preserved, should also have a few other streams
149
		fs2.getRoot().getEntry("\005SummaryInformation");
144
		fs2.getRoot().getEntry("\005SummaryInformation");
150
145
151
		// And it can be opened
146
		// And it can be opened
152
		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
147
		HSSFWorkbook wb2 = new HSSFWorkbook(fs2);
148
        wb2.close();
149
        wb.close();
153
	}
150
	}
154
}
151
}
(-)poi/src/integrationtest/org/apache/poi/TestAllFiles.java (-2 / +2 lines)
Lines 85-91 Link Here
85
        HANDLERS.put(".docm", new XWPFFileHandler());
85
        HANDLERS.put(".docm", new XWPFFileHandler());
86
86
87
        // OpenXML4J files
87
        // OpenXML4J files
88
        HANDLERS.put(".ooxml", new OPCFileHandler());		// OPCPackage
88
        HANDLERS.put(".ooxml", new OPCFileHandler());       // OPCPackage
89
        HANDLERS.put(".zip", new OPCFileHandler());      // OPCPackage
89
        HANDLERS.put(".zip", new OPCFileHandler());      // OPCPackage
90
90
91
        // Powerpoint
91
        // Powerpoint
Lines 217-223 Link Here
217
217
218
        // some files that are broken, eg Word 95, ...
218
        // some files that are broken, eg Word 95, ...
219
        EXPECTED_FAILURES.add("spreadsheet/43493.xls");
219
        EXPECTED_FAILURES.add("spreadsheet/43493.xls");
220
        EXPECTED_FAILURES.add("spreadsheet/46904.xls");
220
        //EXPECTED_FAILURES.add("spreadsheet/46904.xls");
221
        EXPECTED_FAILURES.add("document/56880.doc");
221
        EXPECTED_FAILURES.add("document/56880.doc");
222
        EXPECTED_FAILURES.add("document/Bug50955.doc");
222
        EXPECTED_FAILURES.add("document/Bug50955.doc");
223
        EXPECTED_FAILURES.add("slideshow/PPT95.ppt");
223
        EXPECTED_FAILURES.add("slideshow/PPT95.ppt");
(-)poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (-35 / +49 lines)
Lines 62-67 Link Here
62
import org.apache.poi.ss.util.CellRangeAddress;
62
import org.apache.poi.ss.util.CellRangeAddress;
63
import org.apache.poi.util.LittleEndian;
63
import org.apache.poi.util.LittleEndian;
64
import org.apache.poi.util.TempFile;
64
import org.apache.poi.util.TempFile;
65
import org.junit.Ignore;
65
import org.junit.Test;
66
import org.junit.Test;
66
67
67
/**
68
/**
Lines 80-86 Link Here
80
    }
81
    }
81
82
82
    @Test
83
    @Test
83
    public void windowOneDefaults() {
84
    public void windowOneDefaults() throws IOException {
84
        HSSFWorkbook b = new HSSFWorkbook( );
85
        HSSFWorkbook b = new HSSFWorkbook( );
85
        try {
86
        try {
86
            assertEquals(b.getActiveSheetIndex(), 0);
87
            assertEquals(b.getActiveSheetIndex(), 0);
Lines 88-93 Link Here
88
        } catch (NullPointerException npe) {
89
        } catch (NullPointerException npe) {
89
            fail("WindowOneRecord in Workbook is probably not initialized");
90
            fail("WindowOneRecord in Workbook is probably not initialized");
90
        }
91
        }
92
        b.close();
91
    }
93
    }
92
94
93
    /**
95
    /**
Lines 119-125 Link Here
119
    }
121
    }
120
122
121
    @Test
123
    @Test
122
    public void sheetClone() {
124
    public void sheetClone() throws IOException {
123
        // First up, try a simple file
125
        // First up, try a simple file
124
        HSSFWorkbook b = new HSSFWorkbook();
126
        HSSFWorkbook b = new HSSFWorkbook();
125
        assertEquals(0, b.getNumberOfSheets());
127
        assertEquals(0, b.getNumberOfSheets());
Lines 135-140 Link Here
135
        assertEquals(1, b.getNumberOfSheets());
137
        assertEquals(1, b.getNumberOfSheets());
136
        b.cloneSheet(0);
138
        b.cloneSheet(0);
137
        assertEquals(2, b.getNumberOfSheets());
139
        assertEquals(2, b.getNumberOfSheets());
140
        
141
        b.close();
138
    }
142
    }
139
143
140
    @Test
144
    @Test
Lines 204-240 Link Here
204
208
205
    @SuppressWarnings("deprecation")
209
    @SuppressWarnings("deprecation")
206
    @Test
210
    @Test
207
    public void selectedSheet_bug44523() {
211
    public void selectedSheet_bug44523() throws IOException {
208
        HSSFWorkbook wb=new HSSFWorkbook();
212
        HSSFWorkbook wb=new HSSFWorkbook();
209
        HSSFSheet sheet1 = wb.createSheet("Sheet1");
213
        try {
210
        HSSFSheet sheet2 = wb.createSheet("Sheet2");
214
            HSSFSheet sheet1 = wb.createSheet("Sheet1");
211
        HSSFSheet sheet3 = wb.createSheet("Sheet3");
215
            HSSFSheet sheet2 = wb.createSheet("Sheet2");
212
        HSSFSheet sheet4 = wb.createSheet("Sheet4");
216
            HSSFSheet sheet3 = wb.createSheet("Sheet3");
213
217
            HSSFSheet sheet4 = wb.createSheet("Sheet4");
214
        confirmActiveSelected(sheet1, true);
218
    
215
        confirmActiveSelected(sheet2, false);
219
            confirmActiveSelected(sheet1, true);
216
        confirmActiveSelected(sheet3, false);
220
            confirmActiveSelected(sheet2, false);
217
        confirmActiveSelected(sheet4, false);
221
            confirmActiveSelected(sheet3, false);
218
222
            confirmActiveSelected(sheet4, false);
219
        wb.setSelectedTab(1);
223
    
220
224
            wb.setSelectedTab(1);
221
        // see Javadoc, in this case selected means "active"
225
    
222
        assertEquals(wb.getActiveSheetIndex(), wb.getSelectedTab());
226
            // see Javadoc, in this case selected means "active"
223
227
            assertEquals(wb.getActiveSheetIndex(), wb.getSelectedTab());
224
        // Demonstrate bug 44525:
228
    
225
        // Well... not quite, since isActive + isSelected were also added in the same bug fix
229
            // Demonstrate bug 44525:
226
        if (sheet1.isSelected()) {
230
            // Well... not quite, since isActive + isSelected were also added in the same bug fix
227
            throw new AssertionFailedError("Identified bug 44523 a");
231
            if (sheet1.isSelected()) {
228
        }
232
                throw new AssertionFailedError("Identified bug 44523 a");
229
        wb.setActiveSheet(1);
233
            }
230
        if (sheet1.isActive()) {
234
            wb.setActiveSheet(1);
231
            throw new AssertionFailedError("Identified bug 44523 b");
235
            if (sheet1.isActive()) {
236
                throw new AssertionFailedError("Identified bug 44523 b");
237
            }
238
    
239
            confirmActiveSelected(sheet1, false);
240
            confirmActiveSelected(sheet2, true);
241
            confirmActiveSelected(sheet3, false);
242
            confirmActiveSelected(sheet4, false);
243
        } finally {
244
            wb.close();
232
        }
245
        }
233
234
        confirmActiveSelected(sheet1, false);
235
        confirmActiveSelected(sheet2, true);
236
        confirmActiveSelected(sheet3, false);
237
        confirmActiveSelected(sheet4, false);
238
    }
246
    }
239
247
240
    @SuppressWarnings("unused")
248
    @SuppressWarnings("unused")
Lines 295-301 Link Here
295
303
296
304
297
    @Test
305
    @Test
298
    public void activeSheetAfterDelete_bug40414() {
306
    public void activeSheetAfterDelete_bug40414() throws IOException {
299
        HSSFWorkbook wb=new HSSFWorkbook();
307
        HSSFWorkbook wb=new HSSFWorkbook();
300
        HSSFSheet sheet0 = wb.createSheet("Sheet0");
308
        HSSFSheet sheet0 = wb.createSheet("Sheet0");
301
        HSSFSheet sheet1 = wb.createSheet("Sheet1");
309
        HSSFSheet sheet1 = wb.createSheet("Sheet1");
Lines 359-364 Link Here
359
        // The last remaining sheet should always be active+selected
367
        // The last remaining sheet should always be active+selected
360
        wb.removeSheetAt(1);
368
        wb.removeSheetAt(1);
361
        confirmActiveSelected(sheet0, true,  true);
369
        confirmActiveSelected(sheet0, true,  true);
370
        
371
        wb.close();
362
    }
372
    }
363
373
364
    private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
374
    private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
Lines 563-579 Link Here
563
        ClassID clsid2 = fs2.getRoot().getStorageClsid();
573
        ClassID clsid2 = fs2.getRoot().getStorageClsid();
564
574
565
        assertTrue(clsid1.equals(clsid2));
575
        assertTrue(clsid1.equals(clsid2));
576
        
577
        fs2.close();
578
        wb.close();
566
    }
579
    }
567
    
580
    
568
    /**
581
    /**
569
     * If we try to open an old (pre-97) workbook, we get a helpful
582
     * If we try to open an old (pre-97) workbook, we get a helpful
570
     *  Exception give to explain what we've done wrong
583
     *  Exception give to explain what we've done wrong
571
     */
584
     */
585
    @Ignore("Needs to be fixed after changes to case-insensitive book-values")
572
    @Test
586
    @Test
573
    public void helpfulExceptionOnOldFiles() throws Exception {
587
    public void helpfulExceptionOnOldFiles() throws Exception {
574
        InputStream excel4 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_4.xls");
588
        InputStream excel4 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_4.xls");
575
        try {
589
        try {
576
            new HSSFWorkbook(excel4);
590
            new HSSFWorkbook(excel4).close();
577
            fail("Shouldn't be able to load an Excel 4 file");
591
            fail("Shouldn't be able to load an Excel 4 file");
578
        } catch (OldExcelFormatException e) {
592
        } catch (OldExcelFormatException e) {
579
            assertContains(e.getMessage(), "BIFF4");
593
            assertContains(e.getMessage(), "BIFF4");
Lines 582-588 Link Here
582
        
596
        
583
        InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls");
597
        InputStream excel5 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_5.xls");
584
        try {
598
        try {
585
            new HSSFWorkbook(excel5);
599
            new HSSFWorkbook(excel5).close();
586
            fail("Shouldn't be able to load an Excel 5 file");
600
            fail("Shouldn't be able to load an Excel 5 file");
587
        } catch (OldExcelFormatException e) {
601
        } catch (OldExcelFormatException e) {
588
            assertContains(e.getMessage(), "BIFF5");
602
            assertContains(e.getMessage(), "BIFF5");
Lines 591-597 Link Here
591
        
605
        
592
        InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls");
606
        InputStream excel95 = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("testEXCEL_95.xls");
593
        try {
607
        try {
594
            new HSSFWorkbook(excel95);
608
            new HSSFWorkbook(excel95).close();
595
            fail("Shouldn't be able to load an Excel 95 file");
609
            fail("Shouldn't be able to load an Excel 95 file");
596
        } catch (OldExcelFormatException e) {
610
        } catch (OldExcelFormatException e) {
597
            assertContains(e.getMessage(), "BIFF5");
611
            assertContains(e.getMessage(), "BIFF5");
(-)poi/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java (-70 / +82 lines)
Lines 30-35 Link Here
30
import java.io.IOException;
30
import java.io.IOException;
31
import java.nio.ByteBuffer;
31
import java.nio.ByteBuffer;
32
import java.util.Iterator;
32
import java.util.Iterator;
33
import java.util.Set;
33
34
34
import org.apache.poi.POIDataSamples;
35
import org.apache.poi.POIDataSamples;
35
import org.apache.poi.hpsf.DocumentSummaryInformation;
36
import org.apache.poi.hpsf.DocumentSummaryInformation;
Lines 42-47 Link Here
42
import org.apache.poi.poifs.property.RootProperty;
43
import org.apache.poi.poifs.property.RootProperty;
43
import org.apache.poi.poifs.storage.HeaderBlock;
44
import org.apache.poi.poifs.storage.HeaderBlock;
44
import org.apache.poi.util.IOUtils;
45
import org.apache.poi.util.IOUtils;
46
import org.hamcrest.Matcher;
45
import org.junit.Test;
47
import org.junit.Test;
46
48
47
/**
49
/**
Lines 673-683 Link Here
673
           // Check we can find the entries we expect
675
           // Check we can find the entries we expect
674
           root = fs.getRoot();
676
           root = fs.getRoot();
675
           assertEquals(5, root.getEntryCount());
677
           assertEquals(5, root.getEntryCount());
676
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
678
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
677
           assertThat(root.getEntryNames(), hasItem("Image"));
679
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
678
           assertThat(root.getEntryNames(), hasItem("Tags"));
680
           assertThat(root.getEntryNames(), hasItemUpper("Tags"));
679
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
681
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
680
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
682
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
681
683
682
           
684
           
683
           // Write out, re-load
685
           // Write out, re-load
Lines 686-696 Link Here
686
           // Check they're still there
688
           // Check they're still there
687
           root = fs.getRoot();
689
           root = fs.getRoot();
688
           assertEquals(5, root.getEntryCount());
690
           assertEquals(5, root.getEntryCount());
689
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
691
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
690
           assertThat(root.getEntryNames(), hasItem("Image"));
692
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
691
           assertThat(root.getEntryNames(), hasItem("Tags"));
693
           assertThat(root.getEntryNames(), hasItemUpper("Tags"));
692
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
694
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
693
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
695
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
694
           
696
           
695
           
697
           
696
           // Check the contents of them - parse the summary block and check
698
           // Check the contents of them - parse the summary block and check
Lines 717-728 Link Here
717
           root = fs.getRoot();
719
           root = fs.getRoot();
718
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
720
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
719
           assertEquals(6, root.getEntryCount());
721
           assertEquals(6, root.getEntryCount());
720
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
722
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
721
           assertThat(root.getEntryNames(), hasItem("Image"));
723
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
722
           assertThat(root.getEntryNames(), hasItem("Tags"));
724
           assertThat(root.getEntryNames(), hasItemUpper("Tags"));
723
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
725
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
724
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
726
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
725
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
727
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
726
728
727
           
729
           
728
           // Check old and new are there
730
           // Check old and new are there
Lines 743-754 Link Here
743
           root = fs.getRoot();
745
           root = fs.getRoot();
744
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
746
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
745
           assertEquals(6, root.getEntryCount());
747
           assertEquals(6, root.getEntryCount());
746
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
748
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
747
           assertThat(root.getEntryNames(), hasItem("Image"));
749
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
748
           assertThat(root.getEntryNames(), hasItem("Tags"));
750
           assertThat(root.getEntryNames(), hasItemUpper("Tags"));
749
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
751
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
750
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
752
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
751
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
753
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
752
754
753
           sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
755
           sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
754
                   (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
756
                   (DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
Lines 777-787 Link Here
777
           root = fs.getRoot();
779
           root = fs.getRoot();
778
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
780
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
779
           assertEquals(5, root.getEntryCount());
781
           assertEquals(5, root.getEntryCount());
780
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
782
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
781
           assertThat(root.getEntryNames(), hasItem("Image"));
783
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
782
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
784
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
783
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
785
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
784
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
786
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
785
787
786
           
788
           
787
           // Check old and new are there
789
           // Check old and new are there
Lines 810-826 Link Here
810
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
812
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
811
           
813
           
812
           assertEquals(5, root.getEntryCount());
814
           assertEquals(5, root.getEntryCount());
813
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
815
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
814
           assertThat(root.getEntryNames(), hasItem("Image"));
816
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
815
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
817
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
816
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
818
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
817
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
819
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
818
           
820
           
819
           assertEquals(4, testDir.getEntryCount());
821
           assertEquals(4, testDir.getEntryCount());
820
           assertThat(testDir.getEntryNames(), hasItem("Mini"));
822
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini"));
821
           assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
823
           assertThat(testDir.getEntryNames(), hasItemUpper("Normal4096"));
822
           assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
824
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing 789"));
823
           assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
825
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing ABC"));
824
           
826
           
825
           
827
           
826
           // Add another mini stream
828
           // Add another mini stream
Lines 834-851 Link Here
834
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
836
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
835
           
837
           
836
           assertEquals(5, root.getEntryCount());
838
           assertEquals(5, root.getEntryCount());
837
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
839
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
838
           assertThat(root.getEntryNames(), hasItem("Image"));
840
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
839
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
841
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
840
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
842
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
841
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
843
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
842
           
844
           
843
           assertEquals(5, testDir.getEntryCount());
845
           assertEquals(5, testDir.getEntryCount());
844
           assertThat(testDir.getEntryNames(), hasItem("Mini"));
846
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini"));
845
           assertThat(testDir.getEntryNames(), hasItem("Mini2"));
847
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini2"));
846
           assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
848
           assertThat(testDir.getEntryNames(), hasItemUpper("Normal4096"));
847
           assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
849
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing 789"));
848
           assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
850
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing ABC"));
849
851
850
           assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
852
           assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
851
           assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
853
           assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
Lines 866-883 Link Here
866
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
868
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
867
           
869
           
868
           assertEquals(5, root.getEntryCount());
870
           assertEquals(5, root.getEntryCount());
869
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
871
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
870
           assertThat(root.getEntryNames(), hasItem("Image"));
872
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
871
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
873
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
872
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
874
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
873
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
875
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
874
           
876
           
875
           assertEquals(5, testDir.getEntryCount());
877
           assertEquals(5, testDir.getEntryCount());
876
           assertThat(testDir.getEntryNames(), hasItem("Mini2"));
878
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini2"));
877
           assertThat(testDir.getEntryNames(), hasItem("Mini3"));
879
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini3"));
878
           assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
880
           assertThat(testDir.getEntryNames(), hasItemUpper("Normal4096"));
879
           assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
881
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing 789"));
880
           assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
882
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing ABC"));
881
883
882
           assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
884
           assertContentsMatches(mini2, (DocumentEntry)testDir.getEntry("Mini2"));
883
           assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
885
           assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
Lines 902-919 Link Here
902
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
904
           testDir = (DirectoryEntry)root.getEntry("Testing 123");
903
           
905
           
904
           assertEquals(5, root.getEntryCount());
906
           assertEquals(5, root.getEntryCount());
905
           assertThat(root.getEntryNames(), hasItem("Thumbnail"));
907
           assertThat(root.getEntryNames(), hasItemUpper("Thumbnail"));
906
           assertThat(root.getEntryNames(), hasItem("Image"));
908
           assertThat(root.getEntryNames(), hasItemUpper("Image"));
907
           assertThat(root.getEntryNames(), hasItem("Testing 123"));
909
           assertThat(root.getEntryNames(), hasItemUpper("Testing 123"));
908
           assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
910
           assertThat(root.getEntryNames(), hasItemUpper("\u0005DocumentSummaryInformation"));
909
           assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
911
           assertThat(root.getEntryNames(), hasItemUpper("\u0005SummaryInformation"));
910
           
912
           
911
           assertEquals(5, testDir.getEntryCount());
913
           assertEquals(5, testDir.getEntryCount());
912
           assertThat(testDir.getEntryNames(), hasItem("Mini2"));
914
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini2"));
913
           assertThat(testDir.getEntryNames(), hasItem("Mini3"));
915
           assertThat(testDir.getEntryNames(), hasItemUpper("Mini3"));
914
           assertThat(testDir.getEntryNames(), hasItem("Normal4096"));
916
           assertThat(testDir.getEntryNames(), hasItemUpper("Normal4096"));
915
           assertThat(testDir.getEntryNames(), hasItem("Testing 789"));
917
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing 789"));
916
           assertThat(testDir.getEntryNames(), hasItem("Testing ABC"));
918
           assertThat(testDir.getEntryNames(), hasItemUpper("Testing ABC"));
917
919
918
           assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini2"));
920
           assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini2"));
919
           assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
921
           assertContentsMatches(mini3, (DocumentEntry)testDir.getEntry("Mini3"));
Lines 925-931 Link Here
925
       }
927
       }
926
   }
928
   }
927
   
929
   
928
   /**
930
   private Matcher<? super Set<String>> hasItemUpper(String string) {
931
       return hasItem(string.toUpperCase());
932
   }
933
934
/**
929
    * Create a new file, write it and read it again
935
    * Create a new file, write it and read it again
930
    * Then, add some streams, write and read
936
    * Then, add some streams, write and read
931
    */
937
    */
Lines 1410-1417 Link Here
1410
       
1416
       
1411
       
1417
       
1412
       // Save and re-check
1418
       // Save and re-check
1413
       fs = writeOutAndReadBack(fs);
1419
       NPOIFSFileSystem fsBack = writeOutAndReadBack(fs);
1414
       testDir = fs.getRoot();
1420
1421
       fs.close();
1422
       fs = null;
1423
       
1424
       testDir = fsBack.getRoot();
1415
       
1425
       
1416
       miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
1426
       miniDoc = (DocumentEntry)testDir.getEntry("Mini2");
1417
       assertContentsMatches(mini2, miniDoc);
1427
       assertContentsMatches(mini2, miniDoc);
Lines 1433-1439 Link Here
1433
       assertEquals(64, testDir.getProperty().getSize()); 
1443
       assertEquals(64, testDir.getProperty().getSize()); 
1434
       
1444
       
1435
       // All done
1445
       // All done
1436
       fs.close();
1446
       fsBack.close();
1437
   }
1447
   }
1438
1448
1439
   /**
1449
   /**
Lines 1458-1462 Link Here
1458
       byte wbDataAct[] = IOUtils.toByteArray(pfs.createDocumentInputStream("Workbook"));
1468
       byte wbDataAct[] = IOUtils.toByteArray(pfs.createDocumentInputStream("Workbook"));
1459
       
1469
       
1460
       assertThat(wbDataExp, equalTo(wbDataAct));
1470
       assertThat(wbDataExp, equalTo(wbDataAct));
1471
       
1472
       pfs.close();
1461
   }
1473
   }
1462
}
1474
}
(-)poi/src/java/org/apache/poi/poifs/filesystem/DirectoryNode.java (-10 / +10 lines)
Lines 130-136 Link Here
130
                childNode = new DocumentNode((DocumentProperty) child, this);
130
                childNode = new DocumentNode((DocumentProperty) child, this);
131
            }
131
            }
132
            _entries.add(childNode);
132
            _entries.add(childNode);
133
            _byname.put(childNode.getName(), childNode);
133
            _byname.put(childNode.getName().toUpperCase(), childNode);
134
        }
134
        }
135
    }
135
    }
136
136
Lines 230-236 Link Here
230
        _ofilesystem.addDocument(document);
230
        _ofilesystem.addDocument(document);
231
231
232
        _entries.add(rval);
232
        _entries.add(rval);
233
        _byname.put(property.getName(), rval);
233
        _byname.put(property.getName().toUpperCase(), rval);
234
        return rval;
234
        return rval;
235
    }
235
    }
236
236
Lines 253-259 Link Here
253
        _nfilesystem.addDocument(document);
253
        _nfilesystem.addDocument(document);
254
254
255
        _entries.add(rval);
255
        _entries.add(rval);
256
        _byname.put(property.getName(), rval);
256
        _byname.put(property.getName().toUpperCase(), rval);
257
        return rval;
257
        return rval;
258
    }
258
    }
259
259
Lines 268-274 Link Here
268
    boolean changeName(final String oldName, final String newName)
268
    boolean changeName(final String oldName, final String newName)
269
    {
269
    {
270
        boolean   rval  = false;
270
        boolean   rval  = false;
271
        EntryNode child = ( EntryNode ) _byname.get(oldName);
271
        EntryNode child = ( EntryNode ) _byname.get(oldName.toUpperCase());
272
272
273
        if (child != null)
273
        if (child != null)
274
        {
274
        {
Lines 276-283 Link Here
276
                .changeName(child.getProperty(), newName);
276
                .changeName(child.getProperty(), newName);
277
            if (rval)
277
            if (rval)
278
            {
278
            {
279
                _byname.remove(oldName);
279
                _byname.remove(oldName.toUpperCase());
280
                _byname.put(child.getProperty().getName(), child);
280
                _byname.put(child.getProperty().getName().toUpperCase(), child);
281
            }
281
            }
282
        }
282
        }
283
        return rval;
283
        return rval;
Lines 300-306 Link Here
300
        if (rval)
300
        if (rval)
301
        {
301
        {
302
            _entries.remove(entry);
302
            _entries.remove(entry);
303
            _byname.remove(entry.getName());
303
            _byname.remove(entry.getName().toUpperCase());
304
304
305
            if(_ofilesystem != null) {
305
            if(_ofilesystem != null) {
306
                _ofilesystem.remove(entry);
306
                _ofilesystem.remove(entry);
Lines 373-379 Link Here
373
373
374
    public boolean hasEntry( String name )
374
    public boolean hasEntry( String name )
375
    {
375
    {
376
        return name != null && _byname.containsKey( name );
376
        return name != null && _byname.containsKey( name.toUpperCase() );
377
    }
377
    }
378
378
379
    /**
379
    /**
Lines 392-398 Link Here
392
        Entry rval = null;
392
        Entry rval = null;
393
393
394
        if (name != null) {
394
        if (name != null) {
395
            rval = _byname.get(name);
395
            rval = _byname.get(name.toUpperCase());
396
        }
396
        }
397
        if (rval == null) {
397
        if (rval == null) {
398
            // either a null name was given, or there is no such name
398
            // either a null name was given, or there is no such name
Lines 474-480 Link Here
474
474
475
        (( DirectoryProperty ) getProperty()).addChild(property);
475
        (( DirectoryProperty ) getProperty()).addChild(property);
476
        _entries.add(rval);
476
        _entries.add(rval);
477
        _byname.put(name, rval);
477
        _byname.put(name.toUpperCase(), rval);
478
        return rval;
478
        return rval;
479
    }
479
    }
480
480

Return to bug 47950