Update tests to track updates in StyleTextPropAtom

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353764 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2005-08-14 17:52:43 +00:00
parent b819b7595c
commit 5e6d45c31c

View File

@ -23,6 +23,7 @@ import org.apache.poi.hslf.record.StyleTextPropAtom.*;
import junit.framework.TestCase; import junit.framework.TestCase;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.LinkedList;
/** /**
* Tests that StyleTextPropAtom works properly * Tests that StyleTextPropAtom works properly
@ -38,6 +39,7 @@ public class TestStyleTextPropAtom extends TestCase {
0x04, 00, 00, 00, 00, 0x05, 0x10, 00, 0x04, 00, 00, 00, 00, 0x05, 0x10, 00,
00, 00, 00, 00, 0x04, 00, 0xFF-256, 0x33, 00, 0xFE-256 00, 00, 00, 00, 0x04, 00, 0xFF-256, 0x33, 00, 0xFE-256
}; };
private int data_a_text_len = 54;
private byte[] data_b = new byte[] { 0, 0, 0xA1-256, 0x0F, 0x2E, 0, 0, 0, private byte[] data_b = new byte[] { 0, 0, 0xA1-256, 0x0F, 0x2E, 0, 0, 0,
0x53, 0, 0, 0, 0, 0, 0, 0, 0x53, 0, 0, 0, 0, 0, 0, 0,
@ -47,6 +49,7 @@ public class TestStyleTextPropAtom extends TestCase {
0, 05, 0x19, 0, 0, 0, 0, 0, 0, 05, 0x19, 0, 0, 0, 0, 0,
04, 0, 0xFF-256, 0x33, 0, 0xFE-256 04, 0, 0xFF-256, 0x33, 0, 0xFE-256
}; };
private int data_b_text_len = 83;
public void testRecordType() throws Exception { public void testRecordType() throws Exception {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
@ -55,78 +58,59 @@ public class TestStyleTextPropAtom extends TestCase {
assertEquals(4001l, stpb.getRecordType()); assertEquals(4001l, stpb.getRecordType());
} }
public void testCharacterGroups() throws Exception {
public void testCharacterStyleCounts() throws Exception {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
assertEquals(3, stpa.getCharacterStyles().length); // Set for the appropriate text sizes
assertEquals(3, stpb.getCharacterStyles().length); stpa.setParentTextSize(data_a_text_len);
stpb.setParentTextSize(data_b_text_len);
// In both cases, we should only have 1 paragraph styling
assertEquals(1, stpa.getParagraphStyles().size());
assertEquals(1, stpb.getParagraphStyles().size());
} }
public void testCharacterLengths() throws Exception { public void testParagraphStyleCounts() throws Exception {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
// 54 chars, 21 + 17 (+ 16) // Set for the appropriate text sizes
assertEquals(54, stpa.getParagraphStyleCharactersCoveredLength() ); stpa.setParentTextSize(data_a_text_len);
CharacterStyle[] csa = stpa.getCharacterStyles(); stpb.setParentTextSize(data_b_text_len);
assertEquals(21, csa[0].getCharactersCoveredLength() );
assertEquals(17, csa[1].getCharactersCoveredLength() );
assertEquals(0, csa[2].getCharactersCoveredLength() );
// 83 chars, 30 + 28 (+ 25) // In both cases, we should have three different character stylings
assertEquals(83, stpb.getParagraphStyleCharactersCoveredLength() ); assertEquals(3, stpa.getCharacterStyles().size());
CharacterStyle[] csb = stpb.getCharacterStyles(); assertEquals(3, stpb.getCharacterStyles().size());
assertEquals(30, csb[0].getCharactersCoveredLength() );
assertEquals(28, csb[1].getCharactersCoveredLength() );
assertEquals(0, csb[2].getCharactersCoveredLength() );
} }
public void testCharacterProps() throws Exception {
public void testCharacterStyleLengths() throws Exception {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length); StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
// Set A has no styles // Set for the appropriate text sizes
CharacterStyle[] csa = stpa.getCharacterStyles(); stpa.setParentTextSize(data_a_text_len);
for(int i=0; i<csa.length; i++) { stpb.setParentTextSize(data_b_text_len);
assertEquals(false, csa[i].isBold() );
assertEquals(false, csa[i].isItalic() );
assertEquals(false, csa[i].isUnderlined() );
}
// Set B - 1st bold, 2nd italic // 54 chars, 21 + 17 + 16
CharacterStyle[] csb = stpb.getCharacterStyles(); LinkedList a_ch_l = stpa.getCharacterStyles();
assertEquals(true, csb[0].isBold() ); TextPropCollection a_ch_1 = (TextPropCollection)a_ch_l.get(0);
assertEquals(true, csb[1].isItalic() ); TextPropCollection a_ch_2 = (TextPropCollection)a_ch_l.get(1);
} TextPropCollection a_ch_3 = (TextPropCollection)a_ch_l.get(2);
assertEquals(21, a_ch_1.getCharactersCovered());
assertEquals(17, a_ch_2.getCharactersCovered());
assertEquals(16, a_ch_3.getCharactersCovered());
public void testChangeCharacterProps() throws Exception { // 83 chars, 30 + 28 + 25
// Change from A to B LinkedList b_ch_l = stpb.getCharacterStyles();
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length); TextPropCollection b_ch_1 = (TextPropCollection)b_ch_l.get(0);
CharacterStyle[] csa = stpa.getCharacterStyles(); TextPropCollection b_ch_2 = (TextPropCollection)b_ch_l.get(1);
TextPropCollection b_ch_3 = (TextPropCollection)b_ch_l.get(2);
// Update paragraph length assertEquals(30, b_ch_1.getCharactersCovered());
stpa.setParagraphStyleCharactersCoveredLength(83); assertEquals(28, b_ch_2.getCharactersCovered());
assertEquals(25, b_ch_3.getCharactersCovered());
// Update each of the Character Styles
// First is 30 long and bold
csa[0].setCharactersCoveredLength(30);
csa[0].setBold(true);
// Second is 28 long and italic
csa[1].setCharactersCoveredLength(28);
csa[1].setItalic(true);
// Ensure now matches data from B
// Disabled, as it currently doesn't, as we don't know about
// everything that needs updating, esp the S2 values
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// stpa.writeOut(baos);
// byte[] b = baos.toByteArray();
//
// assertEquals(data_b.length, b.length);
// for(int i=0; i<data_b.length; i++) {
// assertEquals(data_b[i],b[i]);
// }
} }
public void testWrite() throws Exception { public void testWrite() throws Exception {
@ -140,4 +124,18 @@ public class TestStyleTextPropAtom extends TestCase {
assertEquals(data_a[i],b[i]); assertEquals(data_a[i],b[i]);
} }
} }
public void testLoadWrite() throws Exception {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
stpa.setParentTextSize(data_a_text_len);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
stpa.writeOut(baos);
byte[] b = baos.toByteArray();
assertEquals(data_a.length, b.length);
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],b[i]);
}
}
} }