25
25
import java.io.FileReader;
26
26
import java.io.IOException;
27
27
import java.util.ArrayList;
29
import java.util.HashMap;
29
31
import junit.framework.AssertionFailedError;
30
32
import junit.framework.Test;
33
35
import org.apache.commons.compress.AbstractTestCase;
34
36
import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
35
37
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
38
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
36
39
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
37
40
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
45
48
public class LongPathTest extends AbstractTestCase {
49
private static final ArrayList<String> fileList = new ArrayList<String>();
53
private static final Map<String, ArrayList<String>> fileLists = new HashMap<String, ArrayList<String>>();
51
55
public LongPathTest(String name) {
55
private LongPathTest(String name, File file){
59
private LongPathTest(String name, String function, File file) {
60
65
public static TestSuite suite() throws IOException{
61
66
TestSuite suite = new TestSuite("LongPathTests");
62
File arcdir = getFile("longpath");
67
suite.addTest(createSuite("LongPathTest", "longpath"));
68
suite.addTest(createSuite("LongSymlinkTest", "longsymlink"));
72
public static TestSuite createSuite(String name, String dirname) throws IOException {
73
TestSuite suite = new TestSuite(name);
74
File arcdir = getFile(dirname);
63
75
assertTrue(arcdir.exists());
64
76
File listing= new File(arcdir,"files.txt");
65
77
assertTrue("File listing is readable",listing.canRead());
66
78
BufferedReader br = new BufferedReader(new FileReader(listing));
80
ArrayList<String> fileList = new ArrayList<String>();
68
82
while ((line=br.readLine())!=null){
69
83
if (line.startsWith("#")){
80
95
// Appears to be the only way to give the test a variable name
81
96
TestSuite namedSuite = new TestSuite(file.getName());
82
Test test = new LongPathTest("testArchive", file);
97
Test test = new LongPathTest(name, "testArchive", file);
83
98
namedSuite.addTest(test);
84
99
suite.addTest(namedSuite);
104
protected String getExpectedString(ArchiveEntry entry) {
105
if (entry instanceof TarArchiveEntry) {
106
TarArchiveEntry tarEntry = (TarArchiveEntry) entry;
107
if (tarEntry.isSymbolicLink()) {
108
return tarEntry.getName() + " -> " + tarEntry.getLinkName();
111
return entry.getName();
89
114
public void testArchive() throws Exception {
115
ArrayList<String> fileList = fileLists.get(name);
90
116
@SuppressWarnings("unchecked") // fileList is of correct type
91
117
ArrayList<String> expected = (ArrayList<String>) fileList.clone();
92
118
String name = file.getName();