From 5e3743a0aca3529eacf9be400c8b8d7547f66e7f Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 16 Mar 2015 19:22:22 -0400 Subject: started adding minimal support for generics fixed mark-as-deobfuscated issue --- test/cuchaz/enigma/TestSourceIndex.java | 2 +- test/cuchaz/enigma/TestTranslator.java | 17 ++- test/cuchaz/enigma/TestType.java | 163 +++++++++++++++++++++- test/cuchaz/enigma/resources/translation.mappings | 11 +- 4 files changed, 184 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 1397124..94bf941 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -24,7 +24,7 @@ import cuchaz.enigma.mapping.ClassEntry; public class TestSourceIndex { - // TEMP @Test + @Test public void indexEverything() throws Exception { diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 45c69bb..1b61740 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -125,7 +125,22 @@ public class TestTranslator { @Test public void testGenerics() { - // TODO + + // classes + assertMapping(newClass("none/i"), newClass("deobf/I_Generics")); + assertMapping(newClass("none/i$a"), newClass("deobf/I_Generics$A_Type")); + assertMapping(newClass("none/i$b"), newClass("deobf/I_Generics$B_Generic")); + + // fields + assertMapping(newField("none/i", "a", "Ljava/util/List;"), newField("deobf/I_Generics", "f1", "Ljava/util/List;")); + assertMapping(newField("none/i", "b", "Ljava/util/List;"), newField("deobf/I_Generics", "f2", "Ljava/util/List;")); + assertMapping(newField("none/i", "a", "Ljava/util/Map;"), newField("deobf/I_Generics", "f3", "Ljava/util/Map;")); + assertMapping(newField("none/i$b", "a", "Ljava/lang/Object;"), newField("deobf/I_Generics$B_Generic", "f4", "Ljava/lang/Object;")); + assertMapping(newField("none/i", "a", "Lnone/i$b;"), newField("deobf/I_Generics", "f5", "Ldeobf/I_Generics$B_Generic;")); + assertMapping(newField("none/i", "b", "Lnone/i$b;"), newField("deobf/I_Generics", "f6", "Ldeobf/I_Generics$B_Generic;")); + + // methods + assertMapping(newMethod("none/i$b", "a", "()Ljava/lang/Object;"), newMethod("deobf/I_Generics$B_Generic", "m1", "()Ljava/lang/Object;")); } private void assertMapping(Entry obf, Entry deobf) { diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 93f864b..544a10c 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java @@ -1,13 +1,13 @@ package cuchaz.enigma; -import org.junit.Test; - +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import cuchaz.enigma.mapping.Type; +import org.junit.Test; -import static cuchaz.enigma.TestEntryFactory.*; +import cuchaz.enigma.mapping.ParameterizedType; +import cuchaz.enigma.mapping.Type; public class TestType { @@ -24,6 +24,7 @@ public class TestType { assertThat(new Type("D").isVoid(), is(false)); assertThat(new Type("LFoo;").isVoid(), is(false)); assertThat(new Type("[I").isVoid(), is(false)); + assertThat(new Type("TFoo;").isVoid(), is(false)); } @Test @@ -38,6 +39,7 @@ public class TestType { assertThat(new Type("D").isPrimitive(), is(true)); assertThat(new Type("LFoo;").isPrimitive(), is(false)); assertThat(new Type("[I").isPrimitive(), is(false)); + assertThat(new Type("TFoo;").isPrimitive(), is(false)); } @Test @@ -62,13 +64,20 @@ public class TestType { assertThat(new Type("F").isClass(), is(false)); assertThat(new Type("D").isClass(), is(false)); assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;>;").isClass(), is(true)); assertThat(new Type("[I").isClass(), is(false)); + assertThat(new Type("TFoo;").isClass(), is(false)); } @Test public void getClassEntry() { assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;>;").getClassEntry(), is(newClass("Foo"))); } @Test @@ -89,6 +98,7 @@ public class TestType { assertThat(new Type("D").isArray(), is(false)); assertThat(new Type("LFoo;").isArray(), is(false)); assertThat(new Type("[I").isArray(), is(true)); + assertThat(new Type("TFoo;").isArray(), is(false)); } @Test @@ -106,6 +116,30 @@ public class TestType { assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); } + @Test + public void isTemplate() { + assertThat(new Type("V").isTemplate(), is(false)); + assertThat(new Type("Z").isTemplate(), is(false)); + assertThat(new Type("B").isTemplate(), is(false)); + assertThat(new Type("C").isTemplate(), is(false)); + assertThat(new Type("I").isTemplate(), is(false)); + assertThat(new Type("J").isTemplate(), is(false)); + assertThat(new Type("F").isTemplate(), is(false)); + assertThat(new Type("D").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;>;").isTemplate(), is(false)); + assertThat(new Type("[I").isTemplate(), is(false)); + assertThat(new Type("TFoo;").isTemplate(), is(true)); + } + + @Test + public void getTemplate() { + assertThat(new Type("TT;").getTemplate(), is("T")); + assertThat(new Type("TFoo;").getTemplate(), is("Foo")); + } + @Test public void hasClass() { assertThat(new Type("LFoo;").hasClass(), is(true)); @@ -117,6 +151,37 @@ public class TestType { assertThat(new Type("[I").hasClass(), is(false)); assertThat(new Type("[[[I").hasClass(), is(false)); assertThat(new Type("Z").hasClass(), is(false)); + assertThat(new Type("TFoo;").hasClass(), is(false)); + } + + @Test + public void parameters() { + assertThat(new Type("LFoo;").parameters(), contains( + new Type("I") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("I"), + new Type("I"), + new Type("I"), + new Type("I") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("LBar;") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("LBar;"), + new Type("LCow;"), + new Type("LCheese;") + )); + + assertThat(new Type("LFoo;>;").parameters(), contains( + new Type("LBar;") + )); + + assertThat(new Type("LFoo;>;").parameters().iterator().next().parameters(), contains( + new Type("LCow;"), + new Type("LCheese;") + )); } @Test @@ -171,7 +236,18 @@ public class TestType { assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); } } - + + @Test + public void parseTemplate() { + final String answer = "TFoo;"; + assertThat(Type.parseFirst("TFoo;"), is(answer)); + assertThat(Type.parseFirst("TFoo;I"), is(answer)); + assertThat(Type.parseFirst("TFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("TFoo;[I"), is(answer)); + assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer)); + assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer)); + } + @Test public void parseArray() { { @@ -215,15 +291,90 @@ public class TestType { assertThat(new Type("[[[I"), is(new Type("[[[I"))); assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + assertThat(new Type("TFoo;"), is(new Type("TFoo;"))); assertThat(new Type("V"), is(not(new Type("I")))); assertThat(new Type("I"), is(not(new Type("J")))); assertThat(new Type("I"), is(not(new Type("LBar;")))); assertThat(new Type("I"), is(not(new Type("[I")))); assertThat(new Type("LFoo;"), is(not(new Type("LBar;")))); - assertThat(new Type("LFoo;"), is(not(new Type("LFoo;")))); assertThat(new Type("[I"), is(not(new Type("[Z")))); assertThat(new Type("[[[I"), is(not(new Type("[I")))); assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); + assertThat(new Type("TFoo;"), is(not(new Type("TBar;")))); + } + + @Test + public void testToString() { + assertThat(new Type("V").toString(), is("V")); + assertThat(new Type("Z").toString(), is("Z")); + assertThat(new Type("B").toString(), is("B")); + assertThat(new Type("C").toString(), is("C")); + assertThat(new Type("I").toString(), is("I")); + assertThat(new Type("J").toString(), is("J")); + assertThat(new Type("F").toString(), is("F")); + assertThat(new Type("D").toString(), is("D")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("[I").toString(), is("[I")); + assertThat(new Type("[[[I").toString(), is("[[[I")); + assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("LFoo;>;").toString(), is("LFoo;")); + assertThat(new Type("TFoo;").toString(), is("TFoo;")); + } + + private ParameterizedType ptype(String name) { + return new ParameterizedType(new Type(name)); + } + + @Test + public void equalsWithParameters() { + assertThat(ptype("V"), is(ptype("V"))); + assertThat(ptype("Z"), is(ptype("Z"))); + assertThat(ptype("B"), is(ptype("B"))); + assertThat(ptype("C"), is(ptype("C"))); + assertThat(ptype("I"), is(ptype("I"))); + assertThat(ptype("J"), is(ptype("J"))); + assertThat(ptype("F"), is(ptype("F"))); + assertThat(ptype("D"), is(ptype("D"))); + assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); + assertThat(ptype("[I"), is(ptype("[I"))); + assertThat(ptype("[[[I"), is(ptype("[[[I"))); + assertThat(ptype("[LFoo;"), is(ptype("[LFoo;"))); + assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); + assertThat(ptype("TFoo;"), is(ptype("TFoo;"))); + + assertThat(ptype("V"), is(not(ptype("I")))); + assertThat(ptype("I"), is(not(ptype("J")))); + assertThat(ptype("I"), is(not(ptype("LBar;")))); + assertThat(ptype("I"), is(not(ptype("[I")))); + assertThat(ptype("LFoo;"), is(not(ptype("LBar;")))); + assertThat(ptype("[I"), is(not(ptype("[Z")))); + assertThat(ptype("[[[I"), is(not(ptype("[I")))); + assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;")))); + assertThat(ptype("LFoo;"), is(not(ptype("LFoo;")))); + assertThat(ptype("TFoo;"), is(not(ptype("TBar;")))); + } + + @Test + public void testToStringWithParams() { + assertThat(ptype("V").toString(), is("V")); + assertThat(ptype("Z").toString(), is("Z")); + assertThat(ptype("B").toString(), is("B")); + assertThat(ptype("C").toString(), is("C")); + assertThat(ptype("I").toString(), is("I")); + assertThat(ptype("J").toString(), is("J")); + assertThat(ptype("F").toString(), is("F")); + assertThat(ptype("D").toString(), is("D")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("[I").toString(), is("[I")); + assertThat(ptype("[[[I").toString(), is("[[[I")); + assertThat(ptype("[LFoo;").toString(), is("[LFoo;")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("LFoo;>;").toString(), is("LFoo;>;")); + assertThat(ptype("TFoo;").toString(), is("TFoo;")); } } diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index 55bd7e5..db78c19 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -29,4 +29,13 @@ CLASS none/g deobf/G_OuterClass CLASS none/g$b$a A_NamedInnerClass FIELD a f4 I CLASS none/h -CLASS none/i I_Generics +CLASS none/i deobf/I_Generics + CLASS none/i$a A_Type + CLASS none/i$b B_Generic + FIELD a f4 Ljava/lang/Object; + METHOD a m1 ()Ljava/lang/Object; + FIELD a f1 Ljava/util/List; + FIELD b f2 Ljava/util/List; + FIELD a f3 Ljava/util/Map; + FIELD a f5 Lnone/i$b; + FIELD b f6 Lnone/i$b; -- cgit v1.2.3