You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/05/19 08:35:32 UTC

svn commit: r657731 [5/5] - in /poi/tags/REL_3_1_BETA2/src: contrib/src/org/apache/poi/hssf/usermodel/contrib/ documentation/ documentation/content/xdocs/ documentation/content/xdocs/hssf/ java/org/apache/poi/hssf/dev/ java/org/apache/poi/hssf/model/ j...

Modified: poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java?rev=657731&r1=657730&r2=657731&view=diff
==============================================================================
--- poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (original)
+++ poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java Sun May 18 23:35:30 2008
@@ -23,6 +23,7 @@
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 
+import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -193,17 +194,29 @@
 	public void testCloneSheet() {
 		HSSFWorkbook workbook = new HSSFWorkbook();
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
-		HSSFRow row = sheet.createRow((short) 0);
+		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test"); 
-		HSSFSheet cloned = workbook.cloneSheet(0);
-  
+		HSSFCell cell2 = row.createCell((short) 1);
+		cell.setCellValue(new HSSFRichTextString("clone_test")); 
+		cell2.setCellFormula("sin(1)"); 
+
+		HSSFSheet clonedSheet = workbook.cloneSheet(0);
+		HSSFRow clonedRow = clonedSheet.getRow(0);
+
 		//Check for a good clone
-		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+		assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
 
 		//Check that the cells are not somehow linked
-		cell.setCellValue("Difference Check");
-		assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
+		cell.setCellValue(new HSSFRichTextString("Difference Check"));
+		cell2.setCellFormula("cos(2)");
+		if ("Difference Check".equals(clonedRow.getCell(0).getRichStringCellValue().getString())) {
+			fail("string cell not properly cloned");
+		}
+		if ("COS(2)".equals(clonedRow.getCell(1).getCellFormula())) {
+			fail("formula cell not properly cloned");
+		}
+		assertEquals(clonedRow.getCell(0).getRichStringCellValue().getString(), "clone_test");
+		assertEquals(clonedRow.getCell(1).getCellFormula(), "SIN(1)");
 	}
 
 	/** tests that the sheet name for multiple clones of the same sheet is unique
@@ -214,7 +227,7 @@
 		HSSFSheet sheet = workbook.createSheet("Test Clone");
 		HSSFRow row = sheet.createRow((short) 0);
 		HSSFCell cell = row.createCell((short) 0);
-		cell.setCellValue("clone_test");
+		cell.setCellValue(new HSSFRichTextString("clone_test"));
 		//Clone the sheet multiple times
 		workbook.cloneSheet(0);
 		workbook.cloneSheet(0);
@@ -517,11 +530,11 @@
 		HSSFSheet sheet = wb.createSheet();
 		HSSFRow row = sheet.createRow(0);
 		HSSFCell cell = row.createCell((short)0);
-		cell.setCellValue("first row, first cell");
+		cell.setCellValue(new HSSFRichTextString("first row, first cell"));
 
 		row = sheet.createRow(1);
 		cell = row.createCell((short)1);
-		cell.setCellValue("second row, second cell");
+		cell.setCellValue(new HSSFRichTextString("second row, second cell"));
 
 		Region region = new Region(1, (short)0, 1, (short)1);   
 		sheet.addMergedRegion(region);
@@ -643,28 +656,28 @@
 
 	/** cell with formula becomes null on cloning a sheet*/
 	 public void test35084() {
-   
-   	HSSFWorkbook wb = new HSSFWorkbook();
-   	HSSFSheet s =wb.createSheet("Sheet1");
-   	HSSFRow r = s.createRow(0);
-   	r.createCell((short)0).setCellValue(1);
-   	r.createCell((short)1).setCellFormula("A1*2");
-   	HSSFSheet s1 = wb.cloneSheet(0);
-   	r=s1.getRow(0);
-   	assertEquals("double" ,r.getCell((short)0).getNumericCellValue(),(double)1,0); //sanity check
-   	assertNotNull(r.getCell((short)1)); 
-   	assertEquals("formula", r.getCell((short)1).getCellFormula(), "A1*2");
-   }
+
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFSheet s = wb.createSheet("Sheet1");
+		HSSFRow r = s.createRow(0);
+		r.createCell((short) 0).setCellValue(1);
+		r.createCell((short) 1).setCellFormula("A1*2");
+		HSSFSheet s1 = wb.cloneSheet(0);
+		r = s1.getRow(0);
+		assertEquals("double", r.getCell((short) 0).getNumericCellValue(), 1, 0); // sanity check
+		assertNotNull(r.getCell((short) 1));
+		assertEquals("formula", r.getCell((short) 1).getCellFormula(), "A1*2");
+	}
 
 	/** test that new default column styles get applied */
 	public void testDefaultColumnStyle() {
-	HSSFWorkbook wb = new HSSFWorkbook();
-	HSSFCellStyle style = wb.createCellStyle();
-	HSSFSheet s = wb.createSheet();
-	s.setDefaultColumnStyle((short)0, style);
-	HSSFRow r = s.createRow(0);
-	HSSFCell c = r.createCell((short)0);
-	assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
+		HSSFWorkbook wb = new HSSFWorkbook();
+		HSSFCellStyle style = wb.createCellStyle();
+		HSSFSheet s = wb.createSheet();
+		s.setDefaultColumnStyle((short) 0, style);
+		HSSFRow r = s.createRow(0);
+		HSSFCell c = r.createCell((short) 0);
+		assertEquals("style should match", style.getIndex(), c.getCellStyle().getIndex());
 	}
 
 
