01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: 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;
25:
26: public class TestDocumentProperties extends TestCase {
27: private DocumentProperties _documentProperties = null;
28: private HWPFDocFixture _hWPFDocFixture;
29:
30: public TestDocumentProperties(String name) {
31: super (name);
32: }
33:
34: public void testReadWrite() throws Exception {
35: int size = _documentProperties.getSize();
36: byte[] buf = new byte[size];
37:
38: _documentProperties.serialize(buf, 0);
39:
40: DocumentProperties newDocProperties = new DocumentProperties(
41: buf, 0);
42:
43: Field[] fields = DocumentProperties.class.getSuperclass()
44: .getDeclaredFields();
45: AccessibleObject.setAccessible(fields, true);
46:
47: for (int x = 0; x < fields.length; x++) {
48: if (!fields[x].getType().isArray()) {
49: assertEquals(fields[x].get(_documentProperties),
50: fields[x].get(newDocProperties));
51: } else {
52: byte[] buf1 = (byte[]) fields[x]
53: .get(_documentProperties);
54: byte[] buf2 = (byte[]) fields[x].get(newDocProperties);
55: Arrays.equals(buf1, buf2);
56: }
57: }
58:
59: }
60:
61: protected void setUp() throws Exception {
62: super .setUp();
63: /**@todo verify the constructors*/
64:
65: _hWPFDocFixture = new HWPFDocFixture(this );
66:
67: _hWPFDocFixture.setUp();
68:
69: _documentProperties = new DocumentProperties(
70: _hWPFDocFixture._tableStream, _hWPFDocFixture._fib
71: .getFcDop());
72: }
73:
74: protected void tearDown() throws Exception {
75: _documentProperties = null;
76: _hWPFDocFixture.tearDown();
77:
78: _hWPFDocFixture = null;
79: super.tearDown();
80: }
81:
82: }
|