|
| 1 | +package cuchaz.enigma.command; |
| 2 | + |
| 3 | +import cuchaz.enigma.ProgressListener; |
| 4 | +import cuchaz.enigma.translation.mapping.EntryMapping; |
| 5 | +import cuchaz.enigma.translation.mapping.serde.MappingFileNameFormat; |
| 6 | +import cuchaz.enigma.translation.mapping.serde.MappingFormat; |
| 7 | +import cuchaz.enigma.translation.mapping.serde.MappingSaveParameters; |
| 8 | +import cuchaz.enigma.translation.mapping.tree.EntryTree; |
| 9 | +import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 10 | +import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | + |
| 13 | +import java.nio.file.Files; |
| 14 | +import java.nio.file.Path; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 19 | + |
| 20 | +public class MapSpecializedMethodsCommandTest extends CommandTest { |
| 21 | + private static final Path JAR = obfJar("bridge"); |
| 22 | + private static final Path MAPPINGS = getResource("/mapSpecializedMethods/"); |
| 23 | + |
| 24 | + private static final ClassEntry BASE_CLASS = new ClassEntry("a"); |
| 25 | + private static final MethodEntry BASE_FOO_1 = MethodEntry.parse("a", "d", "()La;"); |
| 26 | + private static final MethodEntry BASE_FOO_2 = MethodEntry.parse("a", "a", "(I)La;"); |
| 27 | + private static final MethodEntry BASE_FOO_3 = MethodEntry.parse("a", "a", "(II)La;"); |
| 28 | + private static final MethodEntry BASE_BAR_1 = MethodEntry.parse("a", "e", "()La;"); |
| 29 | + private static final MethodEntry BASE_BAR_2 = MethodEntry.parse("a", "b", "(I)La;"); |
| 30 | + private static final MethodEntry BASE_BAZ_1 = MethodEntry.parse("a", "c", "(I)La;"); |
| 31 | + private static final MethodEntry BASE_BAZ_2 = MethodEntry.parse("a", "b", "(II)La;"); |
| 32 | + private static final ClassEntry OTHER_CLASS = new ClassEntry("b"); |
| 33 | + private static final MethodEntry OTHER_GET = MethodEntry.parse("b", "a", "()Ljava/lang/Integer;"); |
| 34 | + private static final MethodEntry OTHER_GET_BRIDGE = MethodEntry.parse("b", "get", "()Ljava/lang/Object;"); |
| 35 | + private static final MethodEntry OTHER_APPLY = MethodEntry.parse("b", "a", "(Ljava/lang/String;)Ljava/lang/Integer;"); |
| 36 | + private static final MethodEntry OTHER_APPLY_BRIDGE = MethodEntry.parse("b", "apply", "(Ljava/lang/Object;)Ljava/lang/Object;"); |
| 37 | + private static final ClassEntry SUB_CLASS = new ClassEntry("c"); |
| 38 | + private static final MethodEntry SUB_FOO_1 = MethodEntry.parse("c", "f", "()Lc;"); |
| 39 | + private static final MethodEntry SUB_FOO_1_BRIDGE = MethodEntry.parse("c", "d", "()La;"); |
| 40 | + private static final MethodEntry SUB_FOO_2 = MethodEntry.parse("c", "d", "(I)Lc;"); |
| 41 | + private static final MethodEntry SUB_FOO_2_BRIDGE = MethodEntry.parse("c", "a", "(I)La;"); |
| 42 | + private static final MethodEntry SUB_FOO_3 = MethodEntry.parse("c", "c", "(II)Lc;"); |
| 43 | + private static final MethodEntry SUB_FOO_3_BRIDGE = MethodEntry.parse("c", "a", "(II)La;"); |
| 44 | + private static final MethodEntry SUB_BAR_1 = MethodEntry.parse("c", "g", "()Lc;"); |
| 45 | + private static final MethodEntry SUB_BAR_1_BRIDGE = MethodEntry.parse("c", "e", "()La;"); |
| 46 | + private static final MethodEntry SUB_BAR_2 = MethodEntry.parse("c", "e", "(I)Lc;"); |
| 47 | + private static final MethodEntry SUB_BAR_2_BRIDGE = MethodEntry.parse("c", "b", "(I)La;"); |
| 48 | + private static final MethodEntry SUB_BAZ_1 = MethodEntry.parse("c", "f", "(I)Lc;"); |
| 49 | + private static final MethodEntry SUB_BAZ_1_BRIDGE = MethodEntry.parse("c", "c", "(I)La;"); |
| 50 | + private static final MethodEntry SUB_BAZ_2 = MethodEntry.parse("c", "d", "(II)Lc;"); |
| 51 | + private static final MethodEntry SUB_BAZ_2_BRIDGE = MethodEntry.parse("c", "b", "(II)La;"); |
| 52 | + private static final ClassEntry INNER_SUB_CLASS = new ClassEntry("c$a"); |
| 53 | + private static final MethodEntry INNER_SUB_FOO_1_BRIDGE = MethodEntry.parse("c$a", "d", "()La;"); |
| 54 | + private static final MethodEntry INNER_SUB_FOO_2_BRIDGE = MethodEntry.parse("c$a", "a", "(I)La;"); |
| 55 | + private static final MethodEntry INNER_SUB_FOO_3_BRIDGE = MethodEntry.parse("c$a", "a", "(II)La;"); |
| 56 | + private static final MethodEntry INNER_SUB_BAR_1_BRIDGE = MethodEntry.parse("c$a", "e", "()La;"); |
| 57 | + private static final MethodEntry INNER_SUB_BAR_2_BRIDGE = MethodEntry.parse("c$a", "b", "(I)La;"); |
| 58 | + private static final MethodEntry INNER_SUB_BAZ_1_BRIDGE = MethodEntry.parse("c$a", "c", "(I)La;"); |
| 59 | + private static final MethodEntry INNER_SUB_BAZ_2_BRIDGE = MethodEntry.parse("c$a", "b", "(II)La;"); |
| 60 | + |
| 61 | + @Test |
| 62 | + public void test() throws Exception { |
| 63 | + Path resultFile = Files.createTempFile("mapSpecializedMethods", ".mappings"); |
| 64 | + MapSpecializedMethodsCommand.run(JAR, MappingFormat.ENIGMA_DIRECTORY.name(), MAPPINGS, MappingFormat.ENIGMA_FILE.name(), resultFile); |
| 65 | + |
| 66 | + EntryTree<EntryMapping> result = MappingFormat.ENIGMA_FILE.read(resultFile, ProgressListener.none(), new MappingSaveParameters(MappingFileNameFormat.BY_DEOBF)); |
| 67 | + |
| 68 | + assertNotNull(result.findNode(BASE_CLASS)); |
| 69 | + assertEquals("foo", getName(result, BASE_FOO_1)); |
| 70 | + assertEquals("foo", getName(result, BASE_FOO_2)); |
| 71 | + assertEquals("foo", getName(result, BASE_FOO_3)); |
| 72 | + assertEquals("bar", getName(result, BASE_BAR_1)); |
| 73 | + assertEquals("bar", getName(result, BASE_BAR_2)); |
| 74 | + assertEquals("baz", getName(result, BASE_BAZ_1)); |
| 75 | + assertEquals("baz", getName(result, BASE_BAZ_2)); |
| 76 | + |
| 77 | + assertNotNull(result.findNode(OTHER_CLASS)); |
| 78 | + assertEquals("get", getName(result, OTHER_GET)); |
| 79 | + assertNull(getName(result, OTHER_GET_BRIDGE)); |
| 80 | + assertEquals("apply", getName(result, OTHER_APPLY)); |
| 81 | + assertNull(getName(result, OTHER_APPLY_BRIDGE)); |
| 82 | + |
| 83 | + assertNotNull(result.findNode(SUB_CLASS)); |
| 84 | + assertEquals("foo", getName(result, SUB_FOO_1)); |
| 85 | + assertNull(getName(result, SUB_FOO_1_BRIDGE)); |
| 86 | + assertEquals("foo", getName(result, SUB_FOO_2)); |
| 87 | + assertNull(getName(result, SUB_FOO_2_BRIDGE)); |
| 88 | + assertEquals("foo", getName(result, SUB_FOO_3)); |
| 89 | + assertNull(getName(result, SUB_FOO_3_BRIDGE)); |
| 90 | + assertEquals("bar", getName(result, SUB_BAR_1)); |
| 91 | + assertNull(getName(result, SUB_BAR_1_BRIDGE)); |
| 92 | + assertEquals("bar", getName(result, SUB_BAR_2)); |
| 93 | + assertNull(getName(result, SUB_BAR_2_BRIDGE)); |
| 94 | + assertEquals("baz", getName(result, SUB_BAZ_1)); |
| 95 | + assertNull(getName(result, SUB_BAZ_1_BRIDGE)); |
| 96 | + assertEquals("baz", getName(result, SUB_BAZ_2)); |
| 97 | + assertNull(getName(result, SUB_BAZ_2_BRIDGE)); |
| 98 | + |
| 99 | + assertNull(getName(result, INNER_SUB_FOO_1_BRIDGE)); |
| 100 | + assertNull(getName(result, INNER_SUB_FOO_2_BRIDGE)); |
| 101 | + assertNull(getName(result, INNER_SUB_FOO_3_BRIDGE)); |
| 102 | + assertNull(getName(result, INNER_SUB_BAR_1_BRIDGE)); |
| 103 | + assertNull(getName(result, INNER_SUB_BAR_2_BRIDGE)); |
| 104 | + assertNull(getName(result, INNER_SUB_BAZ_1_BRIDGE)); |
| 105 | + assertNull(getName(result, INNER_SUB_BAZ_2_BRIDGE)); |
| 106 | + } |
| 107 | +} |
0 commit comments