1 2 17 18 package org.apache.poi.hwpf.model; 19 20 import junit.framework.*; 21 import org.apache.poi.hwpf.*; 22 23 import java.lang.reflect.*; 24 import java.util.Arrays ; 25 26 public class TestDocumentProperties 27 extends TestCase 28 { 29 private DocumentProperties _documentProperties = null; 30 private HWPFDocFixture _hWPFDocFixture; 31 32 public TestDocumentProperties(String name) 33 { 34 super(name); 35 } 36 37 38 public void testReadWrite() 39 throws Exception 40 { 41 int size = _documentProperties.getSize(); 42 byte[] buf = new byte[size]; 43 44 _documentProperties.serialize(buf, 0); 45 46 DocumentProperties newDocProperties = 47 new DocumentProperties(buf, 0); 48 49 Field[] fields = DocumentProperties.class.getSuperclass().getDeclaredFields(); 50 AccessibleObject.setAccessible(fields, true); 51 52 for (int x = 0; x < fields.length; x++) 53 { 54 if (!fields[x].getType().isArray()) 55 { 56 assertEquals(fields[x].get(_documentProperties), 57 fields[x].get(newDocProperties)); 58 } 59 else 60 { 61 byte[] buf1 = (byte[])fields[x].get(_documentProperties); 62 byte[] buf2 = (byte[])fields[x].get(newDocProperties); 63 Arrays.equals(buf1, buf2); 64 } 65 } 66 67 } 68 69 protected void setUp() 70 throws Exception 71 { 72 super.setUp(); 73 74 75 _hWPFDocFixture = new HWPFDocFixture(this); 76 77 _hWPFDocFixture.setUp(); 78 79 _documentProperties = new DocumentProperties(_hWPFDocFixture._tableStream, _hWPFDocFixture._fib.getFcDop()); 80 } 81 82 protected void tearDown() 83 throws Exception 84 { 85 _documentProperties = null; 86 _hWPFDocFixture.tearDown(); 87 88 _hWPFDocFixture = null; 89 super.tearDown(); 90 } 91 92 } 93 | Popular Tags |