1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *
15 *  See the License for the specific language governing permissions and
16 *  limitations under the License.
17 */
18
19package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
20
21import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
22import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
23import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
24import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
25import org.apache.harmony.jpda.tests.framework.jdwp.Value;
26import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
27import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
28
29
30/**
31 * JDWP Unit test for ReferenceType.GetValues command for static field of interface class.
32 */
33public class GetValues007Test extends JDWPSyncTestCase {
34
35    @Override
36    protected String getDebuggeeClassName() {
37        return GetValues007Debuggee.class.getName();
38    }
39
40    /**
41     * This tests the ReferenceType.GetValues command on the static field of an interface.
42     * <BR>The test starts GetValues007Debuggee and checks that the ReferenceType.GetValues
43     * command runs correctly for a static field declared in an interface.
44     * <BR>Test checks that expected value of this field is returned.
45     */
46    public void testGetValues007() {
47        String thisTestName = "testGetValues007";
48        logWriter.println("==> " + thisTestName +
49            " for ReferenceType.GetValues command: START...");
50        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
51
52        logWriter.println("\n=> Get debuggeeRefTypeID for debuggee class = "
53            + getDebuggeeClassName() + "...");
54        long debuggeeRefTypeID = getClassIDBySignature(getDebuggeeClassSignature());
55        logWriter.println("=> debuggeeRefTypeID = " + debuggeeRefTypeID);
56
57        logWriter.println(
58            "\n=> Get implementerRefTypeID for implementer = GetValues007Implementer...");
59        long implementerRefTypeID =
60            getClassIDBySignature(getClassSignature(GetValues007Interface.class));
61        logWriter.println("=> implementerRefTypeID = " + implementerRefTypeID);
62
63        logWriter.println("\n=> Get interfaceFieldID for field of interface class...");
64        String interfaceFieldName = "interfaceStaticIntVar";
65        long interfaceFieldID = checkField(implementerRefTypeID, interfaceFieldName);
66        logWriter.println("=> interfaceFieldID = " + interfaceFieldID);
67
68        logWriter.println("\n=> CHECK ClassType::SetValues command for implementerRefTypeID," +
69            " interfaceFieldID...");
70        int expectedIntValue = 2;
71        CommandPacket setValuesCommand = new CommandPacket(
72            JDWPCommands.ClassTypeCommandSet.CommandSetID,
73            JDWPCommands.ClassTypeCommandSet.SetValuesCommand);
74        setValuesCommand.setNextValueAsClassID(implementerRefTypeID);
75        setValuesCommand.setNextValueAsInt(1);
76        setValuesCommand.setNextValueAsFieldID(interfaceFieldID);
77        setValuesCommand.setNextValueAsInt(expectedIntValue);
78        ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(setValuesCommand);
79        checkReplyPacket(reply, "ClassType::SetValues command");
80
81        logWriter.println("\n=> CHECK ReferenceType::GetValues command for implementerRefTypeID," +
82            " interfaceFieldID...");
83        CommandPacket getValuesCommand = new CommandPacket(
84                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
85                JDWPCommands.ReferenceTypeCommandSet.GetValuesCommand);
86        getValuesCommand.setNextValueAsReferenceTypeID(implementerRefTypeID);
87        getValuesCommand.setNextValueAsInt(1);
88        getValuesCommand.setNextValueAsFieldID(interfaceFieldID);
89        ReplyPacket getValuesReply = debuggeeWrapper.vmMirror.performCommand(getValuesCommand);
90        checkReplyPacket(getValuesReply, "ReferenceType::GetValues command");
91
92        getValuesReply.getNextValueAsInt();
93        Value fieldValue = getValuesReply.getNextValueAsValue();
94        byte fieldTag = fieldValue.getTag();
95        logWriter.println("=> Returned value tag = " + fieldTag
96            + "(" + JDWPConstants.Tag.getName(fieldTag) + ")");
97        assertTagEquals("Invalid value tag is returned,", JDWPConstants.Tag.INT_TAG, fieldTag);
98
99        int intValue = fieldValue.getIntValue();
100        logWriter.println("=> Returned value = " + intValue);
101        // here expected value = 2 (staticIntField)
102        assertEquals("Invalid int value,", expectedIntValue, intValue);
103
104        assertAllDataRead(getValuesReply);
105
106        logWriter.println("=> CHECK PASSED: Expected value is returned!");
107
108        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
109        logWriter.println("==> " + thisTestName + " for ReferenceType::GetValues command: FINISH");
110    }
111}
112