fix: cast of int-to-(number) when int is boolean (#596) (PR #602)

This commit is contained in:
Ahmed Ashour
2019-04-20 19:29:41 +03:00
committed by skylot
parent 2148d4b0f5
commit c134329ce9
14 changed files with 343 additions and 2 deletions
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToByte extends SmaliTest {
/**
private boolean showConsent;
public void write(byte b) {
}
public void writeToParcel(TestBooleanToByte testBooleanToByte) {
testBooleanToByte.write(this.showConsent ? (byte) 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToByte");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? (byte) 1 : 0);"));
}
}
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToChar extends SmaliTest {
/**
private boolean showConsent;
public void write(char b) {
}
public void writeToParcel(TestBooleanToChar testBooleanToChar) {
testBooleanToChar.write(this.showConsent ? (char) 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToChar");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? (char) 1 : 0);"));
}
}
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToDouble extends SmaliTest {
/**
private boolean showConsent;
public void write(double d) {
}
public void writeToParcel(TestBooleanToDouble testBooleanToDouble) {
testBooleanToDouble.write(this.showConsent ? 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToDouble");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? 1.0d : 0.0d);"));
}
}
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToFloat extends SmaliTest {
/**
private boolean showConsent;
public void write(float f) {
}
public void writeToParcel(TestBooleanToFloat testBooleanToFloat) {
testBooleanToFloat.write(this.showConsent ? 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToFloat");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? 1.0f : 0.0f);"));
}
}
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToLong extends SmaliTest {
/**
private boolean showConsent;
public void write(long j) {
}
public void writeToParcel(TestBooleanToLong testBooleanToLong) {
testBooleanToLong.write(this.showConsent ? 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToLong");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? 1 : 0);"));
}
}
@@ -0,0 +1,30 @@
package jadx.tests.integration.conditions;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import org.junit.jupiter.api.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.SmaliTest;
public class TestBooleanToShort extends SmaliTest {
/**
private boolean showConsent;
public void write(short b) {
}
public void writeToParcel(TestBooleanToShort testBooleanToShort) {
testBooleanToShort.write(this.showConsent ? (short) 1 : 0);
}
*/
@Test
public void test() {
ClassNode cls = getClassNodeFromSmaliWithPath("conditions", "TestBooleanToShort");
String code = cls.getCode().toString();
assertThat(code, containsString("write(this.showConsent ? (short) 1 : 0);"));
}
}
@@ -0,0 +1,22 @@
.class public LTestBooleanToByte;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToByte;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToByte;->showConsent:Z
int-to-byte p1, p1
invoke-virtual {p0, p1}, LTestBooleanToByte;->write(B)V
return-void
.end method
.method public write(B)V
.locals 0
return-void
.end method
@@ -0,0 +1,22 @@
.class public LTestBooleanToChar;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToChar;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToChar;->showConsent:Z
int-to-char p1, p1
invoke-virtual {p0, p1}, LTestBooleanToChar;->write(C)V
return-void
.end method
.method public write(C)V
.locals 0
return-void
.end method
@@ -0,0 +1,22 @@
.class public LTestBooleanToDouble;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToDouble;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToDouble;->showConsent:Z
int-to-double p1, p1
invoke-virtual {p0, p1}, LTestBooleanToDouble;->write(D)V
return-void
.end method
.method public write(D)V
.locals 0
return-void
.end method
@@ -0,0 +1,22 @@
.class public LTestBooleanToFloat;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToFloat;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToFloat;->showConsent:Z
int-to-float p1, p1
invoke-virtual {p0, p1}, LTestBooleanToFloat;->write(F)V
return-void
.end method
.method public write(F)V
.locals 0
return-void
.end method
@@ -0,0 +1,22 @@
.class public LTestBooleanToLong;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToLong;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToLong;->showConsent:Z
int-to-long p1, p1
invoke-virtual {p0, p1}, LTestBooleanToLong;->write(J)V
return-void
.end method
.method public write(J)V
.locals 0
return-void
.end method
@@ -0,0 +1,22 @@
.class public LTestBooleanToShort;
.super Ljava/lang/Object;
.field private showConsent:Z
.method public writeToParcel(LTestBooleanToShort;)V
.locals 0
iget-boolean p1, p0, LTestBooleanToShort;->showConsent:Z
int-to-short p1, p1
invoke-virtual {p0, p1}, LTestBooleanToShort;->write(S)V
return-void
.end method
.method public write(S)V
.locals 0
return-void
.end method