|
1 | 1 | import com.github.difflib.DiffUtils;
|
2 | 2 | import com.github.difflib.algorithm.DiffException;
|
3 | 3 | import com.github.difflib.patch.Patch;
|
| 4 | +import org.junit.Assert; |
| 5 | +import org.junit.Ignore; |
| 6 | +import org.junit.Test; |
| 7 | +import org.junit.runner.RunWith; |
| 8 | +import org.junit.runners.Parameterized; |
| 9 | +import org.objectweb.asm.ClassReader; |
| 10 | +import org.objectweb.asm.util.TraceClassVisitor; |
| 11 | + |
4 | 12 | import java.io.ByteArrayOutputStream;
|
5 | 13 | import java.io.File;
|
6 | 14 | import java.io.FileInputStream;
|
|
10 | 18 | import java.util.ArrayList;
|
11 | 19 | import java.util.Collection;
|
12 | 20 | import java.util.List;
|
13 |
| -import org.junit.Assert; |
14 |
| -import org.junit.Ignore; |
15 |
| -import org.junit.Test; |
16 |
| -import org.junit.runner.RunWith; |
17 |
| -import org.junit.runners.Parameterized; |
18 |
| -import org.objectweb.asm.ClassReader; |
19 |
| -import org.objectweb.asm.util.TraceClassVisitor; |
20 | 21 |
|
21 | 22 | /**
|
22 | 23 | * Contains bytecode comparisons that are expected to fail
|
|
27 | 28 | @RunWith(Parameterized.class)
|
28 | 29 | public class ByteCodeCompareClasses {
|
29 | 30 |
|
30 |
| - private final String referenceFolder; |
31 |
| - private final String otherFolder; |
32 |
| - private final File filename; |
| 31 | + private final String referenceFolder; |
| 32 | + private final String otherFolder; |
| 33 | + private final File filename; |
33 | 34 |
|
34 |
| - @Parameterized.Parameters |
35 |
| - public static Collection<Object[]> generateParams() { |
36 |
| - List<Object[]> params = new ArrayList<Object[]>(); |
| 35 | + public ByteCodeCompareClasses(String referenceFolder, String otherFolder, File filename) { |
| 36 | + this.referenceFolder = referenceFolder; |
| 37 | + this.otherFolder = otherFolder; |
| 38 | + this.filename = filename; |
| 39 | + } |
37 | 40 |
|
38 |
| - params.addAll(createParaList("reference", "1.5")); |
39 |
| - params.addAll(createParaList("reference", "1.6")); |
40 |
| - params.addAll(createParaList("reference", "1.7")); |
| 41 | + @Parameterized.Parameters |
| 42 | + public static Collection<Object[]> generateParams() { |
| 43 | + List<Object[]> params = new ArrayList<Object[]>(); |
41 | 44 |
|
42 |
| - params.addAll(createParaList("reference", "ecj1.5")); |
43 |
| - params.addAll(createParaList("reference", "ecj1.6")); |
44 |
| - params.addAll(createParaList("reference", "ecj1.7")); |
45 |
| - params.addAll(createParaList("reference", "ecj1.8")); |
| 45 | + params.addAll(createParaList("reference", "1.5")); |
| 46 | + params.addAll(createParaList("reference", "1.6")); |
| 47 | + params.addAll(createParaList("reference", "1.7")); |
46 | 48 |
|
47 |
| - // params.addAll(createParaList("reference", "gcj1.5")); |
48 |
| - // params.addAll(createParaList("reference", "gcj1.6")); |
| 49 | + params.addAll(createParaList("reference", "ecj1.5")); |
| 50 | + params.addAll(createParaList("reference", "ecj1.6")); |
| 51 | + params.addAll(createParaList("reference", "ecj1.7")); |
| 52 | + params.addAll(createParaList("reference", "ecj1.8")); |
49 | 53 |
|
50 |
| - return params; |
51 |
| - } |
| 54 | + // params.addAll(createParaList("reference", "gcj1.5")); |
| 55 | + // params.addAll(createParaList("reference", "gcj1.6")); |
52 | 56 |
|
53 |
| - public static List<Object[]> createParaList(String refeFolder, String cmpFolder) { |
54 |
| - List<Object[]> params = new ArrayList<Object[]>(); |
| 57 | + return params; |
| 58 | + } |
55 | 59 |
|
56 |
| - URL url = ByteCodeCompareClasses.class.getResource("/" + refeFolder); |
57 |
| - File refClass = new File(url.getFile()); |
| 60 | + public static List<Object[]> createParaList(String refeFolder, String cmpFolder) { |
| 61 | + List<Object[]> params = new ArrayList<Object[]>(); |
58 | 62 |
|
59 |
| - // the other class |
60 |
| - URL otherurl = ByteCodeCompareClasses.class.getResource("/" + cmpFolder); |
61 |
| - String otherFolder = new File(otherurl.getFile()).toString(); |
| 63 | + URL url = ByteCodeCompareClasses.class.getResource("/" + refeFolder); |
| 64 | + File refClass = new File(url.getFile()); |
62 | 65 |
|
63 |
| - File[] listOfFiles = refClass.listFiles(); |
| 66 | + // the other class |
| 67 | + URL otherurl = ByteCodeCompareClasses.class.getResource("/" + cmpFolder); |
| 68 | + String otherFolder = new File(otherurl.getFile()).toString(); |
64 | 69 |
|
65 |
| - for (File filename : listOfFiles) { |
| 70 | + File[] listOfFiles = refClass.listFiles(); |
66 | 71 |
|
67 |
| - params.add(new Object[] {refClass.toString(), otherFolder, filename}); |
68 |
| - } |
69 |
| - return params; |
70 |
| - } |
| 72 | + for (File filename : listOfFiles) { |
71 | 73 |
|
72 |
| - public ByteCodeCompareClasses(String referenceFolder, String otherFolder, File filename) { |
73 |
| - this.referenceFolder = referenceFolder; |
74 |
| - this.otherFolder = otherFolder; |
75 |
| - this.filename = filename; |
76 |
| - } |
| 74 | + params.add(new Object[]{refClass.toString(), otherFolder, filename}); |
| 75 | + } |
| 76 | + return params; |
| 77 | + } |
77 | 78 |
|
78 |
| - @Test |
79 |
| - public void test() throws IOException, DiffException { |
80 |
| - String qname = filename.getName().substring(0, filename.getName().indexOf(".")); |
| 79 | + @Test |
| 80 | + public void test() throws IOException, DiffException { |
| 81 | + String qname = filename.getName().substring(0, filename.getName().indexOf(".")); |
81 | 82 |
|
82 |
| - System.out.println( |
83 |
| - "Compare " + referenceFolder + " against " + otherFolder + " using class " + qname); |
| 83 | + System.out.println( |
| 84 | + "Compare " + referenceFolder + " against " + otherFolder + " using class " + qname); |
84 | 85 |
|
85 |
| - ClassReader cr = new ClassReader(new FileInputStream(filename)); |
86 |
| - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 86 | + ClassReader cr = new ClassReader(new FileInputStream(filename)); |
| 87 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
87 | 88 |
|
88 |
| - cr.accept( |
89 |
| - new TraceClassVisitor(new PrintWriter(byteArrayOutputStream)), ClassReader.SKIP_DEBUG); |
| 89 | + cr.accept( |
| 90 | + new TraceClassVisitor(new PrintWriter(byteArrayOutputStream)), ClassReader.SKIP_DEBUG); |
90 | 91 |
|
91 |
| - String filename2 = otherFolder + "/" + qname + ".class"; |
92 |
| - ClassReader cr2 = new ClassReader(new FileInputStream(filename2)); |
93 |
| - ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream(); |
| 92 | + String filename2 = otherFolder + "/" + qname + ".class"; |
| 93 | + ClassReader cr2 = new ClassReader(new FileInputStream(filename2)); |
| 94 | + ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream(); |
94 | 95 |
|
95 |
| - cr2.accept( |
96 |
| - new TraceClassVisitor(new PrintWriter(byteArrayOutputStream2)), ClassReader.SKIP_DEBUG); |
| 96 | + cr2.accept( |
| 97 | + new TraceClassVisitor(new PrintWriter(byteArrayOutputStream2)), ClassReader.SKIP_DEBUG); |
97 | 98 |
|
98 |
| - Patch<String> diff = |
99 |
| - DiffUtils.diff(byteArrayOutputStream.toString(), byteArrayOutputStream2.toString(), null); |
100 |
| - System.out.println("Number of diffs: " + diff.getDeltas().size()); |
101 |
| - System.out.println(diff); |
| 99 | + Patch<String> diff = |
| 100 | + DiffUtils.diff(byteArrayOutputStream.toString(), byteArrayOutputStream2.toString(), null); |
| 101 | + System.out.println("Number of diffs: " + diff.getDeltas().size()); |
| 102 | + System.out.println(diff); |
102 | 103 |
|
103 |
| - boolean condition = diff.getDeltas().size() <= 1; |
| 104 | + boolean condition = diff.getDeltas().size() <= 1; |
104 | 105 |
|
105 |
| - System.out.println( |
106 |
| - "Latex: " |
107 |
| - + filename |
108 |
| - + " " |
109 |
| - + otherFolder.substring(otherFolder.lastIndexOf("/", otherFolder.length() - 1)) |
110 |
| - + " : " |
111 |
| - + condition); |
| 106 | + System.out.println( |
| 107 | + "Latex: " |
| 108 | + + filename |
| 109 | + + " " |
| 110 | + + otherFolder.substring(otherFolder.lastIndexOf("/", otherFolder.length() - 1)) |
| 111 | + + " : " |
| 112 | + + condition); |
112 | 113 |
|
113 |
| - Assert.assertTrue(condition); |
114 |
| - } |
| 114 | + Assert.assertTrue(condition); |
| 115 | + } |
115 | 116 | }
|
0 commit comments