Removed unused imports under src/java and src/testcases. Other minor fixes.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@888653 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-12-09 00:12:32 +00:00
parent 0c3c85a152
commit 2ddd88ed0d
11 changed files with 99 additions and 135 deletions

View File

@ -21,12 +21,10 @@ import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingCellDummyRecord;
import org.apache.poi.hssf.eventusermodel.dummyrecord.MissingRowDummyRecord;
import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.MulBlankRecord;
import org.apache.poi.hssf.record.MulRKRecord;
import org.apache.poi.hssf.record.NoteRecord;
import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordFactory;
import org.apache.poi.hssf.record.RowRecord;
@ -44,15 +42,15 @@ import org.apache.poi.hssf.record.SharedFormulaRecord;
*/
public final class MissingRecordAwareHSSFListener implements HSSFListener {
private HSSFListener childListener;
// Need to have different counters for cell rows and
// row rows, as you sometimes get a RowRecord in the
// middle of some cells, and that'd break everything
private int lastRowRow;
private int lastCellRow;
private int lastCellColumn;
/**
* Constructs a new MissingRecordAwareHSSFListener, which
* will fire processRecord on the supplied child
@ -130,15 +128,15 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
break;
}
}
// First part of expanded record handling
if(expandedRecords != null && expandedRecords.length > 0) {
thisRow = expandedRecords[0].getRow();
thisColumn = expandedRecords[0].getColumn();
}
// If we're on cells, and this cell isn't in the same
// row as the last one, then fire the
// row as the last one, then fire the
// dummy end-of-row records
if(thisRow != lastCellRow && lastCellRow > -1) {
for(int i=lastCellRow; i<thisRow; i++) {
@ -149,22 +147,22 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
childListener.processRecord(new LastCellOfRowDummyRecord(i, cols));
}
}
// If we've just finished with the cells, then fire the
// final dummy end-of-row record
if(lastCellRow != -1 && lastCellColumn != -1 && thisRow == -1) {
childListener.processRecord(new LastCellOfRowDummyRecord(lastCellRow, lastCellColumn));
lastCellRow = -1;
lastCellColumn = -1;
}
// If we've moved onto a new row, the ensure we re-set
// the column counter
if(thisRow != lastCellRow) {
lastCellColumn = -1;
}
// If there's a gap in the cells, then fire
// the dummy cell records
if(lastCellColumn != thisColumn-1) {
@ -172,13 +170,13 @@ public final class MissingRecordAwareHSSFListener implements HSSFListener {
childListener.processRecord(new MissingCellDummyRecord(thisRow, i));
}
}
// Next part of expanded record handling
if(expandedRecords != null && expandedRecords.length > 0) {
thisColumn = expandedRecords[expandedRecords.length-1].getColumn();
}
// Update cell and row counts as needed
if(thisColumn != -1) {
lastCellColumn = thisColumn;

View File

@ -17,22 +17,14 @@
package org.apache.poi.hssf.usermodel;
import java.awt.Dimension;
import java.io.ByteArrayInputStream;
import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.util.ImageUtils;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Iterator;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
/**
* Represents a escher picture. Eg. A GIF, JPEG etc...
@ -65,8 +57,6 @@ public final class HSSFPicture extends HSSFSimpleShape implements Picture {
private int _pictureIndex;
HSSFPatriarch _patriarch; // TODO make private
private static final POILogger log = POILogFactory.getLogger(HSSFPicture.class);
/**
* Constructs a picture object.
*/

View File

@ -18,7 +18,6 @@
package org.apache.poi.ss.util;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
/**

View File

@ -17,15 +17,13 @@
package org.apache.poi.ddf;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.IOUtils;
import org.apache.poi.POIDataSamples;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.HexRead;
/**
* Tests for {@link EscherContainerRecord}

View File

@ -29,12 +29,9 @@ import junit.framework.TestCase;
import org.apache.poi.hpsf.CustomProperties;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.MarkUnsupportedException;
import org.apache.poi.hpsf.NoPropertySetStreamException;
import org.apache.poi.hpsf.PropertySet;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hpsf.UnexpectedPropertySetTypeException;
import org.apache.poi.hpsf.WritingNotSupportedException;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.DocumentEntry;
@ -605,9 +602,9 @@ public final class TestMetaDataIPI extends TestCase{
}
/**
/**
* Iterative testing of the unicode test
*
*
*/
public void testSix() {
for (int i = 1; i < 100; i++) {

View File

@ -17,25 +17,21 @@
package org.apache.poi.hpsf.extractor;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.extractor.ExcelExtractor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
public final class TestHPSFPropertiesExtractor extends TestCase {
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
private static final POIDataSamples _samples = POIDataSamples.getHPSFInstance();
public void testNormalProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
_samples.openResourceAsStream("TestMickey.doc")
);
POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestMickey.doc"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText();
@ -57,9 +53,7 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
}
public void testNormalUnicodeProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
_samples.openResourceAsStream("TestUnicode.xls")
);
POIFSFileSystem fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
ext.getText();
@ -82,8 +76,8 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
public void testCustomProperties() throws Exception {
POIFSFileSystem fs = new POIFSFileSystem(
_samples.openResourceAsStream("TestMickey.doc")
);
_samples.openResourceAsStream("TestMickey.doc")
);
HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(fs);
// Custom properties are part of the document info stream
@ -100,9 +94,7 @@ public final class TestHPSFPropertiesExtractor extends TestCase {
POIFSFileSystem fs;
HSSFWorkbook wb;
try {
fs = new POIFSFileSystem(
_samples.openResourceAsStream("TestUnicode.xls")
);
fs = new POIFSFileSystem(_samples.openResourceAsStream("TestUnicode.xls"));
wb = new HSSFWorkbook(fs);
} catch (IOException e) {
throw new RuntimeException(e);

View File

@ -17,18 +17,17 @@
package org.apache.poi.hssf.extractor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.POIDataSamples;
/**
*
@ -243,10 +242,10 @@ public final class TestExcelExtractor extends TestCase {
* Excel embeded in excel
*/
public void testWithEmbededInOwn() throws Exception {
POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
POIDataSamples ssSamples = POIDataSamples.getSpreadSheetInstance();
POIFSFileSystem fs = new POIFSFileSystem(
ssSamples.openResourceAsStream("excel_with_embeded.xls")
);
ssSamples.openResourceAsStream("excel_with_embeded.xls")
);
DirectoryNode dirA = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B5");
DirectoryNode dirB = (DirectoryNode) fs.getRoot().getEntry("MBD0000A3B4");

View File

@ -18,19 +18,17 @@
package org.apache.poi.hssf.record;
import junit.framework.TestCase;
import java.util.Arrays;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import junit.framework.TestCase;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.hssf.record.formula.AreaPtg;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.HexRead;
import org.apache.poi.util.LittleEndianInputStream;
import org.apache.poi.util.LittleEndianOutputStream;
/**
* Tests the serialization and deserialization of the LbsDataSubRecord class works correctly.
@ -167,4 +165,4 @@ public final class TestLbsDataSubRecord extends TestCase {
assertTrue(Arrays.equals(data, baos.toByteArray()));
}
}
}

View File

@ -22,7 +22,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.Offset.LinearOffsetRange;
/**

View File

@ -19,7 +19,6 @@ package org.apache.poi.hssf.usermodel;
import java.util.Date;
import java.util.GregorianCalendar;
import java.io.FileOutputStream;
import junit.framework.AssertionFailedError;
@ -29,10 +28,9 @@ import org.apache.poi.hssf.record.DBCellRecord;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.StringRecord;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.BaseTestCell;
import org.apache.poi.ss.usermodel.ErrorConstants;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.SpreadsheetVersion;
/**
* Tests various functionality having to do with {@link HSSFCell}. For instance support for
@ -42,9 +40,9 @@ import org.apache.poi.ss.SpreadsheetVersion;
* @author Alex Jacoby (ajacoby at gmail.com)
*/
public final class TestHSSFCell extends BaseTestCell {
private static final HSSFITestDataProvider _hssfDP = HSSFITestDataProvider.getInstance();
public TestHSSFCell() {
super(HSSFITestDataProvider.getInstance());
}
@ -64,7 +62,7 @@ public final class TestHSSFCell extends BaseTestCell {
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
sheet.getRow(0).getCell(0).getDateCellValue().getTime());
// now check a file with 1904 Date Windowing
workbook = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
sheet = workbook.getSheetAt(0);
@ -89,17 +87,17 @@ public final class TestHSSFCell extends BaseTestCell {
// first check a file with 1900 Date Windowing
HSSFWorkbook wb;
wb = _hssfDP.openSampleWorkbook("1900DateWindowing.xls");
setCell(wb, 0, 1, date);
wb = _hssfDP.writeOutAndReadBack(wb);
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
readCell(wb, 0, 1).getTime());
// now check a file with 1904 Date Windowing
wb = _hssfDP.openSampleWorkbook("1904DateWindowing.xls");
setCell(wb, 0, 1, date);
setCell(wb, 0, 1, date);
wb = _hssfDP.writeOutAndReadBack(wb);
assertEquals("Date from file using 1900 Date Windowing",
date.getTime(),
@ -110,27 +108,27 @@ public final class TestHSSFCell extends BaseTestCell {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(rowIdx);
HSSFCell cell = row.getCell(colIdx);
if (cell == null) {
cell = row.createCell(colIdx);
}
cell.setCellValue(date);
}
private static Date readCell(HSSFWorkbook workbook, int rowIdx, int colIdx) {
HSSFSheet sheet = workbook.getSheetAt(0);
HSSFRow row = sheet.getRow(rowIdx);
HSSFCell cell = row.getCell(colIdx);
return cell.getDateCellValue();
}
/**
* Tests that the active cell can be correctly read and set
*/
public void testActiveCell() {
//read in sample
HSSFWorkbook book = _hssfDP.openSampleWorkbook("Simple.xls");
//check initial position
HSSFSheet umSheet = book.getSheetAt(0);
Sheet s = umSheet.getSheet();
@ -138,7 +136,7 @@ public final class TestHSSFCell extends BaseTestCell {
(short) 0, s.getActiveCellCol());
assertEquals("Initial active cell should be on row 1",
1, s.getActiveCellRow());
//modify position through HSSFCell
HSSFCell cell = umSheet.createRow(3).createCell(2);
cell.setAsActiveCell();
@ -146,13 +144,13 @@ public final class TestHSSFCell extends BaseTestCell {
(short) 2, s.getActiveCellCol());
assertEquals("After modify, active cell should be on row 3",
3, s.getActiveCellRow());
//write book to temp file; read and verify that position is serialized
book = _hssfDP.writeOutAndReadBack(book);
umSheet = book.getSheetAt(0);
s = umSheet.getSheet();
assertEquals("After serialize, active cell should be in col 2",
(short) 2, s.getActiveCellCol());
assertEquals("After serialize, active cell should be on row 3",
@ -176,14 +174,14 @@ public final class TestHSSFCell extends BaseTestCell {
assertEquals(4, link.getFirstRow());
assertEquals(0, link.getFirstColumn());
}
/**
* Test reading hyperlinks
*/
public void testWithTwoHyperlinks() {
HSSFWorkbook wb = _hssfDP.openSampleWorkbook("WithTwoHyperLinks.xls");
HSSFSheet sheet = wb.getSheetAt(0);
HSSFCell cell1 = sheet.getRow(4).getCell(0);
@ -250,7 +248,7 @@ public final class TestHSSFCell extends BaseTestCell {
/**
* Test for small bug observable around r736460 (prior to version 3.5). POI fails to remove
* the {@link StringRecord} following the {@link FormulaRecord} after the result type had been
* the {@link StringRecord} following the {@link FormulaRecord} after the result type had been
* changed to number/boolean/error. Excel silently ignores the extra record, but some POI
* versions (prior to bug 46213 / r717883) crash instead.
*/
@ -266,13 +264,13 @@ public final class TestHSSFCell extends BaseTestCell {
throw new AssertionFailedError("Identified bug - leftover StringRecord");
}
confirmStringRecord(sheet, false);
// string to error code
cell.setCellValue("abc");
confirmStringRecord(sheet, true);
cell.setCellErrorValue((byte)ErrorConstants.ERROR_REF);
confirmStringRecord(sheet, false);
// string to boolean
cell.setCellValue("abc");
confirmStringRecord(sheet, true);
@ -295,33 +293,32 @@ public final class TestHSSFCell extends BaseTestCell {
assertEquals(DBCellRecord.class, dbcr.getClass());
}
/**
* The maximum length of cell contents (text) is 32,767 characters.
*/
public void testMaxTextLength(){
HSSFSheet sheet = new HSSFWorkbook().createSheet();
HSSFCell cell = sheet.createRow(0).createCell(0);
/**
* The maximum length of cell contents (text) is 32,767 characters.
*/
public void testMaxTextLength(){
HSSFSheet sheet = new HSSFWorkbook().createSheet();
HSSFCell cell = sheet.createRow(0).createCell(0);
int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength();
assertEquals(32767, maxlen);
int maxlen = SpreadsheetVersion.EXCEL97.getMaxTextLength();
assertEquals(32767, maxlen);
StringBuffer b = new StringBuffer() ;
StringBuffer b = new StringBuffer() ;
// 32767 is okay
for( int i = 0 ; i < maxlen ; i++ )
{
b.append( "X" ) ;
}
cell.setCellValue(b.toString());
// 32767 is okay
for( int i = 0 ; i < maxlen ; i++ )
{
b.append( "X" ) ;
}
cell.setCellValue(b.toString());
b.append("X");
// 32768 produces an invalid XLS file
try {
cell.setCellValue(b.toString());
fail("Expected exception");
} catch (IllegalArgumentException e){
assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage());
}
}
b.append("X");
// 32768 produces an invalid XLS file
try {
cell.setCellValue(b.toString());
fail("Expected exception");
} catch (IllegalArgumentException e){
assertEquals("The maximum length of cell contents (text) is 32,767 characters", e.getMessage());
}
}
}

View File

@ -18,19 +18,17 @@
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;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
/**
* Tests for POIFSFileSystem
*
*
* @author Josh Micich
*/
public final class TestPOIFSFileSystem extends TestCase {
@ -45,7 +43,7 @@ public final class TestPOIFSFileSystem extends TestCase {
}
/**
* Helps facilitate testing. Keeps track of whether close() was called.
* Also can throw an exception at a specific point in the stream.
* Also can throw an exception at a specific point in the stream.
*/
private static final class TestIS extends InputStream {
@ -88,15 +86,15 @@ public final class TestPOIFSFileSystem extends TestCase {
return _isClosed;
}
}
/**
* Test for undesired behaviour observable as of svn revision 618865 (5-Feb-2008).
* POIFSFileSystem was not closing the input stream.
*/
public void testAlwaysClose() {
TestIS testIS;
// Normal case - read until EOF and close
testIS = new TestIS(openSampleStream("13224.xls"), -1);
try {
@ -105,7 +103,7 @@ public final class TestPOIFSFileSystem extends TestCase {
throw new RuntimeException(e);
}
assertTrue("input stream was not closed", testIS.isClosed());
// intended to crash after reading 10000 bytes
testIS = new TestIS(openSampleStream("13224.xls"), 10000);
try {
@ -117,14 +115,13 @@ public final class TestPOIFSFileSystem extends TestCase {
// expected
}
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.
@ -133,21 +130,21 @@ public final class TestPOIFSFileSystem extends TestCase {
*/
public void testShortLastBlock() throws Exception {
String[] files = new String[] {
"ShortLastBlock.qwp", "ShortLastBlock.wps"
"ShortLastBlock.qwp", "ShortLastBlock.wps"
};
POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
for(int i=0; i<files.length; i++) {
POIDataSamples _samples = POIDataSamples.getPOIFSInstance();
for(int i=0; i<files.length; i++) {
// Open the file up
POIFSFileSystem fs = new POIFSFileSystem(
_samples.openResourceAsStream(files[i])
);
// Write it into a temp output array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fs.writeFilesystem(baos);
// Check sizes
}
}