JDWP: Add test for SourceDebugExtension

Bug: 30109642
Test: art/tools/run-jdwp-tests.sh --mode=host --test org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionTest

Change-Id: I73b79da3c27a1fdbc5b58226dd1b45bc0fe0ce81
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee.java
index b898a25..0f9183a 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee.java
@@ -30,8 +30,17 @@
 
 public class SourceDebugExtensionDebuggee extends SyncDebuggee {
 
+    private final static String classWithSourceDebugExtension =
+        "org.apache.harmony.jpda.tests.jdwp.Events.SourceDebugExtensionMockClass";
+
     @Override
     public void run() {
+        Class<?> klass = null;
+        try {
+          klass = Class.forName(classWithSourceDebugExtension);
+        } catch (ClassNotFoundException e) {
+          logWriter.println("--> Debuggee: Could not find class " + classWithSourceDebugExtension);
+        }
         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
         logWriter.println("--> Debuggee: SourceDebugExtensionDebuggee...");
         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
@@ -41,4 +50,4 @@
         runDebuggee(SourceDebugExtensionDebuggee.class);
     }
 
-}
\ No newline at end of file
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionTest.java
index c002e08..93dbfa9 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionTest.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionTest.java
@@ -41,7 +41,12 @@
     static final int testStatusPassed = 0;
     static final int testStatusFailed = -1;
     static final String thisCommandName = "ReferenceType.SourceDebugExtension command";
-    static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee;";
+    static final String debuggeeSignature =
+            "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee;";
+    static final String classWithSourceDebugExtension =
+            "Lorg/apache/harmony/jpda/tests/jdwp/Events/SourceDebugExtensionMockClass;";
+    static final String expectedSourceDebugExtension = "SMAP\nhelloworld_jsp.java\nJSP\n*S JSP\n" +
+            "*F\n+ 0 helloworld.jsp\nhelloworld.jsp\n*L\n1,5:53\n6:58,3\n7,4:61\n*E\n";
 
     @Override
     protected String getDebuggeeClassName() {
@@ -50,10 +55,14 @@
 
     /**
      * This testcase exercises ReferenceType.SourceDebugExtension command.
-     * <BR>The test starts SourceDebugExtensionDebuggee class, requests referenceTypeId
-     * for this class by VirtualMachine.ClassesBySignature command, then
-     * performs ReferenceType.SourceDebugExtension command and checks that
-     * no any unexpected ERROR is returned.
+     *
+     * <BR>The test starts a SourceDebugExtensionDebuggee instance, which instantiates a
+     * SourceDebugExtensionMockClass instance. The SourceDebugExtensionMockClass comes from a
+     * class file generated by a JSP to Java bytecode compiler. The testcase requests
+     * referenceTypeId for this class by VirtualMachine.ClassesBySignature command, then
+     * performs ReferenceType.SourceDebugExtension to get the JSR45 metadata for the
+     * class. The testcase checks that no any unexpected ERROR is returned and that
+     * the JSR45 metadata matches the expected value.
      */
     public void testSourceDebugExtension001() {
         String thisTestName = "testSourceDebugExtension001";
@@ -67,11 +76,9 @@
 
         logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
-
-        long refTypeID = getClassIDBySignature(debuggeeSignature);
-
-        logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
-        logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);
+        long refTypeID = getClassIDBySignature(classWithSourceDebugExtension);
+        logWriter.println("=> Class with SourceDebugExtension = " + classWithSourceDebugExtension);
+        logWriter.println("=> referenceTypeID for class with SourceDebugExtension = " + refTypeID);
         logWriter.println("=> CHECK: send " + thisCommandName + " and check reply...");
 
         CommandPacket checkedCommand = new CommandPacket(
@@ -87,18 +94,9 @@
         switch ( errorCode ) {
             case JDWPConstants.Error.NONE:
                 logWriter.println("=> No any ERROR is returned");
-                String SourceDebugExtension = checkedReply.getNextValueAsString();
-                logWriter.println("=> Returned SourceDebugExtension = " + SourceDebugExtension);
-                break;
-            case JDWPConstants.Error.NOT_IMPLEMENTED:
-                logWriter.println("=> ERROR is returned: "+ errorCode
-                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
-                logWriter.println("=> It is possible ERROR");
-                break;
-            case JDWPConstants.Error.ABSENT_INFORMATION:
-                logWriter.println("=> ERROR is returned: "+ errorCode
-                        + "(" + JDWPConstants.Error.getName(errorCode) + ")");
-                    logWriter.println("=> It is possible ERROR");
+                String sourceDebugExtension = checkedReply.getNextValueAsString();
+                logWriter.println("=> Returned SourceDebugExtension = " + sourceDebugExtension);
+                assertEquals(expectedSourceDebugExtension, sourceDebugExtension);
                 break;
             default:
                 logWriter.println("\n## FAILURE: " + thisCommandName + " returns unexpected ERROR = "
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/CapabilitiesNewTest.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/CapabilitiesNewTest.java
index 1cfefb0..6432b98 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/CapabilitiesNewTest.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/VirtualMachine/CapabilitiesNewTest.java
@@ -50,7 +50,7 @@
             {"canUnrestrictedlyRedefineClasses", null},
             {"canPopFrames",                     null},
             {"canUseInstanceFilters",            "true"},
-            {"canGetSourceDebugExtension",       null},
+            {"canGetSourceDebugExtension",       "true"},
             {"canRequestVMDeathEvent",           null},
             {"canSetDefaultStratum",             null},
             {"canGetInstanceInfo",               "true"},