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 org.apache.poi.util.LittleEndian;
24:
25: public class TestPlexOfCps extends TestCase {
26: private PlexOfCps _plexOfCps = null;
27: private HWPFDocFixture _hWPFDocFixture;
28:
29: public TestPlexOfCps(String name) {
30: super (name);
31: }
32:
33: public void testWriteRead() throws Exception {
34: _plexOfCps = new PlexOfCps(4);
35:
36: int last = 0;
37: for (int x = 0; x < 110; x++) {
38: byte[] intHolder = new byte[4];
39: int span = (int) (110.0f * Math.random());
40: LittleEndian.putInt(intHolder, span);
41: _plexOfCps.addProperty(new GenericPropertyNode(last, last
42: + span, intHolder));
43: last += span;
44: }
45:
46: byte[] output = _plexOfCps.toByteArray();
47: _plexOfCps = new PlexOfCps(output, 0, output.length, 4);
48: int len = _plexOfCps.length();
49: assertEquals(len, 110);
50:
51: last = 0;
52: for (int x = 0; x < len; x++) {
53: GenericPropertyNode node = _plexOfCps.getProperty(x);
54: assertEquals(node.getStart(), last);
55: last = node.getEnd();
56: int span = LittleEndian.getInt(node.getBytes());
57: assertEquals(node.getEnd() - node.getStart(), span);
58: }
59: }
60:
61: protected void setUp() throws Exception {
62: super .setUp();
63: /**@todo verify the constructors*/
64: _hWPFDocFixture = new HWPFDocFixture(this );
65:
66: _hWPFDocFixture.setUp();
67: }
68:
69: protected void tearDown() throws Exception {
70: _plexOfCps = null;
71: _hWPFDocFixture.tearDown();
72:
73: _hWPFDocFixture = null;
74: super.tearDown();
75: }
76:
77: }
|