You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by jh...@apache.org on 2005/08/18 09:13:15 UTC

cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/record TestSSTRecord.java

jheight     2005/08/18 00:13:15

  Modified:    src/testcases/org/apache/poi/hssf/record TestSSTRecord.java
  Log:
  Why is there always one file that gets missed??
  
  Minor fix to correct testcase asd a result of Unicode patch
  
  Revision  Changes    Path
  1.12      +145 -145  jakarta-poi/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java
  
  Index: TestSSTRecord.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/record/TestSSTRecord.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestSSTRecord.java	18 Aug 2005 07:06:41 -0000	1.11
  +++ TestSSTRecord.java	18 Aug 2005 07:13:15 -0000	1.12
  @@ -62,117 +62,117 @@
       public void testProcessContinueRecord()
               throws IOException
       {
  -//jmh        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord" );
  -//jmh        byte[] input = new byte[testdata.length - 4];
  -//jmh
  -//jmh        System.arraycopy( testdata, 4, input, 0, input.length );
  -//jmh        SSTRecord record =
  -//jmh                new SSTRecord( LittleEndian.getShort( testdata, 0 ),
  -//jmh                        LittleEndian.getShort( testdata, 2 ), input );
  -//jmh        byte[] continueRecord = HexRead.readData( _test_file_path + File.separator + "BigSSTRecordCR" );
  -//jmh
  -//jmh        input = new byte[continueRecord.length - 4];
  -//jmh        System.arraycopy( continueRecord, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        assertEquals( 1464, record.getNumStrings() );
  -//jmh        assertEquals( 688, record.getNumUniqueStrings() );
  -//jmh        assertEquals( 688, record.countStrings() );
  -//jmh        byte[] ser_output = record.serialize();
  -//jmh        int offset = 0;
  -//jmh        short type = LittleEndian.getShort( ser_output, offset );
  -//jmh
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        short length = LittleEndian.getShort( ser_output, offset );
  -//jmh
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        byte[] recordData = new byte[length];
  -//jmh
  -//jmh        System.arraycopy( ser_output, offset, recordData, 0, length );
  -//jmh        offset += length;
  -//jmh        SSTRecord testRecord = new SSTRecord( type, length, recordData );
  -//jmh
  -//jmh        assertEquals( ContinueRecord.sid,
  -//jmh                LittleEndian.getShort( ser_output, offset ) );
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        length = LittleEndian.getShort( ser_output, offset );
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        byte[] cr = new byte[length];
  -//jmh
  -//jmh        System.arraycopy( ser_output, offset, cr, 0, length );
  -//jmh        offset += length;
  -//jmh        assertEquals( offset, ser_output.length );
  -//jmh        testRecord.processContinueRecord( cr );
  -//jmh        assertEquals( record, testRecord );
  -//jmh
  -//jmh        // testing based on new bug report
  -//jmh        testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2" );
  -//jmh        input = new byte[testdata.length - 4];
  -//jmh        System.arraycopy( testdata, 4, input, 0, input.length );
  -//jmh        record = new SSTRecord( LittleEndian.getShort( testdata, 0 ),
  -//jmh                LittleEndian.getShort( testdata, 2 ), input );
  -//jmh        byte[] continueRecord1 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR1" );
  -//jmh
  -//jmh        input = new byte[continueRecord1.length - 4];
  -//jmh        System.arraycopy( continueRecord1, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord2 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR2" );
  -//jmh
  -//jmh        input = new byte[continueRecord2.length - 4];
  -//jmh        System.arraycopy( continueRecord2, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord3 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR3" );
  -//jmh
  -//jmh        input = new byte[continueRecord3.length - 4];
  -//jmh        System.arraycopy( continueRecord3, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord4 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR4" );
  -//jmh
  -//jmh        input = new byte[continueRecord4.length - 4];
  -//jmh        System.arraycopy( continueRecord4, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord5 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR5" );
  -//jmh
  -//jmh        input = new byte[continueRecord5.length - 4];
  -//jmh        System.arraycopy( continueRecord5, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord6 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR6" );
  -//jmh
  -//jmh        input = new byte[continueRecord6.length - 4];
  -//jmh        System.arraycopy( continueRecord6, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        byte[] continueRecord7 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR7" );
  -//jmh
  -//jmh        input = new byte[continueRecord7.length - 4];
  -//jmh        System.arraycopy( continueRecord7, 4, input, 0, input.length );
  -//jmh        record.processContinueRecord( input );
  -//jmh        assertEquals( 158642, record.getNumStrings() );
  -//jmh        assertEquals( 5249, record.getNumUniqueStrings() );
  -//jmh        assertEquals( 5249, record.countStrings() );
  -//jmh        ser_output = record.serialize();
  -//jmh        offset = 0;
  -//jmh        type = LittleEndian.getShort( ser_output, offset );
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        length = LittleEndian.getShort( ser_output, offset );
  -//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh        recordData = new byte[length];
  -//jmh        System.arraycopy( ser_output, offset, recordData, 0, length );
  -//jmh        offset += length;
  -//jmh        testRecord = new SSTRecord( type, length, recordData );
  -//jmh        for ( int count = 0; count < 7; count++ )
  -//jmh        {
  -//jmh            assertEquals( ContinueRecord.sid,
  -//jmh                    LittleEndian.getShort( ser_output, offset ) );
  -//jmh            offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh            length = LittleEndian.getShort( ser_output, offset );
  -//jmh            offset += LittleEndianConsts.SHORT_SIZE;
  -//jmh            cr = new byte[length];
  -//jmh            System.arraycopy( ser_output, offset, cr, 0, length );
  -//jmh            testRecord.processContinueRecord( cr );
  -//jmh            offset += length;
  -//jmh        }
  -//jmh        assertEquals( offset, ser_output.length );
  -//jmh        assertEquals( record, testRecord );
  -//jmh        assertEquals( record.countStrings(), testRecord.countStrings() );
  +//jmh        byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord" );
  +//jmh        byte[] input = new byte[testdata.length - 4];
  +//jmh
  +//jmh        System.arraycopy( testdata, 4, input, 0, input.length );
  +//jmh        SSTRecord record =
  +//jmh                new SSTRecord( LittleEndian.getShort( testdata, 0 ),
  +//jmh                        LittleEndian.getShort( testdata, 2 ), input );
  +//jmh        byte[] continueRecord = HexRead.readData( _test_file_path + File.separator + "BigSSTRecordCR" );
  +//jmh
  +//jmh        input = new byte[continueRecord.length - 4];
  +//jmh        System.arraycopy( continueRecord, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        assertEquals( 1464, record.getNumStrings() );
  +//jmh        assertEquals( 688, record.getNumUniqueStrings() );
  +//jmh        assertEquals( 688, record.countStrings() );
  +//jmh        byte[] ser_output = record.serialize();
  +//jmh        int offset = 0;
  +//jmh        short type = LittleEndian.getShort( ser_output, offset );
  +//jmh
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        short length = LittleEndian.getShort( ser_output, offset );
  +//jmh
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        byte[] recordData = new byte[length];
  +//jmh
  +//jmh        System.arraycopy( ser_output, offset, recordData, 0, length );
  +//jmh        offset += length;
  +//jmh        SSTRecord testRecord = new SSTRecord( type, length, recordData );
  +//jmh
  +//jmh        assertEquals( ContinueRecord.sid,
  +//jmh                LittleEndian.getShort( ser_output, offset ) );
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        length = LittleEndian.getShort( ser_output, offset );
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        byte[] cr = new byte[length];
  +//jmh
  +//jmh        System.arraycopy( ser_output, offset, cr, 0, length );
  +//jmh        offset += length;
  +//jmh        assertEquals( offset, ser_output.length );
  +//jmh        testRecord.processContinueRecord( cr );
  +//jmh        assertEquals( record, testRecord );
  +//jmh
  +//jmh        // testing based on new bug report
  +//jmh        testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2" );
  +//jmh        input = new byte[testdata.length - 4];
  +//jmh        System.arraycopy( testdata, 4, input, 0, input.length );
  +//jmh        record = new SSTRecord( LittleEndian.getShort( testdata, 0 ),
  +//jmh                LittleEndian.getShort( testdata, 2 ), input );
  +//jmh        byte[] continueRecord1 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR1" );
  +//jmh
  +//jmh        input = new byte[continueRecord1.length - 4];
  +//jmh        System.arraycopy( continueRecord1, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord2 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR2" );
  +//jmh
  +//jmh        input = new byte[continueRecord2.length - 4];
  +//jmh        System.arraycopy( continueRecord2, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord3 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR3" );
  +//jmh
  +//jmh        input = new byte[continueRecord3.length - 4];
  +//jmh        System.arraycopy( continueRecord3, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord4 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR4" );
  +//jmh
  +//jmh        input = new byte[continueRecord4.length - 4];
  +//jmh        System.arraycopy( continueRecord4, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord5 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR5" );
  +//jmh
  +//jmh        input = new byte[continueRecord5.length - 4];
  +//jmh        System.arraycopy( continueRecord5, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord6 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR6" );
  +//jmh
  +//jmh        input = new byte[continueRecord6.length - 4];
  +//jmh        System.arraycopy( continueRecord6, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        byte[] continueRecord7 = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord2CR7" );
  +//jmh
  +//jmh        input = new byte[continueRecord7.length - 4];
  +//jmh        System.arraycopy( continueRecord7, 4, input, 0, input.length );
  +//jmh        record.processContinueRecord( input );
  +//jmh        assertEquals( 158642, record.getNumStrings() );
  +//jmh        assertEquals( 5249, record.getNumUniqueStrings() );
  +//jmh        assertEquals( 5249, record.countStrings() );
  +//jmh        ser_output = record.serialize();
  +//jmh        offset = 0;
  +//jmh        type = LittleEndian.getShort( ser_output, offset );
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        length = LittleEndian.getShort( ser_output, offset );
  +//jmh        offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh        recordData = new byte[length];
  +//jmh        System.arraycopy( ser_output, offset, recordData, 0, length );
  +//jmh        offset += length;
  +//jmh        testRecord = new SSTRecord( type, length, recordData );
  +//jmh        for ( int count = 0; count < 7; count++ )
  +//jmh        {
  +//jmh            assertEquals( ContinueRecord.sid,
  +//jmh                    LittleEndian.getShort( ser_output, offset ) );
  +//jmh            offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh            length = LittleEndian.getShort( ser_output, offset );
  +//jmh            offset += LittleEndianConsts.SHORT_SIZE;
  +//jmh            cr = new byte[length];
  +//jmh            System.arraycopy( ser_output, offset, cr, 0, length );
  +//jmh            testRecord.processContinueRecord( cr );
  +//jmh            offset += length;
  +//jmh        }
  +//jmh        assertEquals( offset, ser_output.length );
  +//jmh        assertEquals( record, testRecord );
  +//jmh        assertEquals( record.countStrings(), testRecord.countStrings() );
       }
   
       /**
  @@ -190,13 +190,13 @@
                       new byte[9000], new byte[7433], new byte[9002],
                       new byte[16998]
                   };
  -        UnicodeString[] strings = new UnicodeString[bstrings.length];
  +        UnicodeString[] strings = new UnicodeString[bstrings.length];
           int total_length = 0;
   
           for ( int k = 0; k < bstrings.length; k++ )
           {
               Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
  -            strings[k] = new UnicodeString( new String(bstrings[k]) );
  +            strings[k] = new UnicodeString( new String(bstrings[k]) );
               record.addString( strings[k] );
               total_length += 3 + bstrings[k].length;
           }
  @@ -214,10 +214,10 @@
           record.serialize( 0, content );
           assertEquals( total_length, content.length );
   
  -        //Deserialize the record.
  -        RecordInputStream recStream = new RecordInputStream(new ByteArrayInputStream(content));
  -        recStream.nextRecord();
  -        record = new SSTRecord(recStream);
  +        //Deserialize the record.
  +        RecordInputStream recStream = new RecordInputStream(new ByteArrayInputStream(content));
  +        recStream.nextRecord();
  +        record = new SSTRecord(recStream);
   
           assertEquals( strings.length, record.getNumStrings() );
           assertEquals( strings.length, record.getNumUniqueStrings() );
  @@ -233,14 +233,14 @@
               if ( ( bstrings[k].length % 2 ) == 1 )
               {
                   Arrays.fill( bstrings[k], (byte) ( 'a' + k ) );
  -                strings[k] = new UnicodeString( new String(bstrings[k]) );
  +                strings[k] = new UnicodeString( new String(bstrings[k]) );
               }
               else
               {
                   char[] data = new char[bstrings[k].length / 2];
   
                   Arrays.fill( data, (char) ( '\u2122' + k ) );
  -                strings[k] = new UnicodeString(new String( data ));
  +                strings[k] = new UnicodeString(new String( data ));
               }
               record.addString( strings[k] );
           }
  @@ -249,9 +249,9 @@
           total_length--;
           assertEquals( total_length, content.length );
   
  -        recStream = new RecordInputStream(new ByteArrayInputStream(content));
  -        recStream.nextRecord();
  -        record = new SSTRecord(recStream);
  +        recStream = new RecordInputStream(new ByteArrayInputStream(content));
  +        recStream.nextRecord();
  +        record = new SSTRecord(recStream);
   
           assertEquals( strings.length, record.getNumStrings() );
           assertEquals( strings.length, record.getNumUniqueStrings() );
  @@ -277,7 +277,7 @@
           // the record will start with two integers, then this string
           // ... that will eat up 16 of the 8224 bytes that the record
           // can hold
  -        record.addString( new UnicodeString("Hello") );
  +        record.addString( new UnicodeString("Hello") );
   
           // now we have an additional 8208 bytes, which is an exact
           // multiple of 16 bytes
  @@ -285,19 +285,19 @@
   
           for ( int k = 0; k < 2000; k++ )
           {
  -            record.addString( new UnicodeString(String.valueOf( testvalue++ )) );
  +            record.addString( new UnicodeString(String.valueOf( testvalue++ )) );
           }
           byte[] content = new byte[record.getRecordSize()];
   
           record.serialize( 0, content );
  -        assertEquals(8224, LittleEndian.getShort(content, 2));
  -        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 8228));
  -        assertEquals(8224, LittleEndian.getShort(content, 8228+2));
  +        assertEquals(8224, LittleEndian.getShort(content, 2));
  +        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 8228));
  +        assertEquals(8224, LittleEndian.getShort(content, 8228+2));
           assertEquals( (byte) 13, content[4 + 8228] );
  -        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 2*8228));
  -        assertEquals(8224, LittleEndian.getShort(content, 8228*2+2));
  +        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 2*8228));
  +        assertEquals(8224, LittleEndian.getShort(content, 8228*2+2));
           assertEquals( (byte) 13, content[4 + 8228 * 2] );
  -        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 3*8228));
  +        assertEquals(ContinueRecord.sid, LittleEndian.getShort(content, 3*8228));
           assertEquals( (byte) 13, content[4 + 8228 * 3] );
       }
   
  @@ -307,10 +307,10 @@
       public void testSimpleAddString()
       {
           SSTRecord record = new SSTRecord();
  -        UnicodeString s1 = new UnicodeString("Hello world");
  +        UnicodeString s1 = new UnicodeString("Hello world");
   
           // \u2122 is the encoding of the trademark symbol ...
  -        UnicodeString s2 = new UnicodeString("Hello world\u2122");
  +        UnicodeString s2 = new UnicodeString("Hello world\u2122");
   
           assertEquals( 0, record.addString( s1 ) );
           assertEquals( s1, record.getString( 0 ) );
  @@ -333,11 +333,11 @@
           {
               UnicodeString ucs = (UnicodeString) iter.next();
   
  -            if ( ucs.equals( s1 ) )
  +            if ( ucs.equals( s1 ) )
               {
                   assertEquals( (byte) 0, ucs.getOptionFlags() );
               }
  -            else if ( ucs.equals( s2 ) )
  +            else if ( ucs.equals( s2 ) )
               {
                   assertEquals( (byte) 1, ucs.getOptionFlags() );
               }
  @@ -357,27 +357,27 @@
       public void testReaderConstructor()
               throws IOException
       {
  -/* JMH this test case data is crap because it does not contain a full record. Ie the last string
  -       is missing a record
  -
  +/* JMH this test case data is crap because it does not contain a full record. Ie the last string
  +       is missing a record
  +
           byte[] testdata = HexRead.readData( _test_file_path + File.separator + "BigSSTRecord" );
  -//        byte[] input = new byte[testdata.length - 4];
  +//        byte[] input = new byte[testdata.length - 4];
   
           System.arraycopy( testdata, 4, input, 0, input.length );
  -        SSTRecord record = new SSTRecord( new TestcaseRecordInputStream(LittleEndian.getShort( testdata, 0 ),
  +        SSTRecord record = new SSTRecord( new TestcaseRecordInputStream(LittleEndian.getShort( testdata, 0 ),
                   LittleEndian.getShort( testdata, 2 ),
  -                input) );
  +                input) );
   
           assertEquals( 1464, record.getNumStrings() );
           assertEquals( 688, record.getNumUniqueStrings() );
           assertEquals( 492, record.countStrings() );
  -        assertEquals( 1, record.getDeserializer().getContinuationExpectedChars() );
  +        assertEquals( 1, record.getDeserializer().getContinuationExpectedChars() );
           assertEquals( "Consolidated B-24J Liberator The Dragon & His Tai",
                   record.getDeserializer().getUnfinishedString() );
   //        assertEquals( 52, record.getDeserializer().getTotalLength() );
   //        assertEquals( 3, record.getDeserializer().getStringDataOffset() );
           assertTrue( !record.getDeserializer().isWideChar() );
  - */
  + */
       }
   
       /**
  @@ -429,7 +429,7 @@
           HSSFWorkbook wb = new HSSFWorkbook( stream );
           stream.close();
           HSSFSheet sheet = wb.getSheetAt( 1 );
  -        assertEquals( "01/05 (Wed) ", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue() );
  +        assertEquals( "01/05 (Wed)", sheet.getRow( 0 ).getCell( (short) 8 ).getStringCellValue() );
           assertEquals( "01/05 (Wed)", sheet.getRow( 1 ).getCell( (short) 8 ).getStringCellValue() );
   
           file = TempFile.createTempFile( "testout", "xls" );
  @@ -445,11 +445,11 @@
           stream.close();
           sheet = wb.getSheetAt( 0 );
           int row = 0;
  -        assertEquals( "Testing ", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
  +        assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
           assertEquals( "rich", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
           assertEquals( "text", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
           assertEquals( "strings", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
  -        assertEquals( "Testing  ", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
  +        assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
           assertEquals( "Testing", sheet.getRow( row++ ).getCell( (short) 0 ).getStringCellValue() );
   
   //        file = new File("/tryme.xls");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
Mailing List:    http://jakarta.apache.org/site/mail2.html#poi
The Apache Jakarta POI Project: http://jakarta.apache.org/poi/