@@ -814,11 +827,6 @@
 		assertTrue(wb3.getSheetAt(3).getForceFormulaRecalculation());
 	}
 
-
-	public static void main(java.lang.String[] args) {
-		 junit.textui.TestRunner.run(TestHSSFSheet.class);
-	}
-
 	public void testColumnWidth() throws Exception {
 		//check we can correctly read column widths from a reference workbook
 		HSSFWorkbook wb = openSample("colwidth.xls");
@@ -870,11 +878,33 @@
 		assertEquals(256*10, sh.getColumnWidth((short)0));
 		assertEquals(256*10, sh.getColumnWidth((short)1));
 		assertEquals(256*10, sh.getColumnWidth((short)2));
-		//columns D-F have custom wodth
+		//columns D-F have custom width
 		for (char i = 'D'; i <= 'F'; i++) {
 			short w = (short)(256*12);
 			assertEquals(w, sh.getColumnWidth((short)i));
 		}
+	}
+	
+	/**
+	 * Some utilities write Excel files without the ROW records.
+	 * Excel, ooo, and google docs are OK with this.
+	 * Now POI is too.
+	 */
+	public void testMissingRowRecords_bug41187() {
+		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex41187-19267.xls");
 
+		HSSFSheet sheet = wb.getSheetAt(0);
+		HSSFRow row = sheet.getRow(0);
+		if(row == null) {
+			throw new AssertionFailedError("Identified bug 41187 a");
+		}
+		if (row.getHeight() == 0) {
+			throw new AssertionFailedError("Identified bug 41187 b");
+		}
+		assertEquals("Hi Excel!", row.getCell(0).getRichStringCellValue().getString());
+		// check row height for 'default' flag
+		assertEquals((short)0x8000, row.getHeight());
+		
+		HSSFTestDataSamples.writeOutAndReadBack(wb);
 	}
 }

Modified: poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java?rev=657731&r1=657730&r2=657731&view=diff
==============================================================================
--- poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java (original)
+++ poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java Sun May 18 23:35:30 2008
@@ -17,13 +17,18 @@
 
 package org.apache.poi.hssf.usermodel;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.hssf.record.NameRecord;
