aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/android/tools/r8/debug/InterfaceMethodTest.java
blob: 03f011fd6542685a5e1c048ec591886f5c6e5728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

package com.android.tools.r8.debug;

import static org.junit.Assert.assertEquals;

import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ToolHelper.DexVm;
import com.android.tools.r8.debug.DebugTestBase.JUnit3Wrapper.Command;
import com.android.tools.r8.debug.DebugTestBase.StepFilter.IntelliJStepFilter;
import java.util.ArrayList;
import java.util.List;
import org.junit.Assume;
import org.junit.Test;

public class InterfaceMethodTest extends DebugTestBase {

  private static final String SOURCE_FILE = "DebugInterfaceMethod.java";

  @Test
  public void testDefaultMethod() throws Throwable {
    // TODO(b/67225390) Dalvik steps into class loader first.
    Assume.assumeTrue("Dalvik suspends in class loader",
        ToolHelper.getDexVm().isNewerThan(DexVm.ART_4_4_4));

    String debuggeeClass = "DebugInterfaceMethod";
    String parameterName = "msg";
    String localVariableName = "name";

    List<Command> commands = new ArrayList<>();
    commands.add(breakpoint(debuggeeClass, "testDefaultMethod"));
    commands.add(run());
    commands.add(checkMethod(debuggeeClass, "testDefaultMethod"));
    commands.add(checkLine(SOURCE_FILE, 31));
    if (!supportsDefaultMethod()) {
      // We desugared default method. This means we're going to step through an extra (forward)
      // method first.
      commands.add(stepInto());
    }
    commands.add(stepInto());
    commands.add(checkLine(SOURCE_FILE, 9));
    // TODO(shertz) we should see the local variable this even when desugaring.
    if (supportsDefaultMethod()) {
      commands.add(checkLocal("this"));
    }
    commands.add(checkLocal(parameterName));
    commands.add(stepOver());
    commands.add(checkLocal(parameterName));
    commands.add(checkLocal(localVariableName));
    // TODO(shertz) check current method name ?
    commands.add(run());
    commands.add(run()  /* resume after 2nd breakpoint */);

    runDebugTestJava8(debuggeeClass, commands);
  }

  @Test
  public void testOverrideDefaultMethod() throws Throwable {
    String debuggeeClass = "DebugInterfaceMethod";
    String parameterName = "msg";
    String localVariableName = "newMsg";

    List<Command> commands = new ArrayList<>();
    commands.add(breakpoint(debuggeeClass, "testDefaultMethod"));
    commands.add(run());
    commands.add(run() /* resume after 1st breakpoint */);
    commands.add(checkMethod(debuggeeClass, "testDefaultMethod"));
    commands.add(checkLine(SOURCE_FILE, 31));
    commands.add(stepInto());
    commands.add(checkMethod("DebugInterfaceMethod$OverrideImpl", "doSomething"));
    commands.add(checkLocal("this"));
    commands.add(checkLocal(parameterName));
    commands.add(stepOver());
    commands.add(checkLocal("this"));
    commands.add(checkLocal(parameterName));
    commands.add(checkLocal(localVariableName));
    commands.add(run());

    runDebugTestJava8(debuggeeClass, commands);
  }

  @Test
  public void testStaticMethod() throws Throwable {
    String debuggeeClass = "DebugInterfaceMethod";
    String parameterName = "msg";

    List<Command> commands = new ArrayList<>();
    commands.add(breakpoint(debuggeeClass, "testStaticMethod"));
    commands.add(run());
    commands.add(checkMethod(debuggeeClass, "testStaticMethod"));
    commands.add(checkLine(SOURCE_FILE, 35));
    commands.add(stepInto());
    commands.add(checkLocal(parameterName));
    commands.add(stepOver());
    commands.add(checkLocal(parameterName));
    commands.add(run());

    runDebugTestJava8(debuggeeClass, commands);
  }
}