Home | History | Annotate | Download | only in debug
      1 // Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
      2 // for details. All rights reserved. Use of this source code is governed by a
      3 // BSD-style license that can be found in the LICENSE file.
      4 
      5 package com.android.tools.r8.debug;
      6 
      7 import com.android.tools.r8.debug.DebugTestBase.JUnit3Wrapper.Command;
      8 import java.util.ArrayList;
      9 import java.util.List;
     10 import org.junit.Test;
     11 
     12 public class InterfaceMethodTest extends DebugTestBase {
     13 
     14   private static final String SOURCE_FILE = "DebugInterfaceMethod.java";
     15 
     16   @Test
     17   public void testDefaultMethod() throws Throwable {
     18     String debuggeeClass = "DebugInterfaceMethod";
     19     String parameterName = "msg";
     20     String localVariableName = "name";
     21 
     22     List<Command> commands = new ArrayList<>();
     23     commands.add(breakpoint(debuggeeClass, "testDefaultMethod"));
     24     commands.add(run());
     25     commands.add(checkMethod(debuggeeClass, "testDefaultMethod"));
     26     commands.add(checkLine(SOURCE_FILE, 31));
     27     if (!supportsDefaultMethod()) {
     28       // We desugared default method. This means we're going to step through an extra (forward)
     29       // method first.
     30       commands.add(stepInto());
     31     }
     32     commands.add(stepInto());
     33     // TODO(shertz) we should see the local variable this even when desugaring.
     34     if (supportsDefaultMethod()) {
     35       commands.add(checkLocal("this"));
     36     }
     37     commands.add(checkLocal(parameterName));
     38     commands.add(stepOver());
     39     commands.add(checkLocal(parameterName));
     40     commands.add(checkLocal(localVariableName));
     41     // TODO(shertz) check current method name ?
     42     commands.add(run());
     43     commands.add(run()  /* resume after 2nd breakpoint */);
     44 
     45     runDebugTestJava8(debuggeeClass, commands);
     46   }
     47 
     48   @Test
     49   public void testOverrideDefaultMethod() throws Throwable {
     50     String debuggeeClass = "DebugInterfaceMethod";
     51     String parameterName = "msg";
     52     String localVariableName = "newMsg";
     53 
     54     List<Command> commands = new ArrayList<>();
     55     commands.add(breakpoint(debuggeeClass, "testDefaultMethod"));
     56     commands.add(run());
     57     commands.add(run() /* resume after 1st breakpoint */);
     58     commands.add(checkMethod(debuggeeClass, "testDefaultMethod"));
     59     commands.add(checkLine(SOURCE_FILE, 31));
     60     commands.add(stepInto());
     61     commands.add(checkMethod("DebugInterfaceMethod$OverrideImpl", "doSomething"));
     62     commands.add(checkLocal("this"));
     63     commands.add(checkLocal(parameterName));
     64     commands.add(stepOver());
     65     commands.add(checkLocal("this"));
     66     commands.add(checkLocal(parameterName));
     67     commands.add(checkLocal(localVariableName));
     68     commands.add(run());
     69 
     70     runDebugTestJava8(debuggeeClass, commands);
     71   }
     72 
     73   @Test
     74   public void testStaticMethod() throws Throwable {
     75     String debuggeeClass = "DebugInterfaceMethod";
     76     String parameterName = "msg";
     77 
     78     List<Command> commands = new ArrayList<>();
     79     commands.add(breakpoint(debuggeeClass, "testStaticMethod"));
     80     commands.add(run());
     81     commands.add(checkMethod(debuggeeClass, "testStaticMethod"));
     82     commands.add(checkLine(SOURCE_FILE, 35));
     83     commands.add(stepInto());
     84     commands.add(checkLocal(parameterName));
     85     commands.add(stepOver());
     86     commands.add(checkLocal(parameterName));
     87     commands.add(run());
     88 
     89     runDebugTestJava8(debuggeeClass, commands);
     90   }
     91 }
     92