Refactored test case
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@711515 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
abfa088b4f
commit
5da098c36a
|
@ -15,11 +15,8 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
import org.apache.poi.util.HexRead;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,18 +27,20 @@ import junit.framework.TestCase;
|
||||||
public final class TestUnicodeString extends TestCase {
|
public final class TestUnicodeString extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
|
private static void confirmSize(int expectedSize, UnicodeString s) {
|
||||||
|
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
||||||
|
s.getRecordSize(stats);
|
||||||
|
assertEquals(expectedSize, stats.recordSize);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSmallStringSize() {
|
public void testSmallStringSize() {
|
||||||
//Test a basic string
|
//Test a basic string
|
||||||
UnicodeString s = makeUnicodeString("Test");
|
UnicodeString s = makeUnicodeString("Test");
|
||||||
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(7, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(7, stats.recordSize);
|
|
||||||
|
|
||||||
//Test a small string that is uncompressed
|
//Test a small string that is uncompressed
|
||||||
s.setOptionFlags((byte)0x01);
|
s.setOptionFlags((byte)0x01);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(11, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(11, stats.recordSize);
|
|
||||||
|
|
||||||
//Test a compressed small string that has rich text formatting
|
//Test a compressed small string that has rich text formatting
|
||||||
s.setOptionFlags((byte)0x8);
|
s.setOptionFlags((byte)0x8);
|
||||||
|
@ -49,45 +48,33 @@ public final class TestUnicodeString extends TestCase {
|
||||||
s.addFormatRun(r);
|
s.addFormatRun(r);
|
||||||
UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short)2,(short)2);
|
UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short)2,(short)2);
|
||||||
s.addFormatRun(r2);
|
s.addFormatRun(r2);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(17, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(17, stats.recordSize);
|
|
||||||
|
|
||||||
//Test a uncompressed small string that has rich text formatting
|
//Test a uncompressed small string that has rich text formatting
|
||||||
s.setOptionFlags((byte)0x9);
|
s.setOptionFlags((byte)0x9);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(21, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(21, stats.recordSize);
|
|
||||||
|
|
||||||
//Test a compressed small string that has rich text and extended text
|
//Test a compressed small string that has rich text and extended text
|
||||||
s.setOptionFlags((byte)0xC);
|
s.setOptionFlags((byte)0xC);
|
||||||
s.setExtendedRst(new byte[]{(byte)0x1,(byte)0x2,(byte)0x3,(byte)0x4,(byte)0x5});
|
s.setExtendedRst(new byte[]{(byte)0x1,(byte)0x2,(byte)0x3,(byte)0x4,(byte)0x5});
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(26, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(26, stats.recordSize);
|
|
||||||
|
|
||||||
//Test a uncompressed small string that has rich text and extended text
|
//Test a uncompressed small string that has rich text and extended text
|
||||||
s.setOptionFlags((byte)0xD);
|
s.setOptionFlags((byte)0xD);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(30, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(30, stats.recordSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPerfectStringSize() {
|
public void testPerfectStringSize() {
|
||||||
//Test a basic string
|
//Test a basic string
|
||||||
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1);
|
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1);
|
||||||
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(SSTRecord.MAX_RECORD_SIZE, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE, stats.recordSize);
|
|
||||||
|
|
||||||
//Test an uncompressed string
|
//Test an uncompressed string
|
||||||
//Note that we can only ever get to a maximim size of 8227 since an uncompressed
|
//Note that we can only ever get to a maximim size of 8227 since an uncompressed
|
||||||
//string is writing double bytes.
|
//string is writing double bytes.
|
||||||
s = makeUnicodeString((SSTRecord.MAX_RECORD_SIZE-2-1)/2);
|
s = makeUnicodeString((SSTRecord.MAX_RECORD_SIZE-2-1)/2);
|
||||||
s.setOptionFlags((byte)0x1);
|
s.setOptionFlags((byte)0x1);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(SSTRecord.MAX_RECORD_SIZE-1, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testPerfectRichStringSize() {
|
public void testPerfectRichStringSize() {
|
||||||
|
@ -95,10 +82,8 @@ public final class TestUnicodeString extends TestCase {
|
||||||
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1-8-2);
|
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1-8-2);
|
||||||
s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
|
s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
|
||||||
s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
|
s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
|
||||||
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
|
||||||
s.setOptionFlags((byte)0x8);
|
s.setOptionFlags((byte)0x8);
|
||||||
s.getRecordSize(stats);
|
confirmSize(SSTRecord.MAX_RECORD_SIZE, s);
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE, stats.recordSize);
|
|
||||||
|
|
||||||
//Test an uncompressed rich text string
|
//Test an uncompressed rich text string
|
||||||
//Note that we can only ever get to a maximim size of 8227 since an uncompressed
|
//Note that we can only ever get to a maximim size of 8227 since an uncompressed
|
||||||
|
@ -107,17 +92,13 @@ public final class TestUnicodeString extends TestCase {
|
||||||
s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
|
s.addFormatRun(new UnicodeString.FormatRun((short)1,(short)0));
|
||||||
s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
|
s.addFormatRun(new UnicodeString.FormatRun((short)2,(short)1));
|
||||||
s.setOptionFlags((byte)0x9);
|
s.setOptionFlags((byte)0x9);
|
||||||
stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(SSTRecord.MAX_RECORD_SIZE-1, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE-1, stats.recordSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testContinuedStringSize() {
|
public void testContinuedStringSize() {
|
||||||
//Test a basic string
|
//Test a basic string
|
||||||
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1+20);
|
UnicodeString s = makeUnicodeString(SSTRecord.MAX_RECORD_SIZE-2-1+20);
|
||||||
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(SSTRecord.MAX_RECORD_SIZE+4+1+20, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE+4+1+20, stats.recordSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests that a string size calculation that fits neatly in two records, the second being a continue*/
|
/** Tests that a string size calculation that fits neatly in two records, the second being a continue*/
|
||||||
|
@ -131,14 +112,10 @@ public final class TestUnicodeString extends TestCase {
|
||||||
//Continue Record additional byte overhead
|
//Continue Record additional byte overhead
|
||||||
strSize -= 1;
|
strSize -= 1;
|
||||||
UnicodeString s = makeUnicodeString(strSize);
|
UnicodeString s = makeUnicodeString(strSize);
|
||||||
UnicodeString.UnicodeRecordStats stats = new UnicodeString.UnicodeRecordStats();
|
confirmSize(SSTRecord.MAX_RECORD_SIZE*2, s);
|
||||||
s.getRecordSize(stats);
|
|
||||||
assertEquals(SSTRecord.MAX_RECORD_SIZE*2, stats.recordSize);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static UnicodeString makeUnicodeString( String s )
|
private static UnicodeString makeUnicodeString( String s )
|
||||||
{
|
{
|
||||||
UnicodeString st = new UnicodeString(s);
|
UnicodeString st = new UnicodeString(s);
|
||||||
|
|
Loading…
Reference in New Issue