1 17 18 package org.apache.tools.zip; 19 20 import junit.framework.TestCase; 21 22 26 public class ZipShortTest extends TestCase { 27 28 public ZipShortTest(String name) { 29 super(name); 30 } 31 32 35 public void testToBytes() { 36 ZipShort zs = new ZipShort(0x1234); 37 byte[] result = zs.getBytes(); 38 assertEquals("length getBytes", 2, result.length); 39 assertEquals("first byte getBytes", 0x34, result[0]); 40 assertEquals("second byte getBytes", 0x12, result[1]); 41 } 42 43 46 public void testFromBytes() { 47 byte[] val = new byte[] {0x34, 0x12}; 48 ZipShort zs = new ZipShort(val); 49 assertEquals("value from bytes", 0x1234, zs.getValue()); 50 } 51 52 55 public void testEquals() { 56 ZipShort zs = new ZipShort(0x1234); 57 ZipShort zs2 = new ZipShort(0x1234); 58 ZipShort zs3 = new ZipShort(0x5678); 59 60 assertTrue("reflexive", zs.equals(zs)); 61 62 assertTrue("works", zs.equals(zs2)); 63 assertTrue("works, part two", !zs.equals(zs3)); 64 65 assertTrue("symmetric", zs2.equals(zs)); 66 67 assertTrue("null handling", !zs.equals(null)); 68 assertTrue("non ZipShort handling", !zs.equals(new Integer (0x1234))); 69 } 70 71 74 public void testSign() { 75 ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF}); 76 assertEquals(0x0000FFFF, zs.getValue()); 77 } 78 79 } 80 | Popular Tags |