Happy with that. I don't actually use the mains myself anyway. I just
modified it because it looked like a pre-apache thing.
Regards,
Glen
> Hi Glen,
>
> I'll be doing this as I see it anyhow but this:
>
> System.setProperty(
> "HSSF.testdata.path",
> "src/testcases/org/apache/poi/hssf/data");
>
> should read
>
> System.setProperty(
> "HSSF.testdata.path",
> args[0]);
>
> grabbing the first argument from the command prompt. -- Include sanity
> checks for was there no argument or property -- there are examples to do
> that, but you get the idea.
>
> -Andy
>
> [EMAIL PROTECTED] wrote:
>
> >glens 02/04/29 04:10:29
> >
> > Modified: src/java/org/apache/poi/hssf/model Workbook.java
> > src/java/org/apache/poi/hssf/util HSSFColor.java
> > src/testcases/org/apache/poi/hssf/usermodel
> > TestCellStyle.java TestWorkbook.java
> > Added: src/testcases/org/apache/poi/hssf/usermodel
> > SanityChecker.java
> > Log:
> > Some testing related stuff. The first shot at a sanity tester for XLS
record structure. Needs heaps more checks but it's a start.
> >
> > Revision Changes Path
> > 1.6 +5 -0
jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java
> >
> > Index: Workbook.java
> > ===================================================================
> > RCS file:
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/Workbook.java,v
> > retrieving revision 1.5
> > retrieving revision 1.6
> > diff -u -r1.5 -r1.6
> > --- Workbook.java 23 Apr 2002 22:24:40 -0000 1.5
> > +++ Workbook.java 29 Apr 2002 11:10:29 -0000 1.6
> > @@ -1772,4 +1772,9 @@
> > }
> > return null;
> > }
> > +
> > + public List getRecords()
> > + {
> > + return records;
> > + }
> > }
> >
> >
> >
> > 1.4 +4 -4
jakarta-poi/src/java/org/apache/poi/hssf/util/HSSFColor.java
> >
> > Index: HSSFColor.java
> > ===================================================================
> > RCS file:
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/util/HSSFColor.java,v
> > retrieving revision 1.3
> > retrieving revision 1.4
> > diff -u -r1.3 -r1.4
> > --- HSSFColor.java 7 Apr 2002 17:28:27 -0000 1.3
> > +++ HSSFColor.java 29 Apr 2002 11:10:29 -0000 1.4
> > @@ -87,7 +87,7 @@
> > * it takes to create it once per request but you will not hold
onto it
> > * if you have none of those requests.
> > *
> > - * @returns a hashtable containing all colors mapped to their
gnumeric-like
> > + * @return a hashtable containing all colors mapped to their
gnumeric-like
> > * triplet string
> > */
> >
> > @@ -148,7 +148,7 @@
> > }
> >
> > /**
> > - * @returns index to the standard palet
> > + * @return index to the standard palet
> > */
> >
> > public short getIndex()
> > @@ -157,7 +157,7 @@
> > }
> >
> > /**
> > - * @returns short[] triplet representation like that in Excel
> > + * @return triplet representation like that in Excel
> > */
> >
> > public short [] getTriplet()
> > @@ -168,7 +168,7 @@
> > // its a hack but its a good hack
> >
> > /**
> > - * @returns a hex string exactly like a gnumeric triplet
> > + * @return a hex string exactly like a gnumeric triplet
> > */
> >
> > public String getHexString()
> >
> >
> >
> > 1.6 +9 -3
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestCellStyle.java
> >
> > Index: TestCellStyle.java
> > ===================================================================
> > RCS file:
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestCellSt
yle.java,v
> > retrieving revision 1.5
> > retrieving revision 1.6
> > diff -u -r1.5 -r1.6
> > --- TestCellStyle.java 15 Mar 2002 02:47:56 -0000 1.5
> > +++ TestCellStyle.java 29 Apr 2002 11:10:29 -0000 1.6
> > @@ -127,7 +127,9 @@
> > }
> > wb.write(out);
> > out.close();
> > - assertEquals("FILE LENGTH == 87040", file.length(), 87040);
> > + SanityChecker sanityChecker = new SanityChecker();
> > + sanityChecker.checkHSSFWorkbook(wb);
> > + assertEquals("FILE LENGTH == 87040", file.length(), 87040);
// remove me
> > assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
> > assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
> >
> > @@ -164,8 +166,10 @@
> >
> > wb.write(out);
> > out.close();
> > + SanityChecker sanityChecker = new SanityChecker();
> > + sanityChecker.checkHSSFWorkbook(wb);
> >
> > - assertEquals("FILE LENGTH ", 5632, file.length());
> > + assertEquals("FILE LENGTH ", 5632, file.length()); //
remove me
> > assertEquals("LAST ROW ", 0, s.getLastRowNum());
> > assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
> >
> > @@ -226,7 +230,9 @@
> > }
> > wb.write(out);
> > out.close();
> > - assertEquals("FILE LENGTH == 87040", file.length(), 87040);
> > + SanityChecker sanityChecker = new SanityChecker();
> > + sanityChecker.checkHSSFWorkbook(wb);
> > + assertEquals("FILE LENGTH == 87040", file.length(), 87040);
// remove me
> > assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
> > assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
> >
> >
> >
> >
> > 1.2 +11 -25
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbook.java
> >
> > Index: TestWorkbook.java
> > ===================================================================
> > RCS file:
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestWorkbo
ok.java,v
> > retrieving revision 1.1
> > retrieving revision 1.2
> > diff -u -r1.1 -r1.2
> > --- TestWorkbook.java 31 Jan 2002 02:23:52 -0000 1.1
> > +++ TestWorkbook.java 29 Apr 2002 11:10:29 -0000 1.2
> > @@ -73,6 +73,8 @@
> > * Class to test Workbook functionality
> > *
> > * @author Andrew C. Oliver
> > + * @author Greg Merrill
> > + * @author Siggi Cherem
> > */
> >
> > public class TestWorkbook
> > @@ -88,6 +90,7 @@
> > private static final String LAST_NAME_VALUE = "Bush";
> > private static final String FIRST_NAME_VALUE = "George";
> > private static final String SSN_VALUE = "555555555";
> > + private SanityChecker sanityChecker = new SanityChecker();
> >
> > /**
> > * Constructor TestWorkbook
> > @@ -108,7 +111,6 @@
> > * FAILURE: HSSF does not create a sheet or excepts. Filesize
does not match the known good.
> > * HSSFSheet last row or first row is incorrect.
<P>
> > *
> > - * @author Andrew C. Oliver
> > */
> >
> > public void testWriteSheetSimple()
> > @@ -139,8 +141,9 @@
> > }
> > wb.write(out);
> > out.close();
> > + sanityChecker.checkHSSFWorkbook(wb);
> > assertEquals("FILE LENGTH == 87040", 87040,
> > - file.length()); // changed because of new sheet
behavior
> > + file.length()); //
remove me
> > assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
> > assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
> >
> > @@ -156,7 +159,6 @@
> > * FAILURE: HSSF does not create a sheet or excepts. Filesize
does not match the known good.
> > * HSSFSheet last row or first row is incorrect.
<P>
> > *
> > - * @author Andrew C. Oliver
> > */
> >
> > public void testWriteModifySheetSimple()
> > @@ -198,11 +200,9 @@
> > wb.write(out);
> > out.close();
> >
> > - // System.out.println(file.length());
> > - // assertEquals("FILE LENGTH == 87552",file.length(), 87552);
> > - // System.out.println(s.getLastRowNum());
> > + sanityChecker.checkHSSFWorkbook(wb);
> > assertEquals("FILE LENGTH == 45568", 45568,
> > - file.length()); // changed due to new sheet
behavior (<3)
> > + file.length()); // remove
> > assertEquals("LAST ROW == 74", 74, s.getLastRowNum());
> > assertEquals("FIRST ROW == 25", 25, s.getFirstRowNum());
> > }
> > @@ -214,8 +214,6 @@
> > * FAILURE: HSSF does not read a sheet or excepts. HSSF cannot
identify values
> > * in the sheet in their known positions.<P>
> > *
> > - * @author Greg Merrill
> > - * @author Andrew C. Oliver
> > */
> >
> > public void testReadSimple()
> > @@ -242,8 +240,6 @@
> > * FAILURE: HSSF does not read a sheet or excepts. HSSF cannot
identify values
> > * in the sheet in their known positions.<P>
> > *
> > - * @author Greg Merrill
> > - * @author Andrew C. Oliver
> > */
> >
> > public void testReadEmployeeSimple()
> > @@ -283,8 +279,6 @@
> > * HSSF does not re-read the sheet or excepts. Upon
re-reading the sheet the value
> > * is incorrect or has not been replaced. <P>
> > *
> > - * @author Andrew C. Oliver
> > - * @author Greg Merrill
> > */
> >
> > public void testModifySimple()
> > @@ -328,8 +322,6 @@
> > * is incorrect or has not been replaced or the
incorrect cell has its value replaced
> > * or is incorrect. <P>
> > *
> > - * @author Andrew C. Oliver
> > - * @author Greg Merrill
> > */
> >
> > public void testModifySimpleWithSkip()
> > @@ -381,8 +373,6 @@
> > * HSSF does not re-read the sheet or excepts. Upon
re-reading the sheet the value
> > * is incorrect or has not been replaced. <P>
> > *
> > - * @author Andrew C. Oliver
> > - * @author Greg Merrill
> > */
> >
> > public void testModifySimpleWithStyling()
> > @@ -433,8 +423,6 @@
> > * HSSF does not re-read the sheet or excepts. Upon
re-reading the sheet the value
> > * is incorrect or has not been replaced. <P>
> > *
> > - * @author Andrew C. Oliver
> > - * @author Greg Merrill
> > */
> >
> > public void testModifyEmployee()
> > @@ -487,8 +475,6 @@
> > * SUCCESS: HSSF reads a sheet. HSSF returns that the cell is
a numeric type cell. <P>
> > * FAILURE: HSSF does not read a sheet or excepts. HSSF
incorrectly indentifies the cell<P>
> > *
> > - * @author Siggi Cherem
> > - * @author Andrew C. Oliver (acoliver at apache dot org)
> > */
> >
> > public void testReadSheetWithRK()
> > @@ -519,7 +505,6 @@
> > * FAILURE: HSSF does not create a sheet or excepts. Filesize
does not match the known good.
> > * HSSFSheet last row or first row is incorrect.
<P>
> > *
> > - * @author Andrew C. Oliver
> > */
> >
> > public void testWriteModifySheetMerged()
> > @@ -555,6 +540,7 @@
> > ( short ) 15));
> > wb.write(out);
> > out.close();
> > + sanityChecker.checkHSSFWorkbook(wb);
> > in = new FileInputStream(file);
> > wb = new HSSFWorkbook(new POIFSFileSystem(in));
> > s = wb.getSheetAt(0);
> > @@ -582,7 +568,7 @@
> > throws Exception
> > {
> > HSSFWorkbook wb = new HSSFWorkbook();
> > - HSSFSheet s = wb.createSheet();
> > + wb.createSheet();
> > Workbook workbook = wb.getWorkbook();
> > BackupRecord record = workbook.getBackupRecord();
> >
> > @@ -629,12 +615,12 @@
> > {
> > String filename = System.getProperty("HSSF.testdata.path");
> >
> > - // assume andy is running this in the debugger
> > + // assume this is relative to basedir
> > if (filename == null)
> > {
> > System.setProperty(
> > "HSSF.testdata.path",
> > -
"/home/andy/npoi3/poi/production/testcases/net/sourceforge/poi/hssf/data");
> > + "src/testcases/org/apache/poi/hssf/data");
> > }
> > System.out
> > .println("Testing
org.apache.poi.hssf.usermodel.HSSFWorkbook");
> >
> >
> >
> > 1.1
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/SanityChecker.java
> >
> > Index: SanityChecker.java
> > ===================================================================
> > /* ====================================================================
> > * The Apache Software License, Version 1.1
> > *
> > * Copyright (c) 2002 The Apache Software Foundation. All rights
> > * reserved.
> > *
> > * Redistribution and use in source and binary forms, with or without
> > * modification, are permitted provided that the following conditions
> > * are met:
> > *
> > * 1. Redistributions of source code must retain the above copyright
> > * notice, this list of conditions and the following disclaimer.
> > *
> > * 2. Redistributions in binary form must reproduce the above copyright
> > * notice, this list of conditions and the following disclaimer in
> > * the documentation and/or other materials provided with the
> > * distribution.
> > *
> > * 3. The end-user documentation included with the redistribution,
> > * if any, must include the following acknowledgment:
> > * "This product includes software developed by the
> > * Apache Software Foundation (http://www.apache.org/)."
> > * Alternately, this acknowledgment may appear in the software
itself,
> > * if and wherever such third-party acknowledgments normally appear.
> > *
> > * 4. The names "Apache" and "Apache Software Foundation" and
> > * "Apache POI" must not be used to endorse or promote products
> > * derived from this software without prior written permission. For
> > * written permission, please contact [EMAIL PROTECTED]
> > *
> > * 5. Products derived from this software may not be called "Apache",
> > * "Apache POI", nor may "Apache" appear in their name, without
> > * prior written permission of the Apache Software Foundation.
> > *
> > * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
> > * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
> > * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> > * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
> > * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> > * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
> > * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
> > * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
> > * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
> > * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
> > * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> > * SUCH DAMAGE.
> > * ====================================================================
> > *
> > * This software consists of voluntary contributions made by many
> > * individuals on behalf of the Apache Software Foundation. For more
> > * information on the Apache Software Foundation, please see
> > * <http://www.apache.org/>.
> > */
> >
> > package org.apache.poi.hssf.usermodel;
> >
> > import junit.framework.Assert;
> > import org.apache.poi.hssf.model.Sheet;
> > import org.apache.poi.hssf.model.Workbook;
> > import org.apache.poi.hssf.record.*;
> > import org.apache.poi.hssf.usermodel.HSSFWorkbook;
> >
> > import java.util.List;
> >
> > /**
> > * Designed to check wither the records written actually make sense.
> > */
> > public class SanityChecker
> > extends Assert
> > {
> > private class CheckRecord
> > {
> > Class record;
> > char occurance; // 1 = one time, M = many times
> >
> > public CheckRecord(Class record, char occurance)
> > {
> > this.record = record;
> > this.occurance = occurance;
> > }
> >
> > public Class getRecord()
> > {
> > return record;
> > }
> >
> > public char getOccurance()
> > {
> > return occurance;
> > }
> > }
> >
> > CheckRecord[] workbookRecords = new CheckRecord[] {
> > new CheckRecord(BOFRecord.class, '1'),
> > new CheckRecord(InterfaceHdrRecord.class, '1'),
> > new CheckRecord(MMSRecord.class, '1'),
> > new CheckRecord(InterfaceEndRecord.class, '1'),
> > new CheckRecord(WriteAccessRecord.class, '1'),
> > new CheckRecord(CodepageRecord.class, '1'),
> > new CheckRecord(DSFRecord.class, '1'),
> > new CheckRecord(TabIdRecord.class, '1'),
> > new CheckRecord(FnGroupCountRecord.class, '1'),
> > new CheckRecord(WindowProtectRecord.class, '1'),
> > new CheckRecord(ProtectRecord.class, '1'),
> > new CheckRecord(PasswordRev4Record.class, '1'),
> > new CheckRecord(WindowOneRecord.class, '1'),
> > new CheckRecord(BackupRecord.class, '1'),
> > new CheckRecord(HideObjRecord.class, '1'),
> > new CheckRecord(DateWindow1904Record.class, '1'),
> > new CheckRecord(PrecisionRecord.class, '1'),
> > new CheckRecord(RefreshAllRecord.class, '1'),
> > new CheckRecord(BookBoolRecord.class, '1'),
> > new CheckRecord(FontRecord.class, 'M'),
> > new CheckRecord(FormatRecord.class, 'M'),
> > new CheckRecord(ExtendedFormatRecord.class, 'M'),
> > new CheckRecord(StyleRecord.class, 'M'),
> > new CheckRecord(UseSelFSRecord.class, '1'),
> > new CheckRecord(BoundSheetRecord.class, '1'), // Is this
right?
> > new CheckRecord(CountryRecord.class, '1'),
> > new CheckRecord(SSTRecord.class, '1'),
> > new CheckRecord(ExtSSTRecord.class, '1'),
> > new CheckRecord(EOFRecord.class, '1'),
> > };
> >
> > CheckRecord[] sheetRecords = new CheckRecord[] {
> > new CheckRecord(BOFRecord.class, '1'),
> > new CheckRecord(CalcModeRecord.class, '1'),
> > new CheckRecord(RefModeRecord.class, '1'),
> > new CheckRecord(IterationRecord.class, '1'),
> > new CheckRecord(DeltaRecord.class, '1'),
> > new CheckRecord(SaveRecalcRecord.class, '1'),
> > new CheckRecord(PrintHeadersRecord.class, '1'),
> > new CheckRecord(PrintGridlinesRecord.class, '1'),
> > new CheckRecord(GridsetRecord.class, '1'),
> > new CheckRecord(GutsRecord.class, '1'),
> > new CheckRecord(DefaultRowHeightRecord.class, '1'),
> > new CheckRecord(WSBoolRecord.class, '1'),
> > new CheckRecord(HeaderRecord.class, '1'),
> > new CheckRecord(FooterRecord.class, '1'),
> > new CheckRecord(HCenterRecord.class, '1'),
> > new CheckRecord(VCenterRecord.class, '1'),
> > new CheckRecord(PrintSetupRecord.class, '1'),
> > new CheckRecord(DefaultColWidthRecord.class, '1'),
> > new CheckRecord(DimensionsRecord.class, '1'),
> > new CheckRecord(WindowTwoRecord.class, '1'),
> > new CheckRecord(SelectionRecord.class, '1'),
> > new CheckRecord(EOFRecord.class, '1')
> > };
> >
> > public void checkWorkbookRecords(Workbook workbook)
> > {
> > List records = workbook.getRecords();
> > assertTrue(records.get(0) instanceof BOFRecord);
> > assertTrue(records.get(records.size() - 1) instanceof
EOFRecord);
> >
> > checkRecordOrder(records, workbookRecords);
> > }
> >
> > public void checkSheetRecords(Sheet sheet)
> > {
> > List records = sheet.getRecords();
> > assertTrue(records.get(0) instanceof BOFRecord);
> > assertTrue(records.get(records.size() - 1) instanceof
EOFRecord);
> >
> > checkRecordOrder(records, sheetRecords);
> > }
> >
> > public void checkHSSFWorkbook(HSSFWorkbook wb)
> > {
> > checkWorkbookRecords(wb.getWorkbook());
> > for (int i = 0; i < wb.getNumberOfSheets(); i++)
> > checkSheetRecords(wb.getSheetAt(i).getSheet());
> >
> > }
> >
> > private void checkRecordOrder(List records, CheckRecord[] check)
> > {
> > int checkIndex = 0;
> > for (int recordIndex = 0; recordIndex < records.size();
recordIndex++)
> > {
> > Record record = (Record) records.get(recordIndex);
> > if (check[checkIndex].getRecord().isInstance(record))
> > {
> > if (check[checkIndex].getOccurance() == 'M')
> > {
> > // skip over duplicate records if multiples are
allowed
> > while (recordIndex+1 < records.size() &&
check[checkIndex].getRecord().isInstance(records.get(recordIndex+1)))
> > recordIndex++;
> > }
> > checkIndex++;
> > }
> > if (checkIndex >= check.length)
> > return;
> > }
> > fail("Could not find required record: " + check[checkIndex]);
> > }
> >
> > }
> >
> >
> >
> >
>
>
>