KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hwpf > model > TestDocumentProperties


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

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 JavaDoc;
25
26 public class TestDocumentProperties
27   extends TestCase
28 {
29   private DocumentProperties _documentProperties = null;
30   private HWPFDocFixture _hWPFDocFixture;
31
32   public TestDocumentProperties(String JavaDoc name)
33   {
34     super(name);
35   }
36
37
38   public void testReadWrite()
39     throws Exception JavaDoc
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 JavaDoc
71   {
72     super.setUp();
73     /**@todo verify the constructors*/
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 JavaDoc
84   {
85     _documentProperties = null;
86     _hWPFDocFixture.tearDown();
87
88     _hWPFDocFixture = null;
89     super.tearDown();
90   }
91
92 }
93
Popular Tags