From 730238f3bab1c680424e0ac74178c33b15b43eb5 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 7 Sep 2014 22:30:28 -0400 Subject: added some basic tests for the deobufscator and the jar index --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 201 ++++++++++++++++++++++++++ 1 file changed, 201 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..56031dd --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * 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.newClass; +import static cuchaz.enigma.EntryFactory.newField; +import static cuchaz.enigma.EntryFactory.newFieldReferenceByConstructor; +import static cuchaz.enigma.EntryFactory.newFieldReferenceByMethod; +import static cuchaz.enigma.EntryFactory.newMethod; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; + +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.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/libs/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().getSuperclassName( "none/a" ), is( nullValue() ) ); + assertThat( m_index.getTranslationIndex().getSuperclassName( "cuchaz/enigma/inputs/Keep" ), is( nullValue() ) ); + assertThat( m_index.getTranslationIndex().getAncestry( "none/a" ), is( empty() ) ); + assertThat( m_index.getTranslationIndex().getAncestry( "cuchaz/enigma/inputs/Keep" ), is( empty() ) ); + assertThat( m_index.getTranslationIndex().getSubclassNames( "none/a" ), is( empty() ) ); + assertThat( m_index.getTranslationIndex().getSubclassNames( "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 isImplemented( ) + { + assertThat( m_index.isMethodImplemented( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) ); + assertThat( m_index.isMethodImplemented( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), is( false ) ); + } + + @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( ) + { + Collection> references = m_index.getFieldReferences( newField( "none/a", "a" ) ); + assertThat( references, containsInAnyOrder( + newFieldReferenceByConstructor( "none/a", "a", "none/a", "(Ljava/lang/String;)V" ), + newFieldReferenceByMethod( "none/a", "a", "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( "none/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 bridgeMethods( ) + { + assertThat( m_index.getBridgeMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( nullValue() ) ); + } + + @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.containsObfMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) ); + assertThat( m_index.containsObfMethod( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), is( false ) ); + } +} -- cgit v1.2.3 From a68dc42b6a835bd513e9d617c9892e85f321ddb6 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 8 Sep 2014 00:23:46 -0400 Subject: added some tests for a small inheritance hierarchy --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 8 ++++---- 1 file changed, 4 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 56031dd..9236d0c 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -95,7 +95,6 @@ public class TestJarIndexLoneClass assertThat( node.getObfClassName(), is( "none/a" ) ); assertThat( node.getChildCount(), is( 0 ) ); } - @Test public void methodInheritance( ) @@ -133,10 +132,11 @@ public class TestJarIndexLoneClass @SuppressWarnings( "unchecked" ) public void fieldReferences( ) { - Collection> references = m_index.getFieldReferences( newField( "none/a", "a" ) ); + FieldEntry source = newField( "none/a", "a" ); + Collection> references = m_index.getFieldReferences( source ); assertThat( references, containsInAnyOrder( - newFieldReferenceByConstructor( "none/a", "a", "none/a", "(Ljava/lang/String;)V" ), - newFieldReferenceByMethod( "none/a", "a", "none/a", "a", "()Ljava/lang/String;" ) + newFieldReferenceByConstructor( source, "none/a", "(Ljava/lang/String;)V" ), + newFieldReferenceByMethod( source, "none/a", "a", "()Ljava/lang/String;" ) ) ); } -- cgit v1.2.3 From 8409dea980fa03c06b180969c5e0696f7cb5474b Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 21 Sep 2014 00:32:03 -0400 Subject: started unit testing for inner/anonymous class detection --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 9236d0c..4c32b70 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -11,17 +11,9 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.newClass; -import static cuchaz.enigma.EntryFactory.newField; -import static cuchaz.enigma.EntryFactory.newFieldReferenceByConstructor; -import static cuchaz.enigma.EntryFactory.newFieldReferenceByMethod; -import static cuchaz.enigma.EntryFactory.newMethod; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; import java.util.Collection; import java.util.Set; -- cgit v1.2.3 From 8776a8ba38123c822530e5f659c626c8db616217 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 24 Sep 2014 01:00:54 -0400 Subject: HOW DO I WRITE SO MANY BUGS?!? --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 4c32b70..f77d86a 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin.\ + * 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 @@ -72,13 +72,6 @@ public class TestJarIndexLoneClass assertThat( m_index.getAccess( newField( "none/a", "b" ) ), is( nullValue() ) ); } - @Test - public void isImplemented( ) - { - assertThat( m_index.isMethodImplemented( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) ); - assertThat( m_index.isMethodImplemented( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), is( false ) ); - } - @Test public void classInheritance( ) { @@ -187,7 +180,7 @@ public class TestJarIndexLoneClass 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.containsObfMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( true ) ); - assertThat( m_index.containsObfMethod( newMethod( "none/a", "b", "()Ljava/lang/String;" ) ), 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 22cc7f91d61e32c751b74dc6662bef616ab5ddb7 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 2 Oct 2014 22:47:30 -0400 Subject: fixed test case --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index f77d86a..e2a87d0 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -140,7 +140,7 @@ public class TestJarIndexLoneClass @Test public void outerClass( ) { - assertThat( m_index.getOuterClass( "none/a" ), is( nullValue() ) ); + assertThat( m_index.getOuterClass( "a" ), is( nullValue() ) ); } @Test -- cgit v1.2.3 From 035e73fba69ab06172ae9d784b9e0e4fffeb8388 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 8 Oct 2014 23:54:08 -0400 Subject: relicense as LGPL --- 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 e2a87d0..defec46 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -1,10 +1,9 @@ /******************************************************************************* * 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 + * 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 812e2a4630ef01463ff153ba5ffae675e8ac24ac Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 9 Oct 2014 19:37:19 -0400 Subject: reverting to GPL license --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 7 ++++--- 1 file changed, 4 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 defec46..e2a87d0 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -1,9 +1,10 @@ /******************************************************************************* * Copyright (c) 2014 Jeff Martin. + * * All rights reserved. This program and the accompanying materials - * 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 + * 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 -- cgit v1.2.3 From 959cb5fd4f9586ec3bd265b452fe25fe1db82e3f Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 13 Jan 2015 23:25:04 -0500 Subject: source format change don't hate me too much if you were planning a big merge. =P --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 168 ++++++++++++-------------- 1 file changed, 75 insertions(+), 93 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index e2a87d0..0575eec 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -33,154 +33,136 @@ import cuchaz.enigma.mapping.FieldEntry; import cuchaz.enigma.mapping.MethodEntry; import cuchaz.enigma.mapping.Translator; -public class TestJarIndexLoneClass -{ +public class TestJarIndexLoneClass { + private JarIndex m_index; - public TestJarIndexLoneClass( ) - throws Exception - { + public TestJarIndexLoneClass() throws Exception { m_index = new JarIndex(); - m_index.indexJar( new JarFile( "build/libs/testLoneClass.obf.jar" ), false ); + m_index.indexJar(new JarFile("build/libs/testLoneClass.obf.jar"), false); } @Test - public void obfEntries( ) - { - assertThat( m_index.getObfClassEntries(), containsInAnyOrder( - newClass( "cuchaz/enigma/inputs/Keep" ), - newClass( "none/a" ) - ) ); + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + newClass("none/a") + )); } @Test - public void translationIndex( ) - { - assertThat( m_index.getTranslationIndex().getSuperclassName( "none/a" ), is( nullValue() ) ); - assertThat( m_index.getTranslationIndex().getSuperclassName( "cuchaz/enigma/inputs/Keep" ), is( nullValue() ) ); - assertThat( m_index.getTranslationIndex().getAncestry( "none/a" ), is( empty() ) ); - assertThat( m_index.getTranslationIndex().getAncestry( "cuchaz/enigma/inputs/Keep" ), is( empty() ) ); - assertThat( m_index.getTranslationIndex().getSubclassNames( "none/a" ), is( empty() ) ); - assertThat( m_index.getTranslationIndex().getSubclassNames( "cuchaz/enigma/inputs/Keep" ), is( empty() ) ); + public void translationIndex() { + assertThat(m_index.getTranslationIndex().getSuperclassName("none/a"), is(nullValue())); + assertThat(m_index.getTranslationIndex().getSuperclassName("cuchaz/enigma/inputs/Keep"), is(nullValue())); + assertThat(m_index.getTranslationIndex().getAncestry("none/a"), is(empty())); + assertThat(m_index.getTranslationIndex().getAncestry("cuchaz/enigma/inputs/Keep"), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclassNames("none/a"), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclassNames("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() ) ); + 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 ) ); + 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 ) ); + 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() ) ); + 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() ) ); + 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;" ) ) ); + 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;" ) - ) ); + @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() ) ); + 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() ) ); + public void innerClasses() { + assertThat(m_index.getInnerClasses("none/a"), is(empty())); } @Test - public void outerClass( ) - { - assertThat( m_index.getOuterClass( "a" ), is( nullValue() ) ); + public void outerClass() { + assertThat(m_index.getOuterClass("a"), is(nullValue())); } @Test - public void isAnonymousClass( ) - { - assertThat( m_index.isAnonymousClass( "none/a" ), is( false ) ); + public void isAnonymousClass() { + assertThat(m_index.isAnonymousClass("none/a"), is(false)); } @Test - public void interfaces( ) - { - assertThat( m_index.getInterfaces( "none/a" ), is( empty() ) ); + public void interfaces() { + assertThat(m_index.getInterfaces("none/a"), is(empty())); } @Test - public void implementingClasses( ) - { - assertThat( m_index.getImplementingClasses( "none/a" ), is( empty() ) ); + public void implementingClasses() { + assertThat(m_index.getImplementingClasses("none/a"), is(empty())); } @Test - public void isInterface( ) - { - assertThat( m_index.isInterface( "none/a" ), is( false ) ); + public void isInterface() { + assertThat(m_index.isInterface("none/a"), is(false)); } @Test - public void bridgeMethods( ) - { - assertThat( m_index.getBridgeMethod( newMethod( "none/a", "a", "()Ljava/lang/String;" ) ), is( nullValue() ) ); + public void bridgeMethods() { + assertThat(m_index.getBridgeMethod(newMethod("none/a", "a", "()Ljava/lang/String;")), is(nullValue())); } @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 ) ); + 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 2fbcf8e5c4eec0aa4a4fc59c7cc8abac33b1429c Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 19 Jan 2015 22:22:57 -0500 Subject: solved tricky issue with incorrect translation of fields/methods referenced by a subclass instead of the declaring class --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 0575eec..a061b72 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -29,6 +29,7 @@ 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; @@ -39,7 +40,7 @@ public class TestJarIndexLoneClass { public TestJarIndexLoneClass() throws Exception { m_index = new JarIndex(); - m_index.indexJar(new JarFile("build/libs/testLoneClass.obf.jar"), false); + m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); } @Test @@ -52,12 +53,12 @@ public class TestJarIndexLoneClass { @Test public void translationIndex() { - assertThat(m_index.getTranslationIndex().getSuperclassName("none/a"), is(nullValue())); - assertThat(m_index.getTranslationIndex().getSuperclassName("cuchaz/enigma/inputs/Keep"), is(nullValue())); - assertThat(m_index.getTranslationIndex().getAncestry("none/a"), is(empty())); - assertThat(m_index.getTranslationIndex().getAncestry("cuchaz/enigma/inputs/Keep"), is(empty())); - assertThat(m_index.getTranslationIndex().getSubclassNames("none/a"), is(empty())); - assertThat(m_index.getTranslationIndex().getSubclassNames("cuchaz/enigma/inputs/Keep"), is(empty())); + 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 -- cgit v1.2.3 From 818716acb3992e602e01725b6e151c1eb0f6c2e2 Mon Sep 17 00:00:00 2001 From: jeff Date: Thu, 5 Feb 2015 23:52:55 -0500 Subject: fix test code formatting and disable the super duper slow test for now --- test/cuchaz/enigma/TestJarIndexLoneClass.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/cuchaz/enigma/TestJarIndexLoneClass.java') diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index a061b72..108c623 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -38,7 +38,8 @@ public class TestJarIndexLoneClass { private JarIndex m_index; - public TestJarIndexLoneClass() throws Exception { + public TestJarIndexLoneClass() + throws Exception { m_index = new JarIndex(); m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); } -- cgit v1.2.3