FileDocCategorySizeDatePackage
TestSSTDeserializer.javaAPI DocApache Poi 3.0.16593Mon Jan 01 12:39:46 GMT 2007org.apache.poi.hssf.record

TestSSTDeserializer

public class TestSSTDeserializer extends TestCase
Exercise the SSTDeserializer class.
author
Glen Stampoultzis (glens at apache.org)

Fields Summary
private String
_test_file_path
private static final String
_test_file_path_property
Constructors Summary
public TestSSTDeserializer(String s)


        
    
        super( s );
    
Methods Summary
private byte[]joinArray(byte[] array1, byte[] array2)

      byte[] bigArray = new byte[array1.length+array2.length];
      System.arraycopy(array1, 0, bigArray, 0, array1.length);
      System.arraycopy(array2, 0, bigArray, array1.length, array2.length);
      return bigArray;    
    
protected voidsetUp()

        _test_file_path = System.getProperty( _test_file_path_property );
    
public voidtestContinuationWithNoOverlap()

        byte[] header = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "header" );
        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "continue1" );
        continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
        TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));

        IntMapper strings = new IntMapper();
        SSTDeserializer deserializer = new SSTDeserializer( strings );
        deserializer.manufactureStrings( 2, in);

        assertEquals( "At a dinner party or", strings.get( 0 ) + "" );
        assertEquals( "At a dinner party", strings.get( 1 ) + "" );
    
public voidtestExtendedStrings()

        byte[] header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-header" );
        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-continue1" );
        continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
        TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
        
        IntMapper strings = new IntMapper();
        SSTDeserializer deserializer = new SSTDeserializer( strings );
        deserializer.manufactureStrings( 1, in);

        assertEquals( "At a dinner party orAt At At ", strings.get( 0  ) + "" );


        header = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-header" );
        continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-continue1" );
        continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
        in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
        
        strings = new IntMapper();
        deserializer = new SSTDeserializer( strings );
        deserializer.manufactureStrings( 1, in);

        assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );

    
public voidtestSpanRichTextToPlainText()

      byte[] header = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "header" );
        byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "continue1" );
      continueBytes = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continueBytes.length, continueBytes);
      TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, joinArray(header, continueBytes));
      

        IntMapper strings = new IntMapper();
        SSTDeserializer deserializer = new SSTDeserializer( strings );
        deserializer.manufactureStrings(1, in );

        assertEquals( "At a dinner party orAt At At ", strings.get( 0 ) + "" );
    
public voidtestStringAcross2Continuations()
Strings can actually span across more than one continuation.

        byte[] header = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "header" );
        byte[] continue1 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue1" );
        continue1 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue1.length, continue1);
        byte[] continue2 = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue2" );
        continue2 = TestcaseRecordInputStream.mergeDataAndSid(ContinueRecord.sid, (short)continue2.length, continue2);
        
        byte[] bytes = joinArray(header, continue1);
        bytes = joinArray(bytes, continue2);
        TestcaseRecordInputStream in = new TestcaseRecordInputStream((short)0, (short)header.length, bytes);

        IntMapper strings = new IntMapper();
        SSTDeserializer deserializer = new SSTDeserializer( strings );
        deserializer.manufactureStrings( 2, in);

        assertEquals( "At a dinner party or", strings.get(  0 ) + "" );
        assertEquals( "At a dinner partyAt a dinner party", strings.get( 1 ) + "" );