Source Code Cross Referenced for AsiExtraFieldTest.java in  » Build » ANT » org » apache » tools » zip » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Build » ANT » org.apache.tools.zip 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         *
017:         */
018:
019:        package org.apache.tools.zip;
020:
021:        import junit.framework.TestCase;
022:
023:        /**
024:         * JUnit 3 testcases for org.apache.tools.zip.AsiExtraField.
025:         *
026:         */
027:        public class AsiExtraFieldTest extends TestCase implements  UnixStat {
028:            public AsiExtraFieldTest(String name) {
029:                super (name);
030:            }
031:
032:            /**
033:             * Test file mode magic.
034:             */
035:            public void testModes() {
036:                AsiExtraField a = new AsiExtraField();
037:                a.setMode(0123);
038:                assertEquals("plain file", 0100123, a.getMode());
039:                a.setDirectory(true);
040:                assertEquals("directory", 040123, a.getMode());
041:                a.setLinkedFile("test");
042:                assertEquals("symbolic link", 0120123, a.getMode());
043:            }
044:
045:            /**
046:             * Test content.
047:             */
048:            public void testContent() {
049:                AsiExtraField a = new AsiExtraField();
050:                a.setMode(0123);
051:                a.setUserId(5);
052:                a.setGroupId(6);
053:                byte[] b = a.getLocalFileDataData();
054:
055:                // CRC manually calculated, sorry
056:                byte[] expect = { (byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
057:                        0123, (byte) 0x80, // mode
058:                        0, 0, 0, 0, // link length
059:                        5, 0, 6, 0 }; // uid, gid
060:                assertEquals("no link", expect.length, b.length);
061:                for (int i = 0; i < expect.length; i++) {
062:                    assertEquals("no link, byte " + i, expect[i], b[i]);
063:                }
064:
065:                a.setLinkedFile("test");
066:                expect = new byte[] { 0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
067:                        0123, (byte) 0xA0, // mode
068:                        4, 0, 0, 0, // link length
069:                        5, 0, 6, 0, // uid, gid
070:                        (byte) 't', (byte) 'e', (byte) 's', (byte) 't' };
071:                b = a.getLocalFileDataData();
072:                assertEquals("no link", expect.length, b.length);
073:                for (int i = 0; i < expect.length; i++) {
074:                    assertEquals("no link, byte " + i, expect[i], b[i]);
075:                }
076:
077:            }
078:
079:            /**
080:             * Test reparse
081:             */
082:            public void testReparse() throws Exception {
083:                // CRC manually calculated, sorry
084:                byte[] data = { (byte) 0xC6, 0x02, 0x78, (byte) 0xB6, // CRC
085:                        0123, (byte) 0x80, // mode
086:                        0, 0, 0, 0, // link length
087:                        5, 0, 6, 0 }; // uid, gid
088:                AsiExtraField a = new AsiExtraField();
089:                a.parseFromLocalFileData(data, 0, data.length);
090:                assertEquals("length plain file", data.length, a
091:                        .getLocalFileDataLength().getValue());
092:                assertTrue("plain file, no link", !a.isLink());
093:                assertTrue("plain file, no dir", !a.isDirectory());
094:                assertEquals("mode plain file", FILE_FLAG | 0123, a.getMode());
095:                assertEquals("uid plain file", 5, a.getUserId());
096:                assertEquals("gid plain file", 6, a.getGroupId());
097:
098:                data = new byte[] { 0x75, (byte) 0x8E, 0x41, (byte) 0xFD, // CRC
099:                        0123, (byte) 0xA0, // mode
100:                        4, 0, 0, 0, // link length
101:                        5, 0, 6, 0, // uid, gid
102:                        (byte) 't', (byte) 'e', (byte) 's', (byte) 't' };
103:                a = new AsiExtraField();
104:                a.parseFromLocalFileData(data, 0, data.length);
105:                assertEquals("length link", data.length, a
106:                        .getLocalFileDataLength().getValue());
107:                assertTrue("link, is link", a.isLink());
108:                assertTrue("link, no dir", !a.isDirectory());
109:                assertEquals("mode link", LINK_FLAG | 0123, a.getMode());
110:                assertEquals("uid link", 5, a.getUserId());
111:                assertEquals("gid link", 6, a.getGroupId());
112:                assertEquals("test", a.getLinkedFile());
113:
114:                data = new byte[] { (byte) 0x8E, 0x01, (byte) 0xBF,
115:                        (byte) 0x0E, // CRC
116:                        0123, (byte) 0x40, // mode
117:                        0, 0, 0, 0, // link
118:                        5, 0, 6, 0 }; // uid, gid
119:                a = new AsiExtraField();
120:                a.parseFromLocalFileData(data, 0, data.length);
121:                assertEquals("length dir", data.length, a
122:                        .getLocalFileDataLength().getValue());
123:                assertTrue("dir, no link", !a.isLink());
124:                assertTrue("dir, is dir", a.isDirectory());
125:                assertEquals("mode dir", DIR_FLAG | 0123, a.getMode());
126:                assertEquals("uid dir", 5, a.getUserId());
127:                assertEquals("gid dir", 6, a.getGroupId());
128:
129:                data = new byte[] { 0, 0, 0, 0, // bad CRC
130:                        0123, (byte) 0x40, // mode
131:                        0, 0, 0, 0, // link
132:                        5, 0, 6, 0 }; // uid, gid
133:                a = new AsiExtraField();
134:                try {
135:                    a.parseFromLocalFileData(data, 0, data.length);
136:                    fail("should raise bad CRC exception");
137:                } catch (Exception e) {
138:                    assertEquals("bad CRC checksum 0 instead of ebf018e", e
139:                            .getMessage());
140:                }
141:            }
142:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.