fix: nullable signature members (#10)

This commit will allow "partial" signatures, basically we will be allowed to exclude members to match for the signature
This commit is contained in:
oSumAtrIX
2022-03-21 16:10:37 +01:00
parent bbb2c547aa
commit 674461f08d
3 changed files with 51 additions and 55 deletions

View File

@@ -9,13 +9,12 @@ import net.revanced.patcher.util.ExtraTypes
import net.revanced.patcher.util.TestUtil
import net.revanced.patcher.writer.ASMWriter.insertAt
import net.revanced.patcher.writer.ASMWriter.setAt
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.assertDoesNotThrow
import org.objectweb.asm.Opcodes.*
import org.objectweb.asm.Type
import org.objectweb.asm.tree.*
import java.io.PrintStream
import kotlin.test.Test
import kotlin.test.assertEquals
internal class PatcherTest {
companion object {
@@ -149,25 +148,21 @@ internal class PatcherTest {
//}
@Test()
fun `should raise an exception because opcodes is empty`() {
fun `should not raise an exception if any signature member except the name is missing`() {
val sigName = "testMethod"
val e = assertThrows<IllegalArgumentException>("Should raise an exception because opcodes is empty") {
assertDoesNotThrow("Should raise an exception because opcodes is empty") {
Patcher(
PatcherTest::class.java.getResourceAsStream("/test1.jar")!!,
arrayOf(
Signature(
sigName,
Type.VOID_TYPE,
ACC_PUBLIC or ACC_STATIC,
arrayOf(ExtraTypes.ArrayAny),
emptyArray() // this is not allowed for non-search signatures!
)
)
null,
null,
null,
null
))
)
}
assertEquals(
"Opcode list for signature $sigName is empty. This is not allowed for non-search signatures.",
e.message
)
}
}