1 2 17 18 19 package org.apache.poi.hwpf.model; 20 21 import junit.framework.*; 22 import org.apache.poi.hwpf.*; 23 24 import org.apache.poi.util.LittleEndian; 25 26 public class TestPlexOfCps 27 extends TestCase 28 { 29 private PlexOfCps _plexOfCps = null; 30 private HWPFDocFixture _hWPFDocFixture; 31 32 public TestPlexOfCps(String name) 33 { 34 super(name); 35 } 36 public void testWriteRead() 37 throws Exception 38 { 39 _plexOfCps = new PlexOfCps(4); 40 41 int last = 0; 42 for (int x = 0; x < 110; x++) 43 { 44 byte[] intHolder = new byte[4]; 45 int span = (int)(110.0f * Math.random()); 46 LittleEndian.putInt(intHolder, span); 47 _plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder)); 48 last += span; 49 } 50 51 byte[] output = _plexOfCps.toByteArray(); 52 _plexOfCps = new PlexOfCps(output, 0, output.length, 4); 53 int len = _plexOfCps.length(); 54 assertEquals(len, 110); 55 56 last = 0; 57 for (int x = 0; x < len; x++) 58 { 59 GenericPropertyNode node = _plexOfCps.getProperty(x); 60 assertEquals(node.getStart(), last); 61 last = node.getEnd(); 62 int span = LittleEndian.getInt(node.getBytes()); 63 assertEquals(node.getEnd()-node.getStart(), span); 64 } 65 } 66 protected void setUp() 67 throws Exception 68 { 69 super.setUp(); 70 71 _hWPFDocFixture = new HWPFDocFixture(this); 72 73 _hWPFDocFixture.setUp(); 74 } 75 76 protected void tearDown() 77 throws Exception 78 { 79 _plexOfCps = null; 80 _hWPFDocFixture.tearDown(); 81 82 _hWPFDocFixture = null; 83 super.tearDown(); 84 } 85 86 } 87 | Popular Tags |