From ed9b5cdfc648e86fd463bfa8d86b94c41671e14c Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 8 Feb 2015 21:29:25 -0500 Subject: switch all classes to new signature/type system --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 165 ++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 test/cuchaz/enigma/TestJarIndexLoneClass.java (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 0000000..c6a9e55 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.Collection; +import java.util.Set; +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.analysis.Access; +import cuchaz.enigma.analysis.ClassImplementationsTreeNode; +import cuchaz.enigma.analysis.ClassInheritanceTreeNode; +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.JarIndex; +import cuchaz.enigma.analysis.MethodImplementationsTreeNode; +import cuchaz.enigma.analysis.MethodInheritanceTreeNode; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.MethodEntry; +import cuchaz.enigma.mapping.Translator; + +public class TestJarIndexLoneClass { + + private JarIndex m_index; + + public TestJarIndexLoneClass() + throws Exception { + m_index = new JarIndex(); + m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + newClass("none/a") + )); + } + + @Test + public void translationIndex() { + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + } + + @Test + public void access() { + assertThat(m_index.getAccess(newField("none/a", "a")), is(Access.Private)); + assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); + assertThat(m_index.getAccess(newField("none/a", "b")), is(nullValue())); + } + + @Test + public void classInheritance() { + ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("none/a")); + assertThat(node, is(not(nullValue()))); + assertThat(node.getObfClassName(), is("none/a")); + assertThat(node.getChildCount(), is(0)); + } + + @Test + public void methodInheritance() { + MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); + MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); + assertThat(node, is(not(nullValue()))); + assertThat(node.getMethodEntry(), is(source)); + assertThat(node.getChildCount(), is(0)); + } + + @Test + public void classImplementations() { + ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("none/a")); + assertThat(node, is(nullValue())); + } + + @Test + public void methodImplementations() { + MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); + MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); + assertThat(node, is(nullValue())); + } + + @Test + public void relatedMethodImplementations() { + Set entries = m_index.getRelatedMethodImplementations(newMethod("none/a", "a", "()Ljava/lang/String;")); + assertThat(entries, containsInAnyOrder( + newMethod("none/a", "a", "()Ljava/lang/String;") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void fieldReferences() { + FieldEntry source = newField("none/a", "a"); + Collection> references = m_index.getFieldReferences(source); + assertThat(references, containsInAnyOrder( + newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), + newFieldReferenceByMethod(source, "none/a", "a", "()Ljava/lang/String;") + )); + } + + @Test + public void behaviorReferences() { + assertThat(m_index.getBehaviorReferences(newMethod("none/a", "a", "()Ljava/lang/String;")), is(empty())); + } + + @Test + public void innerClasses() { + assertThat(m_index.getInnerClasses("none/a"), is(empty())); + } + + @Test + public void outerClass() { + assertThat(m_index.getOuterClass("a"), is(nullValue())); + } + + @Test + public void isAnonymousClass() { + assertThat(m_index.isAnonymousClass("none/a"), is(false)); + } + + @Test + public void interfaces() { + assertThat(m_index.getInterfaces("none/a"), is(empty())); + } + + @Test + public void implementingClasses() { + assertThat(m_index.getImplementingClasses("none/a"), is(empty())); + } + + @Test + public void isInterface() { + assertThat(m_index.isInterface("none/a"), is(false)); + } + + @Test + public void contains() { + assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); + assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a")), is(true)); + assertThat(m_index.containsObfField(newField("none/a", "b")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); + } +} -- cgit v1.2.3 From 31a1a418b04cd3e7b06cb50cb8674a2c25079f6c Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 8 Feb 2015 23:10:26 -0500 Subject: added types to fields --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index c6a9e55..c0ac8d7 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -64,9 +64,10 @@ public class TestJarIndexLoneClass { @Test public void access() { - assertThat(m_index.getAccess(newField("none/a", "a")), is(Access.Private)); + assertThat(m_index.getAccess(newField("none/a", "a", "Ljava/lang/String;")), is(Access.Private)); assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); - assertThat(m_index.getAccess(newField("none/a", "b")), is(nullValue())); + assertThat(m_index.getAccess(newField("none/a", "b", "Ljava/lang/String;")), is(nullValue())); + assertThat(m_index.getAccess(newField("none/a", "a", "LFoo;")), is(nullValue())); } @Test @@ -110,7 +111,7 @@ public class TestJarIndexLoneClass { @Test @SuppressWarnings("unchecked") public void fieldReferences() { - FieldEntry source = newField("none/a", "a"); + FieldEntry source = newField("none/a", "a", "Ljava/lang/String;"); Collection> references = m_index.getFieldReferences(source); assertThat(references, containsInAnyOrder( newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), @@ -157,8 +158,9 @@ public class TestJarIndexLoneClass { public void contains() { assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); - assertThat(m_index.containsObfField(newField("none/a", "a")), is(true)); - assertThat(m_index.containsObfField(newField("none/a", "b")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfField(newField("none/a", "b", "Ljava/lang/String;")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a", "LFoo;")), is(false)); assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); } -- cgit v1.2.3 From af1041731c8c0ce1846ff7e7b6052ed7327a5dbc Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Feb 2015 22:23:45 -0500 Subject: fix translation issues, particularly with fields --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index c0ac8d7..768284f 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -11,7 +11,7 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; @@ -96,8 +96,7 @@ public class TestJarIndexLoneClass { @Test public void methodImplementations() { MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); - MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); - assertThat(node, is(nullValue())); + assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); } @Test -- cgit v1.2.3 From 2dc7428e37bdd7a119f53d02ce157675509b0d63 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 23 Feb 2015 23:29:22 -0500 Subject: lots of work in better handling of inner classes also working on recognizing unobfuscated and deobfuscated jars (needed for M3L) --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 768284f..0c126ad 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -26,7 +26,6 @@ import cuchaz.enigma.analysis.ClassImplementationsTreeNode; import cuchaz.enigma.analysis.ClassInheritanceTreeNode; import cuchaz.enigma.analysis.EntryReference; import cuchaz.enigma.analysis.JarIndex; -import cuchaz.enigma.analysis.MethodImplementationsTreeNode; import cuchaz.enigma.analysis.MethodInheritanceTreeNode; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; @@ -125,17 +124,17 @@ public class TestJarIndexLoneClass { @Test public void innerClasses() { - assertThat(m_index.getInnerClasses("none/a"), is(empty())); + assertThat(m_index.getInnerClasses(newClass("none/a")), is(empty())); } @Test public void outerClass() { - assertThat(m_index.getOuterClass("a"), is(nullValue())); + assertThat(m_index.getOuterClass(newClass("a")), is(nullValue())); } @Test public void isAnonymousClass() { - assertThat(m_index.isAnonymousClass("none/a"), is(false)); + assertThat(m_index.isAnonymousClass(newClass("none/a")), is(false)); } @Test -- cgit v1.2.3 From 51b92b780b57cc955e0618d09fbc3aa95ff47163 Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 19 Apr 2015 18:51:04 -0400 Subject: relicense Enigma as LGPL --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 0c126ad..2889241 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation -- cgit v1.2.3 From c7a3de184dc51526ee157d47981a74ffba284f5d Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 24 May 2015 11:23:36 -0400 Subject: fix broken tests, and one broken function. =) --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 2889241..c97b2ef 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -52,10 +52,10 @@ public class TestJarIndexLoneClass { @Test public void translationIndex() { - assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); - assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); - assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); - assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), contains(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); } @@ -152,7 +152,7 @@ public class TestJarIndexLoneClass { } @Test - public void contains() { + public void testContains() { assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); -- cgit v1.2.3