use of org.apache.poi.hssf.record.common.UnicodeString.ExtRst in project poi by apache.
the class TestUnicodeString method extRstFromData.
@Test
public void extRstFromData() throws Exception {
byte[] data = new byte[] { 01, 00, 0x0C, 00, 00, 00, 0x37, 00, 00, 00, 00, 00, 00, 00, // Cruft at the end, as found from real files
00, // Cruft at the end, as found from real files
00 };
assertEquals(16, data.length);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
ExtRst ext = new ExtRst(inp, data.length);
// Excludes 4 byte header
assertEquals(0x0c, ext.getDataSize());
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0x37, ext.getFormattingOptions());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
use of org.apache.poi.hssf.record.common.UnicodeString.ExtRst in project poi by apache.
the class TestUnicodeString method extRstFromEmpty.
@Test
public void extRstFromEmpty() throws Exception {
ExtRst ext = new ExtRst();
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
// Excludes 4 byte header
assertEquals(10, ext.getDataSize());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
LittleEndianOutputStream out = new LittleEndianOutputStream(baos);
ContinuableRecordOutput cout = new ContinuableRecordOutput(out, 0xffff);
ext.serialize(cout);
cout.writeContinue();
byte[] b = baos.toByteArray();
assertEquals(20, b.length);
// First 4 bytes from the outputstream
assertEquals(-1, b[0]);
assertEquals(-1, b[1]);
assertEquals(14, b[2]);
assertEquals(00, b[3]);
// Reserved
assertEquals(1, b[4]);
assertEquals(0, b[5]);
// Data size
assertEquals(10, b[6]);
assertEquals(00, b[7]);
// Font*2
assertEquals(0, b[8]);
assertEquals(0, b[9]);
assertEquals(0, b[10]);
assertEquals(0, b[11]);
// 0 Runs
assertEquals(0, b[12]);
assertEquals(0, b[13]);
// Size=0, *2
assertEquals(0, b[14]);
assertEquals(0, b[15]);
assertEquals(0, b[16]);
assertEquals(0, b[17]);
// Last 2 bytes from the outputstream
assertEquals(ContinueRecord.sid, b[18]);
assertEquals(0, b[19]);
// Load in again and re-test
byte[] data = new byte[14];
System.arraycopy(b, 4, data, 0, data.length);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
ext = new ExtRst(inp, data.length);
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals(0, ext.getFormattingOptions());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
use of org.apache.poi.hssf.record.common.UnicodeString.ExtRst in project poi by apache.
the class TestUnicodeString method smallStringSize.
@Test
public void smallStringSize() {
//Test a basic string
UnicodeString s = makeUnicodeString("Test");
confirmSize(7, s);
//Test a small string that is uncompressed
s = makeUnicodeString(STR_16_BIT);
s.setOptionFlags((byte) 0x01);
confirmSize(11, s);
//Test a compressed small string that has rich text formatting
s.setString("Test");
s.setOptionFlags((byte) 0x8);
UnicodeString.FormatRun r = new UnicodeString.FormatRun((short) 0, (short) 1);
s.addFormatRun(r);
UnicodeString.FormatRun r2 = new UnicodeString.FormatRun((short) 2, (short) 2);
s.addFormatRun(r2);
confirmSize(17, s);
//Test a uncompressed small string that has rich text formatting
s.setString(STR_16_BIT);
s.setOptionFlags((byte) 0x9);
confirmSize(21, s);
//Test a compressed small string that has rich text and extended text
s.setString("Test");
s.setOptionFlags((byte) 0xC);
confirmSize(17, s);
// Extended phonetics data
// Minimum size is 14
// Also adds 4 bytes to hold the length
s.setExtendedRst(new ExtRst());
confirmSize(35, s);
//Test a uncompressed small string that has rich text and extended text
s.setString(STR_16_BIT);
s.setOptionFlags((byte) 0xD);
confirmSize(39, s);
s.setExtendedRst(null);
confirmSize(21, s);
}
use of org.apache.poi.hssf.record.common.UnicodeString.ExtRst in project poi by apache.
the class TestUnicodeString method corruptExtRstDetection.
@Test
public void corruptExtRstDetection() throws Exception {
byte[] data = new byte[] { 0x79, 0x79, 0x11, 0x11, 0x22, 0x22, 0x33, 0x33 };
assertEquals(8, data.length);
LittleEndianInputStream inp = new LittleEndianInputStream(new ByteArrayInputStream(data));
ExtRst ext = new ExtRst(inp, data.length);
// Will be empty
assertEquals(ext, new ExtRst());
// If written, will be the usual size
// Excludes 4 byte header
assertEquals(10, ext.getDataSize());
// Is empty
assertEquals(0, ext.getNumberOfRuns());
assertEquals(0, ext.getFormattingOptions());
assertEquals(0, ext.getFormattingFontIndex());
assertEquals("", ext.getPhoneticText());
assertEquals(0, ext.getPhRuns().length);
}
Aggregations