1 17 18 package org.apache.tools.zip; 19 20 import junit.framework.TestCase; 21 22 26 public class AsiExtraFieldTest extends TestCase implements UnixStat { 27 public AsiExtraFieldTest(String name) { 28 super(name); 29 } 30 31 34 public void testModes() { 35 AsiExtraField a = new AsiExtraField(); 36 a.setMode(0123); 37 assertEquals("plain file", 0100123, a.getMode()); 38 a.setDirectory(true); 39 assertEquals("directory", 040123, a.getMode()); 40 a.setLinkedFile("test"); 41 assertEquals("symbolic link", 0120123, a.getMode()); 42 } 43 44 47 public void testContent() { 48 AsiExtraField a = new AsiExtraField(); 49 a.setMode(0123); 50 a.setUserId(5); 51 a.setGroupId(6); 52 byte[] b = a.getLocalFileDataData(); 53 54 byte[] expect = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, 0123, (byte)0x80, 0, 0, 0, 0, 5, 0, 6, 0}; assertEquals("no link", expect.length, b.length); 60 for (int i=0; i<expect.length; i++) { 61 assertEquals("no link, byte "+i, expect[i], b[i]); 62 } 63 64 a.setLinkedFile("test"); 65 expect = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, 0123, (byte)0xA0, 4, 0, 0, 0, 5, 0, 6, 0, (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; 70 b = a.getLocalFileDataData(); 71 assertEquals("no link", expect.length, b.length); 72 for (int i=0; i<expect.length; i++) { 73 assertEquals("no link, byte "+i, expect[i], b[i]); 74 } 75 76 } 77 78 81 public void testReparse() throws Exception { 82 byte[] data = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, 0123, (byte)0x80, 0, 0, 0, 0, 5, 0, 6, 0}; AsiExtraField a = new AsiExtraField(); 88 a.parseFromLocalFileData(data, 0, data.length); 89 assertEquals("length plain file", data.length, 90 a.getLocalFileDataLength().getValue()); 91 assertTrue("plain file, no link", !a.isLink()); 92 assertTrue("plain file, no dir", !a.isDirectory()); 93 assertEquals("mode plain file", FILE_FLAG | 0123, a.getMode()); 94 assertEquals("uid plain file", 5, a.getUserId()); 95 assertEquals("gid plain file", 6, a.getGroupId()); 96 97 data = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, 0123, (byte)0xA0, 4, 0, 0, 0, 5, 0, 6, 0, (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; 102 a = new AsiExtraField(); 103 a.parseFromLocalFileData(data, 0, data.length); 104 assertEquals("length link", data.length, 105 a.getLocalFileDataLength().getValue()); 106 assertTrue("link, is link", a.isLink()); 107 assertTrue("link, no dir", !a.isDirectory()); 108 assertEquals("mode link", LINK_FLAG | 0123, a.getMode()); 109 assertEquals("uid link", 5, a.getUserId()); 110 assertEquals("gid link", 6, a.getGroupId()); 111 assertEquals("test", a.getLinkedFile()); 112 113 data = new byte[] {(byte)0x8E, 0x01, (byte)0xBF, (byte)0x0E, 0123, (byte)0x40, 0, 0, 0, 0, 5, 0, 6, 0}; a = new AsiExtraField(); 118 a.parseFromLocalFileData(data, 0, data.length); 119 assertEquals("length dir", data.length, 120 a.getLocalFileDataLength().getValue()); 121 assertTrue("dir, no link", !a.isLink()); 122 assertTrue("dir, is dir", a.isDirectory()); 123 assertEquals("mode dir", DIR_FLAG | 0123, a.getMode()); 124 assertEquals("uid dir", 5, a.getUserId()); 125 assertEquals("gid dir", 6, a.getGroupId()); 126 127 data = new byte[] {0, 0, 0, 0, 0123, (byte)0x40, 0, 0, 0, 0, 5, 0, 6, 0}; a = new AsiExtraField(); 132 try { 133 a.parseFromLocalFileData(data, 0, data.length); 134 fail("should raise bad CRC exception"); 135 } catch (Exception e) { 136 assertEquals("bad CRC checksum 0 instead of ebf018e", 137 e.getMessage()); 138 } 139 } 140 } 141 | Popular Tags |