KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hpsf > basic > TestClassID


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.hpsf.basic;
20
21 import junit.framework.Assert;
22 import junit.framework.TestCase;
23
24 import org.apache.poi.hpsf.ClassID;
25
26 /**
27  * <p>Tests ClassID structure.</p>
28  *
29  * @author Michael Zalewski (zalewski@optonline.net)
30  */

31 public class TestClassID extends TestCase
32 {
33     /**
34      * <p>Constructor</p>
35      *
36      * @param name the test case's name
37      */

38     public TestClassID(final String JavaDoc name)
39     {
40         super(name);
41     }
42
43     /**
44      * Various tests of overridden .equals()
45      */

46     public void testEquals()
47     {
48         ClassID clsidTest1 = new ClassID(
49               new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
50                           0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
51             , 0
52         );
53         ClassID clsidTest2 = new ClassID(
54               new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
55                           0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
56             , 0
57         );
58         ClassID clsidTest3 = new ClassID(
59               new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
60                           0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x11 }
61             , 0
62         );
63         Assert.assertEquals(clsidTest1, clsidTest1);
64         Assert.assertEquals(clsidTest1, clsidTest2);
65         Assert.assertFalse(clsidTest1.equals(clsidTest3));
66         Assert.assertFalse(clsidTest1.equals(null));
67     }
68     /**
69      * Try to write to a buffer that is too small. This should
70      * throw an Exception
71      */

72     public void testWriteArrayStoreException()
73     {
74         ClassID clsidTest = new ClassID(
75               new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
76                           0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
77             , 0
78         );
79         boolean bExceptionOccurred = false;
80         try
81         {
82             clsidTest.write(new byte[15], 0);
83         }
84         catch (Exception JavaDoc e)
85         {
86             bExceptionOccurred = true;
87         }
88         Assert.assertTrue(bExceptionOccurred);
89
90         bExceptionOccurred = false;
91         try
92         {
93             clsidTest.write(new byte[16], 1);
94         }
95         catch (Exception JavaDoc e)
96         {
97             bExceptionOccurred = true;
98         }
99         Assert.assertTrue(bExceptionOccurred);
100
101         // These should work without throwing an Exception
102
bExceptionOccurred = false;
103         try
104         {
105             clsidTest.write(new byte[16], 0);
106             clsidTest.write(new byte[17], 1);
107         }
108         catch (Exception JavaDoc e)
109         {
110             bExceptionOccurred = true;
111         }
112         Assert.assertFalse(bExceptionOccurred);
113     }
114     /**
115      * <p>Tests the {@link PropertySet} methods. The test file has two
116      * property set: the first one is a {@link SummaryInformation},
117      * the second one is a {@link DocumentSummaryInformation}.</p>
118      */

119     public void testClassID()
120     {
121         ClassID clsidTest = new ClassID(
122               new byte[] {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
123                           0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10}
124             , 0
125         );
126         Assert.assertEquals(clsidTest.toString().toUpperCase(),
127                             "{04030201-0605-0807-090A-0B0C0D0E0F10}"
128         );
129     }
130
131
132
133     /**
134      * <p>Runs the test cases stand-alone.</p>
135      *
136      * @param args Command-line parameters (ignored)
137      */

138     public static void main(final String JavaDoc[] args)
139     {
140         System.setProperty("HPSF.testdata.path",
141                            "./src/testcases/org/apache/poi/hpsf/data");
142         junit.textui.TestRunner.run(TestClassID.class);
143     }
144
145 }
146
Popular Tags