1 2 17 18 19 package org.apache.poi.hssf.record; 20 21 import org.apache.poi.util.HexRead; 22 import org.apache.poi.util.BinaryTree; 23 24 import java.io.File ; 25 26 import junit.framework.TestCase; 27 28 33 public class TestSSTDeserializer 34 extends TestCase 35 { 36 private String _test_file_path; 37 private static final String _test_file_path_property = "HSSF.testdata.path"; 38 39 public TestSSTDeserializer( String s ) 40 { 41 super( s ); 42 } 43 44 protected void setUp() throws Exception 45 { 46 _test_file_path = System.getProperty( _test_file_path_property ); 47 } 48 49 public void testSpanRichTextToPlainText() 50 throws Exception 51 { 52 byte[] bytes = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "header" ); 53 BinaryTree strings = new BinaryTree(); 54 SSTDeserializer deserializer = new SSTDeserializer( strings ); 55 deserializer.manufactureStrings( bytes, 0); 56 byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "richtextdata.txt", "continue1" ); 57 deserializer.processContinueRecord( continueBytes ); 58 59 assertEquals( "At a dinner party orAt At At ", strings.get( new Integer ( 0 ) ) + "" ); 60 } 61 62 public void testContinuationWithNoOverlap() 63 throws Exception 64 { 65 byte[] bytes = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "header" ); 66 BinaryTree strings = new BinaryTree(); 67 SSTDeserializer deserializer = new SSTDeserializer( strings ); 68 deserializer.manufactureStrings( bytes, 0); 69 byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "evencontinuation.txt", "continue1" ); 70 deserializer.processContinueRecord( continueBytes ); 71 72 assertEquals( "At a dinner party or", strings.get( new Integer ( 0 ) ) + "" ); 73 assertEquals( "At a dinner party", strings.get( new Integer ( 1 ) ) + "" ); 74 75 } 76 77 80 public void testStringAcross2Continuations() 81 throws Exception 82 { 83 byte[] bytes = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "header" ); 84 BinaryTree strings = new BinaryTree(); 85 SSTDeserializer deserializer = new SSTDeserializer( strings ); 86 deserializer.manufactureStrings( bytes, 0); 87 bytes = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue1" ); 88 deserializer.processContinueRecord( bytes ); 89 bytes = HexRead.readData( _test_file_path + File.separator + "stringacross2continuations.txt", "continue2" ); 90 deserializer.processContinueRecord( bytes ); 91 92 assertEquals( "At a dinner party or", strings.get( new Integer ( 0 ) ) + "" ); 93 assertEquals( "At a dinner partyAt a dinner party", strings.get( new Integer ( 1 ) ) + "" ); 94 95 } 96 97 public void testExtendedStrings() 98 throws Exception 99 { 100 byte[] bytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-header" ); 101 BinaryTree strings = new BinaryTree(); 102 SSTDeserializer deserializer = new SSTDeserializer( strings ); 103 deserializer.manufactureStrings( bytes, 0); 104 byte[] continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "rich-continue1" ); 105 deserializer.processContinueRecord( continueBytes ); 106 107 assertEquals( "At a dinner party orAt At At ", strings.get( new Integer ( 0 ) ) + "" ); 108 109 110 bytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-header" ); 111 strings = new BinaryTree(); 112 deserializer = new SSTDeserializer( strings ); 113 deserializer.manufactureStrings( bytes, 0); 114 continueBytes = HexRead.readData( _test_file_path + File.separator + "extendedtextstrings.txt", "norich-continue1" ); 115 deserializer.processContinueRecord( continueBytes ); 116 117 assertEquals( "At a dinner party orAt At At ", strings.get( new Integer ( 0 ) ) + "" ); 118 119 } 120 121 } 122 | Popular Tags |