1 2 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 31 public class TestClassID extends TestCase 32 { 33 38 public TestClassID(final String name) 39 { 40 super(name); 41 } 42 43 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 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 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 e) 96 { 97 bExceptionOccurred = true; 98 } 99 Assert.assertTrue(bExceptionOccurred); 100 101 bExceptionOccurred = false; 103 try 104 { 105 clsidTest.write(new byte[16], 0); 106 clsidTest.write(new byte[17], 1); 107 } 108 catch (Exception e) 109 { 110 bExceptionOccurred = true; 111 } 112 Assert.assertFalse(bExceptionOccurred); 113 } 114 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 138 public static void main(final String [] 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 |