diff options
| author | 2014-09-14 21:54:58 -0400 | |
|---|---|---|
| committer | 2014-09-14 21:54:58 -0400 | |
| commit | 6736d9aac3e7d1591cba33852126abf79dd18a57 (patch) | |
| tree | 63afffa4db2ee1cdcab969632d39ee985b815cf8 | |
| parent | fixed bug with method references pointing to wrong class (diff) | |
| download | enigma-6736d9aac3e7d1591cba33852126abf79dd18a57.tar.gz enigma-6736d9aac3e7d1591cba33852126abf79dd18a57.tar.xz enigma-6736d9aac3e7d1591cba33852126abf79dd18a57.zip | |
added test to check constructor references
| -rw-r--r-- | build.gradle | 12 | ||||
| -rw-r--r-- | test/cuchaz/enigma/TestJarIndexConstructorReferences.java | 129 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/constructors/BaseClass.java | 17 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/constructors/Caller.java | 47 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/constructors/SubClass.java | 31 | ||||
| -rw-r--r-- | test/cuchaz/enigma/inputs/constructors/SubSubClass.java | 12 |
6 files changed, 246 insertions, 2 deletions
diff --git a/build.gradle b/build.gradle index 10294292..767b0321 100644 --- a/build.gradle +++ b/build.gradle | |||
| @@ -82,8 +82,16 @@ task jarInheritanceTree( type: Jar ) { | |||
| 82 | archiveName( "testInheritanceTree.jar" ) | 82 | archiveName( "testInheritanceTree.jar" ) |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | task jarConstructors( type: Jar ) { | ||
| 86 | from( sourceSets.test.output ) { | ||
| 87 | include( "cuchaz/enigma/inputs/Keep.class" ) | ||
| 88 | include( "cuchaz/enigma/inputs/constructors/**" ) | ||
| 89 | } | ||
| 90 | archiveName( "testConstructors.jar" ) | ||
| 91 | } | ||
| 92 | |||
| 85 | task obfTestCases( type: proguard.gradle.ProGuardTask ) { | 93 | task obfTestCases( type: proguard.gradle.ProGuardTask ) { |
| 86 | dependsOn jarLoneClass, jarInheritanceTree | 94 | dependsOn jarLoneClass, jarInheritanceTree, jarConstructors |
| 87 | 95 | ||
| 88 | libraryjars( "${System.getProperty('java.home')}/lib/rt.jar" ) | 96 | libraryjars( "${System.getProperty('java.home')}/lib/rt.jar" ) |
| 89 | overloadaggressively | 97 | overloadaggressively |
| @@ -94,7 +102,7 @@ task obfTestCases( type: proguard.gradle.ProGuardTask ) { | |||
| 94 | 102 | ||
| 95 | keep( "class cuchaz.enigma.inputs.Keep" ) | 103 | keep( "class cuchaz.enigma.inputs.Keep" ) |
| 96 | 104 | ||
| 97 | def jarNames = [ "LoneClass", "InheritanceTree" ]; | 105 | def jarNames = [ "LoneClass", "InheritanceTree", "Constructors" ]; |
| 98 | jarNames.each() { | 106 | jarNames.each() { |
| 99 | injars( "build/libs/test${it}.jar" ) | 107 | injars( "build/libs/test${it}.jar" ) |
| 100 | outjars( "build/libs/test${it}.obf.jar" ) | 108 | outjars( "build/libs/test${it}.obf.jar" ) |
diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java new file mode 100644 index 00000000..38882a0c --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -0,0 +1,129 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByConstructor; | ||
| 14 | import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByMethod; | ||
| 15 | import static cuchaz.enigma.EntryFactory.newClass; | ||
| 16 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 17 | import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| 18 | import static org.hamcrest.Matchers.empty; | ||
| 19 | import static org.hamcrest.Matchers.is; | ||
| 20 | |||
| 21 | import java.util.jar.JarFile; | ||
| 22 | |||
| 23 | import org.junit.Test; | ||
| 24 | |||
| 25 | import cuchaz.enigma.analysis.JarIndex; | ||
| 26 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 27 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 28 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 29 | |||
| 30 | public class TestJarIndexConstructorReferences | ||
| 31 | { | ||
| 32 | private JarIndex m_index; | ||
| 33 | |||
| 34 | private ClassEntry m_baseClass = new ClassEntry( "none/a" ); | ||
| 35 | private ClassEntry m_subClass = new ClassEntry( "none/c" ); | ||
| 36 | private ClassEntry m_subsubClass = new ClassEntry( "none/d" ); | ||
| 37 | private ClassEntry m_callerClass = new ClassEntry( "none/b" ); | ||
| 38 | |||
| 39 | public TestJarIndexConstructorReferences( ) | ||
| 40 | throws Exception | ||
| 41 | { | ||
| 42 | m_index = new JarIndex(); | ||
| 43 | m_index.indexJar( new JarFile( "build/libs/testConstructors.obf.jar" ), false ); | ||
| 44 | } | ||
| 45 | |||
| 46 | @Test | ||
| 47 | public void obfEntries( ) | ||
| 48 | { | ||
| 49 | assertThat( m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 50 | newClass( "cuchaz/enigma/inputs/Keep" ), | ||
| 51 | m_baseClass, | ||
| 52 | m_subClass, | ||
| 53 | m_subsubClass, | ||
| 54 | m_callerClass | ||
| 55 | ) ); | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test | ||
| 59 | @SuppressWarnings( "unchecked" ) | ||
| 60 | public void baseDefault( ) | ||
| 61 | { | ||
| 62 | BehaviorEntry source = new ConstructorEntry( m_baseClass, "()V" ); | ||
| 63 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 64 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "a", "()V" ), | ||
| 65 | newBehaviorReferenceByConstructor( source, m_subClass.getName(), "()V" ), | ||
| 66 | newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(III)V" ) | ||
| 67 | ) ); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Test | ||
| 71 | @SuppressWarnings( "unchecked" ) | ||
| 72 | public void baseInt( ) | ||
| 73 | { | ||
| 74 | BehaviorEntry source = new ConstructorEntry( m_baseClass, "(I)V" ); | ||
| 75 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 76 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "b", "()V" ) | ||
| 77 | ) ); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Test | ||
| 81 | @SuppressWarnings( "unchecked" ) | ||
| 82 | public void subDefault( ) | ||
| 83 | { | ||
| 84 | BehaviorEntry source = new ConstructorEntry( m_subClass, "()V" ); | ||
| 85 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 86 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "c", "()V" ), | ||
| 87 | newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(I)V" ) | ||
| 88 | ) ); | ||
| 89 | } | ||
| 90 | |||
| 91 | @Test | ||
| 92 | @SuppressWarnings( "unchecked" ) | ||
| 93 | public void subInt( ) | ||
| 94 | { | ||
| 95 | BehaviorEntry source = new ConstructorEntry( m_subClass, "(I)V" ); | ||
| 96 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 97 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "d", "()V" ), | ||
| 98 | newBehaviorReferenceByConstructor( source, m_subClass.getName(), "(II)V" ), | ||
| 99 | newBehaviorReferenceByConstructor( source, m_subsubClass.getName(), "(I)V" ) | ||
| 100 | ) ); | ||
| 101 | } | ||
| 102 | |||
| 103 | @Test | ||
| 104 | @SuppressWarnings( "unchecked" ) | ||
| 105 | public void subIntInt( ) | ||
| 106 | { | ||
| 107 | BehaviorEntry source = new ConstructorEntry( m_subClass, "(II)V" ); | ||
| 108 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 109 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "e", "()V" ) | ||
| 110 | ) ); | ||
| 111 | } | ||
| 112 | |||
| 113 | @Test | ||
| 114 | public void subIntIntInt( ) | ||
| 115 | { | ||
| 116 | BehaviorEntry source = new ConstructorEntry( m_subClass, "(III)V" ); | ||
| 117 | assertThat( m_index.getBehaviorReferences( source ), is( empty() ) ); | ||
| 118 | } | ||
| 119 | |||
| 120 | @Test | ||
| 121 | @SuppressWarnings( "unchecked" ) | ||
| 122 | public void subsubInt( ) | ||
| 123 | { | ||
| 124 | BehaviorEntry source = new ConstructorEntry( m_subsubClass, "(I)V" ); | ||
| 125 | assertThat( m_index.getBehaviorReferences( source ), containsInAnyOrder( | ||
| 126 | newBehaviorReferenceByMethod( source, m_callerClass.getName(), "f", "()V" ) | ||
| 127 | ) ); | ||
| 128 | } | ||
| 129 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/BaseClass.java b/test/cuchaz/enigma/inputs/constructors/BaseClass.java new file mode 100644 index 00000000..e6d87681 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/BaseClass.java | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/a | ||
| 4 | public class BaseClass | ||
| 5 | { | ||
| 6 | // <init>()V | ||
| 7 | public BaseClass( ) | ||
| 8 | { | ||
| 9 | System.out.println( "Default constructor" ); | ||
| 10 | } | ||
| 11 | |||
| 12 | // <init>(I)V | ||
| 13 | public BaseClass( int i ) | ||
| 14 | { | ||
| 15 | System.out.println( "Int constructor " + i ); | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/Caller.java b/test/cuchaz/enigma/inputs/constructors/Caller.java new file mode 100644 index 00000000..f356b1b3 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/Caller.java | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/b | ||
| 4 | public class Caller | ||
| 5 | { | ||
| 6 | // a()V | ||
| 7 | public void callBaseDefault( ) | ||
| 8 | { | ||
| 9 | // none/a.<init>()V | ||
| 10 | System.out.println( new BaseClass() ); | ||
| 11 | } | ||
| 12 | |||
| 13 | // b()V | ||
| 14 | public void callBaseInt( ) | ||
| 15 | { | ||
| 16 | // none/a.<init>(I)V | ||
| 17 | System.out.println( new BaseClass( 5 ) ); | ||
| 18 | } | ||
| 19 | |||
| 20 | // c()V | ||
| 21 | public void callSubDefault( ) | ||
| 22 | { | ||
| 23 | // none/c.<init>()V | ||
| 24 | System.out.println( new SubClass() ); | ||
| 25 | } | ||
| 26 | |||
| 27 | // d()V | ||
| 28 | public void callSubInt( ) | ||
| 29 | { | ||
| 30 | // none/c.<init>(I)V | ||
| 31 | System.out.println( new SubClass( 6 ) ); | ||
| 32 | } | ||
| 33 | |||
| 34 | // e()V | ||
| 35 | public void callSubIntInt( ) | ||
| 36 | { | ||
| 37 | // none/c.<init>(II)V | ||
| 38 | System.out.println( new SubClass( 4, 2 ) ); | ||
| 39 | } | ||
| 40 | |||
| 41 | // f()V | ||
| 42 | public void callSubSubInt( ) | ||
| 43 | { | ||
| 44 | // none/d.<init>(I)V | ||
| 45 | System.out.println( new SubSubClass( 3 ) ); | ||
| 46 | } | ||
| 47 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/SubClass.java b/test/cuchaz/enigma/inputs/constructors/SubClass.java new file mode 100644 index 00000000..2235de37 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubClass.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/c extends none/a | ||
| 4 | public class SubClass extends BaseClass | ||
| 5 | { | ||
| 6 | // <init>()V | ||
| 7 | public SubClass( ) | ||
| 8 | { | ||
| 9 | // none/a.<init>()V | ||
| 10 | } | ||
| 11 | |||
| 12 | // <init>(I)V | ||
| 13 | public SubClass( int num ) | ||
| 14 | { | ||
| 15 | // <init>()V | ||
| 16 | this(); | ||
| 17 | System.out.println( "SubClass " + num ); | ||
| 18 | } | ||
| 19 | |||
| 20 | // <init>(II)V | ||
| 21 | public SubClass( int a, int b ) | ||
| 22 | { | ||
| 23 | // <init>(I)V | ||
| 24 | this( a + b ); | ||
| 25 | } | ||
| 26 | |||
| 27 | public SubClass( int a, int b, int c ) | ||
| 28 | { | ||
| 29 | // none/a.<init>()V | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/SubSubClass.java b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java new file mode 100644 index 00000000..a9445d8b --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/d extends none/c | ||
| 4 | public class SubSubClass extends SubClass | ||
| 5 | { | ||
| 6 | // <init>(I)V | ||
| 7 | public SubSubClass( int i ) | ||
| 8 | { | ||
| 9 | // none/c.<init>(I)V | ||
| 10 | super( i ); | ||
| 11 | } | ||
| 12 | } | ||