-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
jadx-core/src/test/java/jadx/tests/integration/others/TestStringConstructor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package jadx.tests.integration.others; | ||
|
||
import static jadx.tests.api.utils.JadxMatchers.containsOne; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import jadx.core.dex.nodes.ClassNode; | ||
import jadx.tests.api.IntegrationTest; | ||
|
||
public class TestStringConstructor extends IntegrationTest { | ||
|
||
public static class TestCls { | ||
public String tag = new String(new byte[] {'a', 'b', 'c'}); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
ClassNode cls = getClassNode(TestCls.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("abc")); | ||
} | ||
|
||
public static class TestCls2 { | ||
public String tag = new String(new byte[] {'a', 'b', 'c'}, StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void test2() { | ||
ClassNode cls = getClassNode(TestCls2.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("new String(\"abc\".getBytes(), StandardCharsets.UTF_8)")); | ||
} | ||
|
||
public static class TestCls3 { | ||
public String tag = new String(new byte[] {1, 2, 3, 'a', 'b', 'c'}); | ||
} | ||
|
||
@Test | ||
public void test3() { | ||
ClassNode cls = getClassNode(TestCls3.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("\\u0001\\u0002\\u0003abc")); | ||
} | ||
|
||
public static class TestCls4 { | ||
public String tag = new String(new char[] {1, 2, 3, 'a', 'b', 'c'}); | ||
} | ||
|
||
@Test | ||
public void test4() { | ||
ClassNode cls = getClassNode(TestCls4.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("\\u0001\\u0002\\u0003abc")); | ||
} | ||
|
||
public static class TestCls5 { | ||
public String tag = new String(new char[] {1, 2, 3, 'a', 'b'}); | ||
} | ||
|
||
@Test | ||
public void test5() { | ||
ClassNode cls = getClassNode(TestCls5.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("{1, 2, 3, 'a', 'b'}")); | ||
} | ||
|
||
public static class TestClsNegative { | ||
public String tag = new String(); | ||
} | ||
|
||
@Test | ||
public void testNegative() { | ||
ClassNode cls = getClassNode(TestClsNegative.class); | ||
String code = cls.getCode().toString(); | ||
|
||
assertThat(code, containsOne("tag = new String();")); | ||
} | ||
} |