Package jadx.tests.integration.loops

Source Code of jadx.tests.integration.loops.TestLoopDetection

package jadx.tests.integration.loops;

import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;

public class TestLoopDetection extends IntegrationTest {

  public static class TestCls {

    private void test(int[] a, int b) {
      int i = 0;
      while (i < a.length && i < b) {
        a[i]++;
        i++;
      }
      while (i < a.length) {
        a[i]--;
        i++;
      }
    }
  }

  @Test
  public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();

    assertThat(code, containsString("while (i < a.length && i < b) {"));
    assertThat(code, containsString("while (i < a.length) {"));

    assertThat(code, containsString("int i = 0;"));
    assertThat(code, not(containsString("i_2")));
    assertThat(code, containsString("i++;"));
  }
}
TOP

Related Classes of jadx.tests.integration.loops.TestLoopDetection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.