KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 JavaDoc name)
33   {
34     super(name);
35   }
36   public void testWriteRead()
37     throws Exception JavaDoc
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 JavaDoc
68   {
69     super.setUp();
70     /**@todo verify the constructors*/
71     _hWPFDocFixture = new HWPFDocFixture(this);
72
73     _hWPFDocFixture.setUp();
74   }
75
76   protected void tearDown()
77     throws Exception JavaDoc
78   {
79     _plexOfCps = null;
80     _hWPFDocFixture.tearDown();
81
82     _hWPFDocFixture = null;
83     super.tearDown();
84   }
85
86 }
87
Popular Tags