From 72e918a5134c2bf747a476284bcfa1bd2ef2fa21 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 14 Sep 2014 23:56:43 -0400 Subject: added tests to check constructor tokens fixed a bug with constructor tokens too --- test/cuchaz/enigma/TestTokensConstructors.java | 152 +++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 test/cuchaz/enigma/TestTokensConstructors.java (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java new file mode 100644 index 0000000..2409153 --- /dev/null +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * 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.newBehaviorReferenceByConstructor; +import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByMethod; +import static cuchaz.enigma.EntryFactory.newConstructor; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; + +import java.io.File; + +import org.junit.Test; + +import cuchaz.enigma.mapping.BehaviorEntry; + +public class TestTokensConstructors extends TokenChecker +{ + public TestTokensConstructors( ) + throws Exception + { + super( new File( "build/libs/testConstructors.obf.jar" ) ); + } + + @Test + public void baseDeclarations( ) + { + assertThat( getDeclarationToken( newConstructor( "none/a", "()V" ) ), is( "a" ) ); + assertThat( getDeclarationToken( newConstructor( "none/a", "(I)V" ) ), is( "a" ) ); + } + + @Test + public void subDeclarations( ) + { + assertThat( getDeclarationToken( newConstructor( "none/d", "()V" ) ), is( "d" ) ); + assertThat( getDeclarationToken( newConstructor( "none/d", "(I)V" ) ), is( "d" ) ); + assertThat( getDeclarationToken( newConstructor( "none/d", "(II)V" ) ), is( "d" ) ); + assertThat( getDeclarationToken( newConstructor( "none/d", "(III)V" ) ), is( "d" ) ); + } + + @Test + public void subsubDeclarations( ) + { + assertThat( getDeclarationToken( newConstructor( "none/e", "(I)V" ) ), is( "e" ) ); + } + + @Test + public void defaultDeclarations( ) + { + assertThat( getDeclarationToken( newConstructor( "none/c", "()V" ) ), nullValue() ); + } + + @Test + public void baseDefaultReferences( ) + { + BehaviorEntry source = newConstructor( "none/a", "()V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "a", "()V" ) ), + containsInAnyOrder( "a" ) + ); + assertThat( + getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "()V" ) ), + containsInAnyOrder( "super" ) // implicit call, decompiled to "super" + ); + assertThat( + getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(III)V" ) ), + containsInAnyOrder( "super" ) // implicit call, decompiled to "super" + ); + } + + @Test + public void baseIntReferences( ) + { + BehaviorEntry source = newConstructor( "none/a", "(I)V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "b", "()V" ) ), + containsInAnyOrder( "a" ) + ); + } + + @Test + public void subDefaultReferences( ) + { + BehaviorEntry source = newConstructor( "none/d", "()V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "c", "()V" ) ), + containsInAnyOrder( "d" ) + ); + assertThat( + getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(I)V" ) ), + containsInAnyOrder( "this" ) + ); + } + + @Test + public void subIntReferences( ) + { + BehaviorEntry source = newConstructor( "none/d", "(I)V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "d", "()V" ) ), + containsInAnyOrder( "d" ) + ); + assertThat( + getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(II)V" ) ), + containsInAnyOrder( "this" ) + ); + assertThat( + getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/e", "(I)V" ) ), + containsInAnyOrder( "super" ) + ); + } + + @Test + public void subIntIntReferences( ) + { + BehaviorEntry source = newConstructor( "none/d", "(II)V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "e", "()V" ) ), + containsInAnyOrder( "d" ) + ); + } + + @Test + public void subsubIntReferences( ) + { + BehaviorEntry source = newConstructor( "none/e", "(I)V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "f", "()V" ) ), + containsInAnyOrder( "e" ) + ); + } + + @Test + public void defaultConstructableReferences( ) + { + BehaviorEntry source = newConstructor( "none/c", "()V" ); + assertThat( + getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "g", "()V" ) ), + containsInAnyOrder( "c" ) + ); + } +} -- 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/TestTokensConstructors.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 2409153..449d70e 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -1,9 +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/TestTokensConstructors.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 449d70e..2409153 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -1,9 +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 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/TestTokensConstructors.java | 137 +++++++++++-------------- 1 file changed, 62 insertions(+), 75 deletions(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 2409153..f805a65 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -24,129 +24,116 @@ import org.junit.Test; import cuchaz.enigma.mapping.BehaviorEntry; -public class TestTokensConstructors extends TokenChecker -{ - public TestTokensConstructors( ) - throws Exception - { - super( new File( "build/libs/testConstructors.obf.jar" ) ); +public class TestTokensConstructors extends TokenChecker { + + public TestTokensConstructors() throws Exception { + super(new File("build/libs/testConstructors.obf.jar")); } @Test - public void baseDeclarations( ) - { - assertThat( getDeclarationToken( newConstructor( "none/a", "()V" ) ), is( "a" ) ); - assertThat( getDeclarationToken( newConstructor( "none/a", "(I)V" ) ), is( "a" ) ); + public void baseDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/a", "()V")), is("a")); + assertThat(getDeclarationToken(newConstructor("none/a", "(I)V")), is("a")); } @Test - public void subDeclarations( ) - { - assertThat( getDeclarationToken( newConstructor( "none/d", "()V" ) ), is( "d" ) ); - assertThat( getDeclarationToken( newConstructor( "none/d", "(I)V" ) ), is( "d" ) ); - assertThat( getDeclarationToken( newConstructor( "none/d", "(II)V" ) ), is( "d" ) ); - assertThat( getDeclarationToken( newConstructor( "none/d", "(III)V" ) ), is( "d" ) ); + public void subDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/d", "()V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(I)V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(II)V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(III)V")), is("d")); } @Test - public void subsubDeclarations( ) - { - assertThat( getDeclarationToken( newConstructor( "none/e", "(I)V" ) ), is( "e" ) ); + public void subsubDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/e", "(I)V")), is("e")); } @Test - public void defaultDeclarations( ) - { - assertThat( getDeclarationToken( newConstructor( "none/c", "()V" ) ), nullValue() ); + public void defaultDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/c", "()V")), nullValue()); } @Test - public void baseDefaultReferences( ) - { - BehaviorEntry source = newConstructor( "none/a", "()V" ); + public void baseDefaultReferences() { + BehaviorEntry source = newConstructor("none/a", "()V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "a", "()V" ) ), - containsInAnyOrder( "a" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "a", "()V")), + containsInAnyOrder("a") ); assertThat( - getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "()V" ) ), - containsInAnyOrder( "super" ) // implicit call, decompiled to "super" + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "()V")), + containsInAnyOrder("super") // implicit call, decompiled to "super" ); assertThat( - getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(III)V" ) ), - containsInAnyOrder( "super" ) // implicit call, decompiled to "super" + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(III)V")), + containsInAnyOrder("super") // implicit call, decompiled to "super" ); } @Test - public void baseIntReferences( ) - { - BehaviorEntry source = newConstructor( "none/a", "(I)V" ); + public void baseIntReferences() { + BehaviorEntry source = newConstructor("none/a", "(I)V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "b", "()V" ) ), - containsInAnyOrder( "a" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "b", "()V")), + containsInAnyOrder("a") ); } - + @Test - public void subDefaultReferences( ) - { - BehaviorEntry source = newConstructor( "none/d", "()V" ); + public void subDefaultReferences() { + BehaviorEntry source = newConstructor("none/d", "()V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "c", "()V" ) ), - containsInAnyOrder( "d" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "c", "()V")), + containsInAnyOrder("d") ); assertThat( - getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(I)V" ) ), - containsInAnyOrder( "this" ) + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(I)V")), + containsInAnyOrder("this") ); } - + @Test - public void subIntReferences( ) - { - BehaviorEntry source = newConstructor( "none/d", "(I)V" ); - assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "d", "()V" ) ), - containsInAnyOrder( "d" ) + public void subIntReferences() { + BehaviorEntry source = newConstructor("none/d", "(I)V"); + assertThat(getReferenceTokens( + newBehaviorReferenceByMethod(source, "none/b", "d", "()V")), + containsInAnyOrder("d") ); - assertThat( - getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/d", "(II)V" ) ), - containsInAnyOrder( "this" ) + assertThat(getReferenceTokens( + newBehaviorReferenceByConstructor(source, "none/d", "(II)V")), + containsInAnyOrder("this") ); - assertThat( - getReferenceTokens( newBehaviorReferenceByConstructor( source, "none/e", "(I)V" ) ), - containsInAnyOrder( "super" ) + assertThat(getReferenceTokens( + newBehaviorReferenceByConstructor(source, "none/e", "(I)V")), + containsInAnyOrder("super") ); } - + @Test - public void subIntIntReferences( ) - { - BehaviorEntry source = newConstructor( "none/d", "(II)V" ); + public void subIntIntReferences() { + BehaviorEntry source = newConstructor("none/d", "(II)V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "e", "()V" ) ), - containsInAnyOrder( "d" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "e", "()V")), + containsInAnyOrder("d") ); } - + @Test - public void subsubIntReferences( ) - { - BehaviorEntry source = newConstructor( "none/e", "(I)V" ); + public void subsubIntReferences() { + BehaviorEntry source = newConstructor("none/e", "(I)V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "f", "()V" ) ), - containsInAnyOrder( "e" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "f", "()V")), + containsInAnyOrder("e") ); } - + @Test - public void defaultConstructableReferences( ) - { - BehaviorEntry source = newConstructor( "none/c", "()V" ); + public void defaultConstructableReferences() { + BehaviorEntry source = newConstructor("none/c", "()V"); assertThat( - getReferenceTokens( newBehaviorReferenceByMethod( source, "none/b", "g", "()V" ) ), - containsInAnyOrder( "c" ) + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "g", "()V")), + containsInAnyOrder("c") ); } } -- 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/TestTokensConstructors.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index f805a65..9f85e81 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -27,7 +27,7 @@ import cuchaz.enigma.mapping.BehaviorEntry; public class TestTokensConstructors extends TokenChecker { public TestTokensConstructors() throws Exception { - super(new File("build/libs/testConstructors.obf.jar")); + super(new File("build/testConstructors.obf.jar")); } @Test -- cgit v1.2.3 From 448685653e90415ebe10b08e8335462b81c30421 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 2 Feb 2015 21:26:10 -0500 Subject: fix issue with bridge methods --- test/cuchaz/enigma/TestTokensConstructors.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 9f85e81..56424ae 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -10,15 +10,11 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByConstructor; -import static cuchaz.enigma.EntryFactory.newBehaviorReferenceByMethod; -import static cuchaz.enigma.EntryFactory.newConstructor; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; -import java.io.File; +import java.util.jar.JarFile; import org.junit.Test; @@ -27,7 +23,7 @@ import cuchaz.enigma.mapping.BehaviorEntry; public class TestTokensConstructors extends TokenChecker { public TestTokensConstructors() throws Exception { - super(new File("build/testConstructors.obf.jar")); + super(new JarFile("build/testConstructors.obf.jar")); } @Test @@ -63,11 +59,11 @@ public class TestTokensConstructors extends TokenChecker { ); assertThat( getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "()V")), - containsInAnyOrder("super") // implicit call, decompiled to "super" + is(empty()) // implicit call, not decompiled to token ); assertThat( getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(III)V")), - containsInAnyOrder("super") // implicit call, decompiled to "super" + is(empty()) // implicit call, not decompiled to token ); } -- 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/TestTokensConstructors.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/cuchaz/enigma/TestTokensConstructors.java') diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 56424ae..6758d2a 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -22,7 +22,8 @@ import cuchaz.enigma.mapping.BehaviorEntry; public class TestTokensConstructors extends TokenChecker { - public TestTokensConstructors() throws Exception { + public TestTokensConstructors() + throws Exception { super(new JarFile("build/testConstructors.obf.jar")); } -- cgit v1.2.3