Create jdwp test checking value of a static field in an interface.

Bug: 31016523
Test: mm run-jdwp-tests-ri & mm run-jdwp-tests-host

(cherry-picked from commit 3bb30d93008c92674d073593618e0fd269e569c1)

Change-Id: I2aa1083b914fd35b5abebae4aa07f85c73d83acf
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Debuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Debuggee.java
new file mode 100644
index 0000000..c0df0b9
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Debuggee.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+public class GetValues006Debuggee extends SyncDebuggee {
+
+    @Override
+    public void run() {
+        logWriter.println("--> Debuggee: GetValues006Debuggee: START");
+
+        GetValues006Interface instance = new GetValues006Implementer();
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("--> Debuggee: GetValues006Debuggee: FINISH");
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(GetValues006Debuggee.class);
+    }
+}
+
+interface GetValues006Interface {
+    static int interfaceStaticIntVar = 1;
+}
+
+class GetValues006Implementer implements GetValues006Interface {
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Test.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Test.java
new file mode 100644
index 0000000..30e600a
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues006Test.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.Value;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for ReferenceType.GetValues command for static field of interface class.
+ */
+public class GetValues006Test extends JDWPSyncTestCase {
+
+    @Override
+    protected String getDebuggeeClassName() {
+        return GetValues006Debuggee.class.getName();
+    }
+
+    /**
+     * This tests the ReferenceType.GetValues command on the static field of an interface.
+     * <BR>The test starts GetValues006Debuggee and checks that the ReferenceType.GetValues
+     * command runs correctly for a static field declared in an interface.
+     * <BR>Test checks that expected value of this field is returned.
+     */
+    public void testGetValues006() {
+        String thisTestName = "testGetValues006";
+        logWriter.println("==> " + thisTestName +
+            " for ReferenceType.GetValues command: START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        logWriter.println("\n=> Get debuggeeRefTypeID for debuggee class = "
+            + getDebuggeeClassName() + "...");
+        long debuggeeRefTypeID = getClassIDBySignature(getDebuggeeClassSignature());
+        logWriter.println("=> debuggeeRefTypeID = " + debuggeeRefTypeID);
+
+        logWriter.println(
+            "\n=> Get implementerRefTypeID for implementer = GetValues006Implementer...");
+        long implementerRefTypeID =
+            getClassIDBySignature(getClassSignature(GetValues006Interface.class));
+        logWriter.println("=> implementerRefTypeID = " + implementerRefTypeID);
+
+        logWriter.println("\n=> Get interfaceFieldID for field of interface class...");
+        String interfaceFieldName = "interfaceStaticIntVar";
+        long interfaceFieldID = checkField(implementerRefTypeID, interfaceFieldName);
+        logWriter.println("=> interfaceFieldID = " + interfaceFieldID);
+
+        logWriter.println("\n=> CHECK ReferenceType::GetValues command for implementerRefTypeID," +
+            " interfaceFieldID...");
+        CommandPacket getValuesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
+        getValuesCommand.setNextValueAsReferenceTypeID(implementerRefTypeID);
+        getValuesCommand.setNextValueAsInt(1);
+        getValuesCommand.setNextValueAsFieldID(interfaceFieldID);
+        ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
+        checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");
+
+        getValuesReply.getNextValueAsInt();
+        Value fieldValue = getValuesReply.getNextValueAsValue();
+        byte fieldTag = fieldValue.getTag();
+        logWriter.println("=> Returned value tag = " + fieldTag
+            + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
+        assertTagEquals("Invalid value tag is returned,", JDWPConstants.Tag.INT_TAG, fieldTag);
+
+        int intValue = fieldValue.getIntValue();
+        logWriter.println("=> Returned value = " + intValue);
+        // here expected value = 1 (staticIntField)
+        int expectedIntValue = 1;
+        assertEquals("Invalid int value,", expectedIntValue, intValue);
+
+        assertAllDataRead(getValuesReply);
+
+        logWriter.println("=> CHECK PASSED: Expected value is returned!");
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for ReferenceType::GetValues command: FINISH");
+    }
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Debuggee.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Debuggee.java
new file mode 100644
index 0000000..c6c19b7
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Debuggee.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
+
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+import org.apache.harmony.jpda.tests.share.SyncDebuggee;
+
+public class GetValues007Debuggee extends SyncDebuggee {
+
+    @Override
+    public void run() {
+        logWriter.println("--> Debuggee: GetValues007Debuggee: START");
+
+        GetValues007Interface instance = new GetValues007Implementer();
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("--> Debuggee: GetValues007Debuggee: FINISH");
+    }
+
+    public static void main(String [] args) {
+        runDebuggee(GetValues007Debuggee.class);
+    }
+}
+
+interface GetValues007Interface {
+    static int interfaceStaticIntVar = 1;
+}
+
+class GetValues007Implementer implements GetValues007Interface {
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Test.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Test.java
new file mode 100644
index 0000000..d4bcd34
--- /dev/null
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/jdwp/ReferenceType/GetValues007Test.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
+
+import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
+import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
+import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
+import org.apache.harmony.jpda.tests.framework.jdwp.Value;
+import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
+import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
+
+
+/**
+ * JDWP Unit test for ReferenceType.GetValues command for static field of interface class.
+ */
+public class GetValues007Test extends JDWPSyncTestCase {
+
+    @Override
+    protected String getDebuggeeClassName() {
+        return GetValues007Debuggee.class.getName();
+    }
+
+    /**
+     * This tests the ReferenceType.GetValues command on the static field of an interface.
+     * <BR>The test starts GetValues007Debuggee and checks that the ReferenceType.GetValues
+     * command runs correctly for a static field declared in an interface.
+     * <BR>Test checks that expected value of this field is returned.
+     */
+    public void testGetValues007() {
+        String thisTestName = "testGetValues007";
+        logWriter.println("==> " + thisTestName +
+            " for ReferenceType.GetValues command: START...");
+        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
+
+        logWriter.println("\n=> Get debuggeeRefTypeID for debuggee class = "
+            + getDebuggeeClassName() + "...");
+        long debuggeeRefTypeID = getClassIDBySignature(getDebuggeeClassSignature());
+        logWriter.println("=> debuggeeRefTypeID = " + debuggeeRefTypeID);
+
+        logWriter.println(
+            "\n=> Get implementerRefTypeID for implementer = GetValues007Implementer...");
+        long implementerRefTypeID =
+            getClassIDBySignature(getClassSignature(GetValues007Interface.class));
+        logWriter.println("=> implementerRefTypeID = " + implementerRefTypeID);
+
+        logWriter.println("\n=> Get interfaceFieldID for field of interface class...");
+        String interfaceFieldName = "interfaceStaticIntVar";
+        long interfaceFieldID = checkField(implementerRefTypeID, interfaceFieldName);
+        logWriter.println("=> interfaceFieldID = " + interfaceFieldID);
+
+        logWriter.println("\n=> CHECK ClassType::SetValues command for implementerRefTypeID," +
+            " interfaceFieldID...");
+        int expectedIntValue = 2;
+        CommandPacket setValuesCommand = new CommandPacket(
+            JDWPCommands.ClassTypeCommandSet.CommandSetID,
+            JDWPCommands.ClassTypeCommandSet.SetValuesCommand);
+        setValuesCommand.setNextValueAsClassID(implementerRefTypeID);
+        setValuesCommand.setNextValueAsInt(1);
+        setValuesCommand.setNextValueAsFieldID(interfaceFieldID);
+        setValuesCommand.setNextValueAsInt(expectedIntValue);
+        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(setValuesCommand);
+        checkReplyPacket(reply, "ClassType::SetValues command");
+
+        logWriter.println("\n=> CHECK ReferenceType::GetValues command for implementerRefTypeID," +
+            " interfaceFieldID...");
+        CommandPacket getValuesCommand = new CommandPacket(
+                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
+                JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
+        getValuesCommand.setNextValueAsReferenceTypeID(implementerRefTypeID);
+        getValuesCommand.setNextValueAsInt(1);
+        getValuesCommand.setNextValueAsFieldID(interfaceFieldID);
+        ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
+        checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");
+
+        getValuesReply.getNextValueAsInt();
+        Value fieldValue = getValuesReply.getNextValueAsValue();
+        byte fieldTag = fieldValue.getTag();
+        logWriter.println("=> Returned value tag = " + fieldTag
+            + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
+        assertTagEquals("Invalid value tag is returned,", JDWPConstants.Tag.INT_TAG, fieldTag);
+
+        int intValue = fieldValue.getIntValue();
+        logWriter.println("=> Returned value = " + intValue);
+        // here expected value = 2 (staticIntField)
+        assertEquals("Invalid int value,", expectedIntValue, intValue);
+
+        assertAllDataRead(getValuesReply);
+
+        logWriter.println("=> CHECK PASSED: Expected value is returned!");
+
+        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
+        logWriter.println("==> " + thisTestName + " for ReferenceType::GetValues command: FINISH");
+    }
+}
diff --git a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
index 5618247..44e4211 100644
--- a/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
+++ b/jdwp/src/test/java/org/apache/harmony/jpda/tests/share/AllTests.java
@@ -163,6 +163,8 @@
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues003Test.class);
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues004Test.class);
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues005Test.class);
+    suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues006Test.class);
+    suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValues007Test.class);
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.GetValuesTest.class);
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.InstancesTest.class);
     suite.addTestSuite(org.apache.harmony.jpda.tests.jdwp.ReferenceType.InterfacesTest.class);