diff --git a/src/test/java/me/coley/cafedude/CrasherPatchingTest.java b/src/test/java/me/coley/cafedude/CrasherPatchingTest.java index 90f790b..2518b42 100644 --- a/src/test/java/me/coley/cafedude/CrasherPatchingTest.java +++ b/src/test/java/me/coley/cafedude/CrasherPatchingTest.java @@ -61,7 +61,7 @@ public void testPatch(File sub) { */ public static List supply() { List files = new ArrayList<>(); - File root = new File("src/test/resources/samples/crasher"); + File root = new File("src/test/resources/samples/obfuscated/crasher"); for (File sub : Objects.requireNonNull(root.listFiles())) { if (sub.getName().endsWith(".class")) files.add(sub); diff --git a/src/test/java/me/coley/cafedude/EqualityIOTest.java b/src/test/java/me/coley/cafedude/EqualityIOTest.java index 1805dcb..bd0d111 100644 --- a/src/test/java/me/coley/cafedude/EqualityIOTest.java +++ b/src/test/java/me/coley/cafedude/EqualityIOTest.java @@ -3,12 +3,18 @@ import me.coley.cafedude.classfile.ClassFile; import me.coley.cafedude.io.ClassFileReader; import me.coley.cafedude.io.ClassFileWriter; -import org.junit.jupiter.api.Test; +import me.coley.cafedude.transform.IllegalStrippingTransformer; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.Objects; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -16,47 +22,34 @@ * Test that asserts the classes that are read and written back to are identical. */ public class EqualityIOTest { - private File lastLoaded; - private int successes; - - @Test - public void testSamples() { + @ParameterizedTest + @MethodSource("supply") + public void testEquality(Path sub) { try { - visitRootDir("samples/annos"); - visitRootDir("samples/modules"); - visitRootDir("samples/javac"); - visitRootDir("samples/misc"); + byte[] code = Files.readAllBytes(sub); + ClassFile cf = new ClassFileReader().read(code); + new IllegalStrippingTransformer(cf).transform(); + byte[] out = new ClassFileWriter().write(cf); + assertEquals(code.length, out.length, "Class difference for: " + cf.getName()); + assertArrayEquals(code, out); } catch (IOException e) { - System.err.println(lastLoaded.getPath()); fail("Failed to read class, IO error", e); } catch (InvalidClassException e) { - System.err.println(lastLoaded.getPath()); fail("Failed to read class, invalid class", e); } - System.out.println("Successes: " + successes); - } - - private void assertReadWriteEquality(byte[] code) throws InvalidClassException { - ClassFile cf = new ClassFileReader().read(code); - byte[] out = new ClassFileWriter().write(cf); - assertEquals(code.length, out.length, "Class difference for: " + cf.getName()); - assertArrayEquals(code, out); } - private void visitRootDir(String dir) throws IOException, InvalidClassException { - File root = new File("src/test/resources/" + dir); - visit(root); - } - - private void visit(File file) throws IOException, InvalidClassException { - if (file.isDirectory()) { - for (File sub : Objects.requireNonNull(file.listFiles())) - visit(sub); - } else if (file.getName().endsWith(".class")) { - lastLoaded = file; - byte[] code = Files.readAllBytes(file.toPath()); - assertReadWriteEquality(code); - successes++; + /** + * @return Test files to check. + */ + public static List supply() { + try { + BiPredicate filter = + (path, attrib) -> attrib.isRegularFile() && path.toString().endsWith(".class"); + return Files.find(Paths.get("src/test/resources/samples/normal"), 25, filter) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/src/test/resources/samples/annos/Anno.class b/src/test/resources/samples/normal/annos/Anno.class similarity index 100% rename from src/test/resources/samples/annos/Anno.class rename to src/test/resources/samples/normal/annos/Anno.class diff --git a/src/test/resources/samples/annos/Anno.java b/src/test/resources/samples/normal/annos/Anno.java similarity index 100% rename from src/test/resources/samples/annos/Anno.java rename to src/test/resources/samples/normal/annos/Anno.java diff --git a/src/test/resources/samples/normal/annos/CommandLine$Command.class b/src/test/resources/samples/normal/annos/CommandLine$Command.class new file mode 100644 index 0000000..c135ca1 Binary files /dev/null and b/src/test/resources/samples/normal/annos/CommandLine$Command.class differ diff --git a/src/test/resources/samples/annos/Sample.class b/src/test/resources/samples/normal/annos/Sample.class similarity index 100% rename from src/test/resources/samples/annos/Sample.class rename to src/test/resources/samples/normal/annos/Sample.class diff --git a/src/test/resources/samples/annos/Sample.java b/src/test/resources/samples/normal/annos/Sample.java similarity index 100% rename from src/test/resources/samples/annos/Sample.java rename to src/test/resources/samples/normal/annos/Sample.java diff --git a/src/test/resources/samples/javac/Conf.class b/src/test/resources/samples/normal/javac/Conf.class similarity index 100% rename from src/test/resources/samples/javac/Conf.class rename to src/test/resources/samples/normal/javac/Conf.class diff --git a/src/test/resources/samples/javac/ConfDisplay.class b/src/test/resources/samples/normal/javac/ConfDisplay.class similarity index 100% rename from src/test/resources/samples/javac/ConfDisplay.class rename to src/test/resources/samples/normal/javac/ConfDisplay.class diff --git a/src/test/resources/samples/javac/InstrumentationResource$1.class b/src/test/resources/samples/normal/javac/InstrumentationResource$1.class similarity index 100% rename from src/test/resources/samples/javac/InstrumentationResource$1.class rename to src/test/resources/samples/normal/javac/InstrumentationResource$1.class diff --git a/src/test/resources/samples/javac/InstrumentationResource$InstrumentationResourceTransformer.class b/src/test/resources/samples/normal/javac/InstrumentationResource$InstrumentationResourceTransformer.class similarity index 100% rename from src/test/resources/samples/javac/InstrumentationResource$InstrumentationResourceTransformer.class rename to src/test/resources/samples/normal/javac/InstrumentationResource$InstrumentationResourceTransformer.class diff --git a/src/test/resources/samples/javac/InstrumentationResource.class b/src/test/resources/samples/normal/javac/InstrumentationResource.class similarity index 100% rename from src/test/resources/samples/javac/InstrumentationResource.class rename to src/test/resources/samples/normal/javac/InstrumentationResource.class diff --git a/src/test/resources/samples/javac/Vector.class b/src/test/resources/samples/normal/javac/Vector.class similarity index 100% rename from src/test/resources/samples/javac/Vector.class rename to src/test/resources/samples/normal/javac/Vector.class diff --git a/src/test/resources/samples/javac/Workspace.class b/src/test/resources/samples/normal/javac/Workspace.class similarity index 100% rename from src/test/resources/samples/javac/Workspace.class rename to src/test/resources/samples/normal/javac/Workspace.class diff --git a/src/test/resources/samples/javac/WorkspaceIO$1.class b/src/test/resources/samples/normal/javac/WorkspaceIO$1.class similarity index 100% rename from src/test/resources/samples/javac/WorkspaceIO$1.class rename to src/test/resources/samples/normal/javac/WorkspaceIO$1.class diff --git a/src/test/resources/samples/javac/WorkspaceIO.class b/src/test/resources/samples/normal/javac/WorkspaceIO.class similarity index 100% rename from src/test/resources/samples/javac/WorkspaceIO.class rename to src/test/resources/samples/normal/javac/WorkspaceIO.class diff --git a/src/test/resources/samples/misc/FileAlterationMonitor.class b/src/test/resources/samples/normal/misc/FileAlterationMonitor.class similarity index 100% rename from src/test/resources/samples/misc/FileAlterationMonitor.class rename to src/test/resources/samples/normal/misc/FileAlterationMonitor.class diff --git a/src/test/resources/samples/misc/IndyTest.class b/src/test/resources/samples/normal/misc/IndyTest.class similarity index 100% rename from src/test/resources/samples/misc/IndyTest.class rename to src/test/resources/samples/normal/misc/IndyTest.class diff --git a/src/test/resources/samples/modules/module-info-javafx-controls.class b/src/test/resources/samples/normal/modules/module-info-javafx-controls.class similarity index 100% rename from src/test/resources/samples/modules/module-info-javafx-controls.class rename to src/test/resources/samples/normal/modules/module-info-javafx-controls.class diff --git a/src/test/resources/samples/crasher/sample1.class b/src/test/resources/samples/obfuscated/crasher/sample1.class similarity index 100% rename from src/test/resources/samples/crasher/sample1.class rename to src/test/resources/samples/obfuscated/crasher/sample1.class diff --git a/src/test/resources/samples/crasher/sample10.class b/src/test/resources/samples/obfuscated/crasher/sample10.class similarity index 100% rename from src/test/resources/samples/crasher/sample10.class rename to src/test/resources/samples/obfuscated/crasher/sample10.class diff --git a/src/test/resources/samples/crasher/sample11.class b/src/test/resources/samples/obfuscated/crasher/sample11.class similarity index 100% rename from src/test/resources/samples/crasher/sample11.class rename to src/test/resources/samples/obfuscated/crasher/sample11.class diff --git a/src/test/resources/samples/crasher/sample12.class b/src/test/resources/samples/obfuscated/crasher/sample12.class similarity index 100% rename from src/test/resources/samples/crasher/sample12.class rename to src/test/resources/samples/obfuscated/crasher/sample12.class diff --git a/src/test/resources/samples/crasher/sample13.class b/src/test/resources/samples/obfuscated/crasher/sample13.class similarity index 100% rename from src/test/resources/samples/crasher/sample13.class rename to src/test/resources/samples/obfuscated/crasher/sample13.class diff --git a/src/test/resources/samples/crasher/sample14.class b/src/test/resources/samples/obfuscated/crasher/sample14.class similarity index 100% rename from src/test/resources/samples/crasher/sample14.class rename to src/test/resources/samples/obfuscated/crasher/sample14.class diff --git a/src/test/resources/samples/crasher/sample15.class b/src/test/resources/samples/obfuscated/crasher/sample15.class similarity index 100% rename from src/test/resources/samples/crasher/sample15.class rename to src/test/resources/samples/obfuscated/crasher/sample15.class diff --git a/src/test/resources/samples/crasher/Sample16.class b/src/test/resources/samples/obfuscated/crasher/sample16.class similarity index 100% rename from src/test/resources/samples/crasher/Sample16.class rename to src/test/resources/samples/obfuscated/crasher/sample16.class diff --git a/src/test/resources/samples/crasher/Sample17.class b/src/test/resources/samples/obfuscated/crasher/sample17.class similarity index 100% rename from src/test/resources/samples/crasher/Sample17.class rename to src/test/resources/samples/obfuscated/crasher/sample17.class diff --git a/src/test/resources/samples/crasher/Sample18.class b/src/test/resources/samples/obfuscated/crasher/sample18.class similarity index 100% rename from src/test/resources/samples/crasher/Sample18.class rename to src/test/resources/samples/obfuscated/crasher/sample18.class diff --git a/src/test/resources/samples/crasher/Sample19.class b/src/test/resources/samples/obfuscated/crasher/sample19.class similarity index 100% rename from src/test/resources/samples/crasher/Sample19.class rename to src/test/resources/samples/obfuscated/crasher/sample19.class diff --git a/src/test/resources/samples/crasher/sample2.class b/src/test/resources/samples/obfuscated/crasher/sample2.class similarity index 100% rename from src/test/resources/samples/crasher/sample2.class rename to src/test/resources/samples/obfuscated/crasher/sample2.class diff --git a/src/test/resources/samples/crasher/Sample20.class b/src/test/resources/samples/obfuscated/crasher/sample20.class similarity index 100% rename from src/test/resources/samples/crasher/Sample20.class rename to src/test/resources/samples/obfuscated/crasher/sample20.class diff --git a/src/test/resources/samples/crasher/sample21.class b/src/test/resources/samples/obfuscated/crasher/sample21.class similarity index 100% rename from src/test/resources/samples/crasher/sample21.class rename to src/test/resources/samples/obfuscated/crasher/sample21.class diff --git a/src/test/resources/samples/crasher/sample22.class b/src/test/resources/samples/obfuscated/crasher/sample22.class similarity index 100% rename from src/test/resources/samples/crasher/sample22.class rename to src/test/resources/samples/obfuscated/crasher/sample22.class diff --git a/src/test/resources/samples/crasher/sample23.class b/src/test/resources/samples/obfuscated/crasher/sample23.class similarity index 100% rename from src/test/resources/samples/crasher/sample23.class rename to src/test/resources/samples/obfuscated/crasher/sample23.class diff --git a/src/test/resources/samples/crasher/sample24.class b/src/test/resources/samples/obfuscated/crasher/sample24.class similarity index 100% rename from src/test/resources/samples/crasher/sample24.class rename to src/test/resources/samples/obfuscated/crasher/sample24.class diff --git a/src/test/resources/samples/crasher/sample25.class b/src/test/resources/samples/obfuscated/crasher/sample25.class similarity index 100% rename from src/test/resources/samples/crasher/sample25.class rename to src/test/resources/samples/obfuscated/crasher/sample25.class diff --git a/src/test/resources/samples/crasher/sample26.class b/src/test/resources/samples/obfuscated/crasher/sample26.class similarity index 100% rename from src/test/resources/samples/crasher/sample26.class rename to src/test/resources/samples/obfuscated/crasher/sample26.class diff --git a/src/test/resources/samples/crasher/sample27.class b/src/test/resources/samples/obfuscated/crasher/sample27.class similarity index 100% rename from src/test/resources/samples/crasher/sample27.class rename to src/test/resources/samples/obfuscated/crasher/sample27.class diff --git a/src/test/resources/samples/crasher/sample28.class b/src/test/resources/samples/obfuscated/crasher/sample28.class similarity index 100% rename from src/test/resources/samples/crasher/sample28.class rename to src/test/resources/samples/obfuscated/crasher/sample28.class diff --git a/src/test/resources/samples/crasher/sample29.class b/src/test/resources/samples/obfuscated/crasher/sample29.class similarity index 100% rename from src/test/resources/samples/crasher/sample29.class rename to src/test/resources/samples/obfuscated/crasher/sample29.class diff --git a/src/test/resources/samples/crasher/sample3.class b/src/test/resources/samples/obfuscated/crasher/sample3.class similarity index 100% rename from src/test/resources/samples/crasher/sample3.class rename to src/test/resources/samples/obfuscated/crasher/sample3.class diff --git a/src/test/resources/samples/crasher/sample4.class b/src/test/resources/samples/obfuscated/crasher/sample4.class similarity index 100% rename from src/test/resources/samples/crasher/sample4.class rename to src/test/resources/samples/obfuscated/crasher/sample4.class diff --git a/src/test/resources/samples/crasher/sample5.class b/src/test/resources/samples/obfuscated/crasher/sample5.class similarity index 100% rename from src/test/resources/samples/crasher/sample5.class rename to src/test/resources/samples/obfuscated/crasher/sample5.class diff --git a/src/test/resources/samples/crasher/sample6.class b/src/test/resources/samples/obfuscated/crasher/sample6.class similarity index 100% rename from src/test/resources/samples/crasher/sample6.class rename to src/test/resources/samples/obfuscated/crasher/sample6.class diff --git a/src/test/resources/samples/crasher/sample7.class b/src/test/resources/samples/obfuscated/crasher/sample7.class similarity index 100% rename from src/test/resources/samples/crasher/sample7.class rename to src/test/resources/samples/obfuscated/crasher/sample7.class diff --git a/src/test/resources/samples/crasher/sample8.class b/src/test/resources/samples/obfuscated/crasher/sample8.class similarity index 100% rename from src/test/resources/samples/crasher/sample8.class rename to src/test/resources/samples/obfuscated/crasher/sample8.class diff --git a/src/test/resources/samples/crasher/sample9.class b/src/test/resources/samples/obfuscated/crasher/sample9.class similarity index 100% rename from src/test/resources/samples/crasher/sample9.class rename to src/test/resources/samples/obfuscated/crasher/sample9.class