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
19/**
20 * @author Anatoly F. Bondarenko
21 */
22
23/**
24 * Created on 24.02.2005
25 */
26package org.apache.harmony.jpda.tests.jdwp.ReferenceType;
27
28import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
29import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
30import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
31import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
32import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
33import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
34
35
36/**
37 * JDWP Unit test for ReferenceType.SourceDebugExtension command.
38 */
39public class SourceDebugExtensionTest extends JDWPSyncTestCase {
40
41    static final int testStatusPassed = 0;
42    static final int testStatusFailed = -1;
43    static final String thisCommandName = "ReferenceType.SourceDebugExtension command";
44    static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/ReferenceType/SourceDebugExtensionDebuggee;";
45
46    protected String getDebuggeeClassName() {
47        return "org.apache.harmony.jpda.tests.jdwp.ReferenceType.SourceDebugExtensionDebuggee";
48    }
49
50    /**
51     * This testcase exercises ReferenceType.SourceDebugExtension command.
52     * <BR>The test starts SourceDebugExtensionDebuggee class, requests referenceTypeId
53     * for this class by VirtualMachine.ClassesBySignature command, then
54     * performs ReferenceType.SourceDebugExtension command and checks that
55     * no any unexpected ERROR is returned.
56     */
57    public void testSourceDebugExtension001() {
58        String thisTestName = "testSourceDebugExtension001";
59
60        //check capability, relevant for this test
61        logWriter.println("=> Check capability: canGetSourceDebugExtension");
62        if (!debuggeeWrapper.vmMirror.canGetSourceDebugExtension()) {
63            logWriter.println("##WARNING: this VM doesn't possess capability: canGetSourceDebugExtension");
64            return;
65        }
66
67        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START...");
68        synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
69
70        long refTypeID = getClassIDBySignature(debuggeeSignature);
71
72        logWriter.println("=> Debuggee class = " + getDebuggeeClassName());
73        logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID);
74        logWriter.println("=> CHECK: send " + thisCommandName + " and check reply...");
75
76        CommandPacket checkedCommand = new CommandPacket(
77                JDWPCommands.ReferenceTypeCommandSet.CommandSetID,
78                JDWPCommands.ReferenceTypeCommandSet.SourceDebugExtensionCommand);
79        checkedCommand.setNextValueAsReferenceTypeID(refTypeID);
80
81        ReplyPacket checkedReply = debuggeeWrapper.vmMirror.performCommand(checkedCommand);
82        checkedCommand = null;
83
84        short errorCode = checkedReply.getErrorCode();
85
86        switch ( errorCode ) {
87            case JDWPConstants.Error.NONE:
88                logWriter.println("=> No any ERROR is returned");
89                String SourceDebugExtension = checkedReply.getNextValueAsString();
90                logWriter.println("=> Returned SourceDebugExtension = " + SourceDebugExtension);
91                break;
92            case JDWPConstants.Error.NOT_IMPLEMENTED:
93                logWriter.println("=> ERROR is returned: "+ errorCode
94                    + "(" + JDWPConstants.Error.getName(errorCode) + ")");
95                logWriter.println("=> It is possible ERROR");
96                break;
97            case JDWPConstants.Error.ABSENT_INFORMATION:
98                logWriter.println("=> ERROR is returned: "+ errorCode
99                        + "(" + JDWPConstants.Error.getName(errorCode) + ")");
100                    logWriter.println("=> It is possible ERROR");
101                break;
102            default:
103                logWriter.println("\n## FAILURE: " + thisCommandName + " returns unexpected ERROR = "
104                    + errorCode + "(" + JDWPConstants.Error.getName(errorCode) + ")");
105                fail(thisCommandName + " returns unexpected ERROR = "
106                    + errorCode + "(" + JDWPConstants.Error.getName(errorCode) + ")");
107        }
108
109        assertAllDataRead(checkedReply);
110
111        logWriter.println("=> CHECK PASSED: No any unexpected ERROR is returned");
112
113        synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
114        logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH");
115    }
116}
117