+import org.apache.poi.util.TempFile;
 /**
- * 
+ *
  */
 public final class TestHSSFWorkbook extends TestCase {
     private static HSSFWorkbook openSample(String sampleFileName) {
@@ -93,7 +98,7 @@
         b.setSheetName( 3,  "name2" );
         b.setSheetName( 3,  "name2" );
         b.setSheetName( 3,  "name2" );
-        
+
         HSSFWorkbook c = new HSSFWorkbook( );
         c.createSheet("Sheet1");
         c.createSheet("Sheet2");
@@ -101,109 +106,274 @@
         c.createSheet("Sheet4");
 
     }
-    
+
     public void testWindowOneDefaults() {
         HSSFWorkbook b = new HSSFWorkbook( );
         try {
-            assertEquals(b.getSelectedTab(), 0);
-            assertEquals(b.getDisplayedTab(), 0);
+            assertEquals(b.getActiveSheetIndex(), 0);
+            assertEquals(b.getFirstVisibleTab(), 0);
         } catch (NullPointerException npe) {
             fail("WindowOneRecord in Workbook is probably not initialized");
         }
     }
-    
+
     public void testSheetSelection() {
         HSSFWorkbook b = new HSSFWorkbook();
         b.createSheet("Sheet One");
         b.createSheet("Sheet Two");
-        b.setSelectedTab((short) 1);
-        b.setDisplayedTab((short) 1);
-        assertEquals(b.getSelectedTab(), 1);
-        assertEquals(b.getDisplayedTab(), 1);
+        b.setActiveSheet(1);
+        b.setSelectedTab(1);
+        b.setFirstVisibleTab(1);
+        assertEquals(1, b.getActiveSheetIndex());
+        assertEquals(1, b.getFirstVisibleTab());
     }
-    
+
     public void testSheetClone() {
         // First up, try a simple file
         HSSFWorkbook b = new HSSFWorkbook();
         assertEquals(0, b.getNumberOfSheets());
         b.createSheet("Sheet One");
         b.createSheet("Sheet Two");
-        
+
         assertEquals(2, b.getNumberOfSheets());
         b.cloneSheet(0);
         assertEquals(3, b.getNumberOfSheets());
-        
+
         // Now try a problem one with drawing records in it
         b = openSample("SheetWithDrawing.xls");
         assertEquals(1, b.getNumberOfSheets());
         b.cloneSheet(0);
         assertEquals(2, b.getNumberOfSheets());
     }
-    
+
     public void testReadWriteWithCharts() {
         HSSFWorkbook b;
         HSSFSheet s;
-        
+
         // Single chart, two sheets
         b = openSample("44010-SingleChart.xls");
         assertEquals(2, b.getNumberOfSheets());
+        assertEquals("Graph2", b.getSheetName(1));
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
-        
+        assertEquals(8, s.getLastRowNum());
+
         // Has chart on 1st sheet??
         // FIXME
         assertNotNull(b.getSheetAt(0).getDrawingPatriarch());
         assertNull(b.getSheetAt(1).getDrawingPatriarch());
         assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart());
-        
-        // We've now called getDrawingPatriarch() so 
+
+        // We've now called getDrawingPatriarch() so
         //  everything will be all screwy
         // So, start again
         b = openSample("44010-SingleChart.xls");
-        
+
         b = writeRead(b);
         assertEquals(2, b.getNumberOfSheets());
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
+
 
-        
         // Two charts, three sheets
         b = openSample("44010-TwoCharts.xls");
         assertEquals(3, b.getNumberOfSheets());
-        
+
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
-        
+        assertEquals(8, s.getLastRowNum());
+
         // Has chart on 1st sheet??
         // FIXME
         assertNotNull(b.getSheetAt(0).getDrawingPatriarch());
         assertNull(b.getSheetAt(1).getDrawingPatriarch());
         assertNull(b.getSheetAt(2).getDrawingPatriarch());
         assertFalse(b.getSheetAt(0).getDrawingPatriarch().containsChart());
-        
-        // We've now called getDrawingPatriarch() so 
+
+        // We've now called getDrawingPatriarch() so
         //  everything will be all screwy
         // So, start again
         b = openSample("44010-TwoCharts.xls");
-        
+
         b = writeRead(b);
         assertEquals(3, b.getNumberOfSheets());
-        
+
         s = b.getSheetAt(1);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
         s = b.getSheetAt(2);
         assertEquals(0, s.getFirstRowNum());
-        assertEquals(0, s.getLastRowNum());
+        assertEquals(8, s.getLastRowNum());
     }
