~ubuntu-branches/ubuntu/utopic/libcommons-compress-java/utopic

« back to all changes in this revision

Viewing changes to src/test/java/org/apache/commons/compress/archivers/LongPathTest.java

  • Committer: Package Import Robot
  • Author(s): Emmanuel Bourg
  • Date: 2013-11-02 13:55:47 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20131102135547-nhcubj3ae7rv6t13
Tags: 1.6-1
* New upstream release
* Updated Standards-Version to 3.9.5 (no changes)
* Build depend on debhelper >= 9
* Removed the unused debian/orig-tar.sh script

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import java.io.FileReader;
26
26
import java.io.IOException;
27
27
import java.util.ArrayList;
 
28
import java.util.Map;
 
29
import java.util.HashMap;
28
30
 
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;
38
41
 
44
47
 */
45
48
public class LongPathTest extends AbstractTestCase {
46
49
 
 
50
    private String name;
47
51
    private File file;
48
52
 
49
 
    private static final ArrayList<String> fileList = new ArrayList<String>();
 
53
    private static final Map<String, ArrayList<String>> fileLists = new HashMap<String, ArrayList<String>>();
50
54
 
51
55
    public LongPathTest(String name) {
52
56
        super(name);
53
57
    }
54
58
 
55
 
    private LongPathTest(String name, File file){
56
 
        super(name);
 
59
    private LongPathTest(String name, String function, File file) {
 
60
        super(function);
 
61
        this.name = name;
57
62
        this.file = file;
58
63
    }
59
64
 
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"));
 
69
        return suite;
 
70
    }
 
71
 
 
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));
 
79
 
 
80
        ArrayList<String> fileList = new ArrayList<String>();
67
81
        String line;
68
82
        while ((line=br.readLine())!=null){
69
83
            if (line.startsWith("#")){
71
85
            }
72
86
            fileList.add(line);
73
87
        }
 
88
        fileLists.put(name, fileList);
74
89
        br.close();
75
90
        File[]files=arcdir.listFiles();
76
91
        for (final File file : files) {
79
94
            }
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);
85
100
        }
86
101
        return suite;
87
102
    }
88
103
 
 
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();
 
109
            }
 
110
        }
 
111
        return entry.getName();
 
112
    }
 
113
 
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();