KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > record > TestSSTDeserializer


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

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 JavaDoc;
25
26 import junit.framework.TestCase;
27
28 /**
29  * Exercise the SSTDeserializer class.
30  *
31  * @author Glen Stampoultzis (glens at apache.org)
32  */

33 public class TestSSTDeserializer
34         extends TestCase
35 {
36     private String JavaDoc _test_file_path;
37     private static final String JavaDoc _test_file_path_property = "HSSF.testdata.path";
38
39     public TestSSTDeserializer( String JavaDoc s )
40     {
41         super( s );
42     }
43
44     protected void setUp() throws Exception JavaDoc
45     {
46         _test_file_path = System.getProperty( _test_file_path_property );
47     }
48
49     public void testSpanRichTextToPlainText()
50             throws Exception JavaDoc
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 JavaDoc( 0 ) ) + "" );
60     }
61
62     public void testContinuationWithNoOverlap()
63             throws Exception JavaDoc
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 JavaDoc( 0 ) ) + "" );
73         assertEquals( "At a dinner party", strings.get( new Integer JavaDoc( 1 ) ) + "" );
74
75     }
76
77     /**
78      * Strings can actually span across more than one continuation.
79      */

80     public void testStringAcross2Continuations()
81             throws Exception JavaDoc
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 JavaDoc( 0 ) ) + "" );
93         assertEquals( "At a dinner partyAt a dinner party", strings.get( new Integer JavaDoc( 1 ) ) + "" );
94
95     }
96
97     public void testExtendedStrings()
98             throws Exception JavaDoc
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 JavaDoc( 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 JavaDoc( 0 ) ) + "" );
118
119     }
120
121 }
122
Popular Tags