-    
+
     private static HSSFWorkbook writeRead(HSSFWorkbook b) {
-    	return HSSFTestDataSamples.writeOutAndReadBack(b);
+        return HSSFTestDataSamples.writeOutAndReadBack(b);
+    }
+
+
+    public void testSelectedSheet_bug44523() {
+        HSSFWorkbook wb=new HSSFWorkbook();
+        HSSFSheet sheet1 = wb.createSheet("Sheet1");
+        HSSFSheet sheet2 = wb.createSheet("Sheet2");
+        HSSFSheet sheet3 = wb.createSheet("Sheet3");
+        HSSFSheet sheet4 = wb.createSheet("Sheet4");
+
+        confirmActiveSelected(sheet1, true);
+        confirmActiveSelected(sheet2, false);
+        confirmActiveSelected(sheet3, false);
+        confirmActiveSelected(sheet4, false);
+
+        wb.setSelectedTab(1);
+
+        // Demonstrate bug 44525:
+        // Well... not quite, since isActive + isSelected were also added in the same bug fix
+        if (sheet1.isSelected()) {
+            throw new AssertionFailedError("Identified bug 44523 a");
+        }
+        wb.setActiveSheet(1);
+        if (sheet1.isActive()) {
+            throw new AssertionFailedError("Identified bug 44523 b");
+        }
+
+        confirmActiveSelected(sheet1, false);
+        confirmActiveSelected(sheet2, true);
+        confirmActiveSelected(sheet3, false);
+        confirmActiveSelected(sheet4, false);
+    }
+
+    public void testSelectMultiple() {
+        HSSFWorkbook wb=new HSSFWorkbook();
+        HSSFSheet sheet1 = wb.createSheet("Sheet1");
+        HSSFSheet sheet2 = wb.createSheet("Sheet2");
+        HSSFSheet sheet3 = wb.createSheet("Sheet3");
+        HSSFSheet sheet4 = wb.createSheet("Sheet4");
+        HSSFSheet sheet5 = wb.createSheet("Sheet5");
+        HSSFSheet sheet6 = wb.createSheet("Sheet6");
+
+        wb.setSelectedTabs(new int[] { 0, 2, 3});
+
+        assertEquals(true, sheet1.isSelected());
+        assertEquals(false, sheet2.isSelected());
+        assertEquals(true, sheet3.isSelected());
+        assertEquals(true, sheet4.isSelected());
+        assertEquals(false, sheet5.isSelected());
+        assertEquals(false, sheet6.isSelected());
+
+        wb.setSelectedTabs(new int[] { 1, 3, 5});
+
+        assertEquals(false, sheet1.isSelected());
+        assertEquals(true, sheet2.isSelected());
+        assertEquals(false, sheet3.isSelected());
+        assertEquals(true, sheet4.isSelected());
+        assertEquals(false, sheet5.isSelected());
+        assertEquals(true, sheet6.isSelected());
+
+        assertEquals(true, sheet1.isActive());
+        assertEquals(false, sheet2.isActive());
+
+
+        assertEquals(true, sheet1.isActive());
+        assertEquals(false, sheet3.isActive());
+        wb.setActiveSheet(2);
+        assertEquals(false, sheet1.isActive());
+        assertEquals(true, sheet3.isActive());
+
+        if (false) { // helpful if viewing this workbook in excel:
+            sheet1.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet1"));
+            sheet2.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet2"));
+            sheet3.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet3"));
+            sheet4.createRow(0).createCell((short)0).setCellValue(new HSSFRichTextString("Sheet4"));
+
+            try {
+                File fOut = TempFile.createTempFile("sheetMultiSelect", ".xls");
+                FileOutputStream os = new FileOutputStream(fOut);
+                wb.write(os);
+                os.close();
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
+    }
+
+
+    public void testActiveSheetAfterDelete_bug40414() {
+        HSSFWorkbook wb=new HSSFWorkbook();
+        HSSFSheet sheet0 = wb.createSheet("Sheet0");
+        HSSFSheet sheet1 = wb.createSheet("Sheet1");
+        HSSFSheet sheet2 = wb.createSheet("Sheet2");
+        HSSFSheet sheet3 = wb.createSheet("Sheet3");
+        HSSFSheet sheet4 = wb.createSheet("Sheet4");
+
+        // confirm default activation/selection
+        confirmActiveSelected(sheet0, true);
+        confirmActiveSelected(sheet1, false);
+        confirmActiveSelected(sheet2, false);
+        confirmActiveSelected(sheet3, false);
+        confirmActiveSelected(sheet4, false);
+
+        wb.setActiveSheet(3);
+        wb.setSelectedTab(3);
+
+        confirmActiveSelected(sheet0, false);
+        confirmActiveSelected(sheet1, false);
+        confirmActiveSelected(sheet2, false);
+        confirmActiveSelected(sheet3, true);
+        confirmActiveSelected(sheet4, false);
+
+        wb.removeSheetAt(3);
+        // after removing the only active/selected sheet, another should be active/selected in its place
+        if (!sheet4.isSelected()) {
+            throw new AssertionFailedError("identified bug 40414 a");
+        }
+        if (!sheet4.isActive()) {
+            throw new AssertionFailedError("identified bug 40414 b");
+        }
+
+        confirmActiveSelected(sheet0, false);
+        confirmActiveSelected(sheet1, false);
+        confirmActiveSelected(sheet2, false);
+        confirmActiveSelected(sheet4, true);
+
+        sheet3 = sheet4; // re-align local vars in this test case
+
+        // Some more cases of removing sheets
+
+        // Starting with a multiple selection, and different active sheet
+        wb.setSelectedTabs(new int[] { 1, 3, });
+        wb.setActiveSheet(2);
+        confirmActiveSelected(sheet0, false, false);
+        confirmActiveSelected(sheet1, false, true);
+        confirmActiveSelected(sheet2, true,  false);
+        confirmActiveSelected(sheet3, false, true);
+
+        // removing a sheet that is not active, and not the only selected sheet
+        wb.removeSheetAt(3);
+        confirmActiveSelected(sheet0, false, false);
+        confirmActiveSelected(sheet1, false, true);
+        confirmActiveSelected(sheet2, true,  false);
+
+        // removing the only selected sheet
+        wb.removeSheetAt(1);
+        confirmActiveSelected(sheet0, false, false);
+        confirmActiveSelected(sheet2, true,  true);
+
+        // The last remaining sheet should always be active+selected
+        wb.removeSheetAt(1);
+        confirmActiveSelected(sheet0, true,  true);
+    }
+
+    private static void confirmActiveSelected(HSSFSheet sheet, boolean expected) {
+        confirmActiveSelected(sheet, expected, expected);
+    }
+
+
+    private static void confirmActiveSelected(HSSFSheet sheet,
+            boolean expectedActive, boolean expectedSelected) {
+        assertEquals("active", expectedActive, sheet.isActive());
+        assertEquals("selected", expectedSelected, sheet.isSelected());
     }
-}
\ No newline at end of file
+}

