1 | package org.armedbear.lisp; |
---|
2 | |
---|
3 | import java.io.FileNotFoundException; |
---|
4 | import static org.junit.Assert.*; |
---|
5 | |
---|
6 | import java.io.File; |
---|
7 | import java.io.FileInputStream; |
---|
8 | import java.io.FileWriter; |
---|
9 | import org.junit.Test; |
---|
10 | import java.io.IOException; |
---|
11 | import java.io.InputStream; |
---|
12 | import java.util.jar.JarFile; |
---|
13 | import java.util.jar.JarInputStream; |
---|
14 | import java.util.zip.ZipEntry; |
---|
15 | import java.util.zip.ZipInputStream; |
---|
16 | import org.junit.Before; |
---|
17 | |
---|
18 | public class ZipTest |
---|
19 | { |
---|
20 | // FIXME These need to be created as part of executing the tests |
---|
21 | String zipFile = "/Users/evenson/work/abcl/dist/abcl-contrib.jar"; |
---|
22 | // created via |
---|
23 | // (require :abcl-contrib) |
---|
24 | // (asdf:load-system :asdf-jar) |
---|
25 | // (asdf-jar:package :cl-ppcre) |
---|
26 | String nestedJarFile = "/var/tmp/cl-ppcre-all-2.1.1.jar"; |
---|
27 | JarPathname zip; |
---|
28 | JarPathname nestedJar; |
---|
29 | |
---|
30 | @Before |
---|
31 | public void setup() { |
---|
32 | zip = (JarPathname) JarPathname.createFromFile(zipFile); |
---|
33 | nestedJar = (JarPathname) JarPathname.createFromFile(nestedJarFile); |
---|
34 | } |
---|
35 | |
---|
36 | @Test |
---|
37 | public void getArchive() { |
---|
38 | ZipCache.Archive archive1 = ZipCache.getArchive(zip); |
---|
39 | assertTrue("Get ZipArchive from pathname", |
---|
40 | archive1 instanceof ZipCache.ArchiveFile |
---|
41 | && ((ZipCache.ArchiveFile)archive1).file != null); |
---|
42 | JarPathname zip2 |
---|
43 | = (JarPathname) JarPathname.createFromFile(zipFile); |
---|
44 | ZipCache.Archive archive2 = ZipCache.getArchive(zip2); |
---|
45 | assertTrue("Get cached ZipArchive from pathname", |
---|
46 | archive2 instanceof ZipCache.ArchiveFile |
---|
47 | && ((ZipCache.ArchiveFile)archive2).file != null); |
---|
48 | assertTrue("Cached ZipArchive refers to same entry", |
---|
49 | archive2.equals(archive1)); |
---|
50 | } |
---|
51 | |
---|
52 | @Test |
---|
53 | public void getEntry() { |
---|
54 | String entryPath = "abcl-asdf/abcl-asdf-tests.asd"; |
---|
55 | JarPathname entryPathname |
---|
56 | = (JarPathname) JarPathname.createEntryFromFile(zipFile, entryPath); |
---|
57 | ZipEntry entry = ZipCache.getZipEntry(entryPathname); |
---|
58 | assertTrue("Getting entry from jar", |
---|
59 | entry.getName().equals(entryPath)); |
---|
60 | JarPathname entryPathname2 |
---|
61 | = (JarPathname) JarPathname.createEntryFromFile(zipFile, entryPath); |
---|
62 | ZipEntry entry2 = ZipCache.getZipEntry(entryPathname2); |
---|
63 | assertTrue("Cached ZipEntry returns same object", |
---|
64 | entry.equals(entry2)); |
---|
65 | } |
---|
66 | |
---|
67 | @Test |
---|
68 | public void getNestedJar() { |
---|
69 | String nestedNamestring = "jar:jar:file:/var/tmp/cl-ppcre-all-2.1.1.jar!/cl-ppcre/packages.abcl!/"; |
---|
70 | JarPathname nested = (JarPathname)JarPathname.create(nestedNamestring); |
---|
71 | ZipCache.Archive archive = ZipCache.getArchive(nested); |
---|
72 | assertTrue("Able to retrieve nested jar archive", |
---|
73 | !archive.equals(null)); |
---|
74 | } |
---|
75 | |
---|
76 | // @Test |
---|
77 | public void getNestedJarEntry() { |
---|
78 | String nestedNamestring = "jar:jar:file:/var/tmp/cl-ppcre-all-2.1.1.jar!/cl-ppcre/packages.abcl!/__loader__._"; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | // @Test |
---|
85 | // public void getZipEntry() throws FileNotFoundException, IOException { |
---|
86 | // FileInputStream inputFile = new FileInputStream(zipFile); |
---|
87 | // ZipInputStream input = new ZipInputStream(inputFile); |
---|
88 | // ZipEntry entry = ZipCache.getEntry(input, "a/b/bar.abcl"); |
---|
89 | // assertNotNull(entry); |
---|
90 | // input.close(); |
---|
91 | // inputFile.close(); |
---|
92 | // } |
---|
93 | |
---|
94 | // @Test |
---|
95 | // public void getZipInputStreamZipEntry() throws FileNotFoundException, IOException { |
---|
96 | // JarFile jar = new JarFile(zipFile); |
---|
97 | // Pathname pathname = (Pathname)Pathname.create("a/b/bar.abcl"); |
---|
98 | // InputStream entryInputStream = ZipCache.getInputStream(jar, pathname); |
---|
99 | // assertNotNull(entryInputStream); |
---|
100 | // ZipInputStream zip = new ZipInputStream(entryInputStream); |
---|
101 | // assertNotNull(zip); |
---|
102 | // ZipEntry entry = ZipCache.getEntry(zip, "bar._"); |
---|
103 | // assertNotNull(entry); |
---|
104 | // } |
---|
105 | |
---|
106 | |
---|
107 | } |
---|