1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.commons.compress;
20
21 import java.io.BufferedReader;
22 import java.io.File;
23 import java.io.FileReader;
24 import java.io.IOException;
25 import java.util.ArrayList;
26
27 import junit.framework.Test;
28 import junit.framework.TestSuite;
29
30 import org.apache.commons.compress.archivers.ArchiveEntry;
31 import org.apache.commons.compress.archivers.ArchiveException;
32
33
34
35
36
37
38
39
40
41
42
43
44 public class ArchiveReadTests extends AbstractTestCase {
45
46 final static ClassLoader classLoader = ArchiveReadTests.class.getClassLoader();
47
48 private File file;
49 private static final ArrayList<String> fileList = new ArrayList<String>();
50
51 public ArchiveReadTests(String name) {
52 super(name);
53 }
54
55 private ArchiveReadTests(String name, File file){
56 super(name);
57 this.file = file;
58 }
59
60 public static TestSuite suite() throws IOException{
61 TestSuite suite = new TestSuite("ArchiveReadTests");
62 File arcdir =new File(classLoader.getResource("archives").getFile());
63 assertTrue(arcdir.exists());
64 File listing= new File(arcdir,"files.txt");
65 assertTrue("files.txt is readable",listing.canRead());
66 BufferedReader br = new BufferedReader(new FileReader(listing));
67 String line;
68 while ((line=br.readLine())!=null){
69 if (line.startsWith("#")){
70 continue;
71 }
72 fileList.add(line);
73 }
74 br.close();
75 File[]files=arcdir.listFiles();
76 for (final File file : files) {
77 if (file.getName().endsWith(".txt")){
78 continue;
79 }
80
81 TestSuite namedSuite = new TestSuite(file.getName());
82 Test test = new ArchiveReadTests("testArchive", file);
83 namedSuite.addTest(test);
84 suite.addTest(namedSuite);
85 }
86 return suite;
87 }
88
89
90 @Override
91 protected String getExpectedString(ArchiveEntry entry) {
92 return entry.getSize() + " " + entry.getName();
93 }
94
95 public void testArchive() throws Exception{
96 @SuppressWarnings("unchecked")
97 ArrayList<String> expected= (ArrayList<String>) fileList.clone();
98 try {
99 checkArchiveContent(file, expected);
100 } catch (ArchiveException e) {
101 fail("Problem checking "+file);
102 }
103 }
104 }