Modified: poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java?rev=657731&r1=657730&r2=657731&view=diff
==============================================================================
--- poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java (original)
+++ poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/hssf/usermodel/TestNamedRange.java Sun May 18 23:35:30 2008
@@ -533,4 +533,28 @@
 		String contents = c.getStringCellValue();
 		assertEquals("Contents of cell retrieved by its named reference", contents, cvalue);
 	}
+
+    public void testDeletedReference() throws Exception {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("24207.xls");
+        assertEquals(2, wb.getNumberOfNames());
+
+        HSSFName name1 = wb.getNameAt(0);
+        assertEquals("a", name1.getNameName());
+        assertEquals("Sheet1!$A$1", name1.getReference());
+        AreaReference ref1 = new AreaReference(name1.getReference());
+        assertTrue("Successfully constructed first reference", true);
+
+        HSSFName name2 = wb.getNameAt(1);
+        assertEquals("b", name2.getNameName());
+        assertEquals("#REF!", name2.getReference());
+        assertTrue(name2.isDeleted());
+        try {
+            AreaReference ref2 = new AreaReference(name2.getReference());
+            fail("attempt to supply an invalid reference to AreaReference constructor results in exception");
+        } catch (Exception e){
+            ;
+        }
+
+    }
+
 }

Modified: poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java?rev=657731&r1=657730&r2=657731&view=diff
==============================================================================
--- poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java (original)
+++ poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSFileSystem.java Sun May 18 23:35:30 2008
@@ -17,6 +17,9 @@
 
 package org.apache.poi.poifs.filesystem;
 
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
@@ -115,6 +118,40 @@
 		assertTrue("input stream was not closed", testIS.isClosed()); // but still should close
 		
 	}
+	
+	/**
+	 * 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
+	 */
+	public void DISABLEDtestShortLastBlock() throws Exception {
+		String[] files = new String[] {
+			"ShortLastBlock.qwp", "ShortLastBlock.wps"	
+		};
+		String pdirname = System.getProperty("POIFS.testdata.path");
+
+		for(int i=0; i<files.length; i++) {
+			File f = new File(pdirname, files[i]);
+			assertTrue(f.exists());
+			
+			// Open the file up
+			POIFSFileSystem fs = new POIFSFileSystem(
+					new FileInputStream(f)
+			);
+			
+			// Write it into a temp output array
+			ByteArrayOutputStream baos = new ByteArrayOutputStream();
+			fs.writeFilesystem(baos);
+			
+			// Check sizes
+		}
+	}
 
 	private static InputStream openSampleStream(String sampleFileName) {
 		return HSSFTestDataSamples.openSampleFileStream(sampleFileName);

Modified: poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java?rev=657731&r1=657730&r2=657731&view=diff
==============================================================================
--- poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (original)
+++ poi/tags/REL_3_1_BETA2/src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java Sun May 18 23:35:30 2008
@@ -152,7 +152,7 @@
 	            }
 	            
 	            assertEquals(
-	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document has probably been truncated!", 
+	            		"7 - Unable to read entire block; "+bts+" read before EOF; expected 512 bytes. Your document was either written by software that ignores the spec, or has been truncated!", 
 	            		(String)(logger.logged.get(0))
 	            );
             } else {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org