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 Vitaly A. Provodin
21  */
22 
23 /**
24  * Created on 10.02.2005
25  */
26 package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
27 
28 import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
29 import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
30 import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
31 import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
32 import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
33 
34 
35 /**
36  * JDWP Unit test for VirtualMachine.CapabilitiesNew command.
37  */
38 public class CapabilitiesNewTest extends JDWPSyncTestCase {
39 
40     static Object [][] capabilitiesFlags = {
41             {"canWatchFieldModification",        "true"},
42             {"canWatchFieldAccess",              "true"},
43             {"canGetBytecodes",                  "true"},
44             {"canGetSyntheticAttribute",         "true"},
45             {"canGetOwnedMonitorInfo",           "true"},
46             {"canGetCurrentContendedMonitor",    "true"},
47             {"canGetMonitorInfo",                "true"},
48             {"canRedefineClasses",               null},
49             {"canAddMethod",                     null},
50             {"canUnrestrictedlyRedefineClasses", null},
51             {"canPopFrames",                     null},
52             {"canUseInstanceFilters",            "true"},
53             {"canGetSourceDebugExtension",       null},
54             {"canRequestVMDeathEvent",           null},
55             {"canSetDefaultStratum",             null},
56             {"canGetInstanceInfo",               "true"},
57             {"canRequestMonitorEvents",          null},
58             {"canGetMonitorFrameInfo",           "true"},
59             {"canUseSourceNameFilters",          null},
60             {"canGetConstantPool",               null},
61             {"canForceEarlyReturn",              null},
62             {"reserved22", null},
63             {"reserved23", null},
64             {"reserved24", null},
65             {"reserved25", null},
66             {"reserved26", null},
67             {"reserved27", null},
68             {"reserved28", null},
69             {"reserved29", null},
70             {"reserved30", null},
71             {"reserved31", null},
72             {"reserved32", null}
73     };
74 
getDebuggeeClassName()75     protected String getDebuggeeClassName() {
76         return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld";
77     }
78 
79     /**
80      * This testcase exercises VirtualMachine.CapabilitiesNew command.
81      * <BR>At first the test starts HelloWorld debuggee.
82      * <BR> Then the test performs VirtualMachine.CapabilitiesNew command and checks that:
83      * all returned capabilities' values are expected values and that
84      * there are no extra data in the reply packet;
85      */
testCapabilitiesNew001()86     public void testCapabilitiesNew001() {
87         synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
88 
89         CommandPacket packet = new CommandPacket(
90                 JDWPCommands.VirtualMachineCommandSet.CommandSetID,
91                 JDWPCommands.VirtualMachineCommandSet.CapabilitiesNewCommand);
92         logWriter.println("\trequest capabilities");
93         ReplyPacket reply = debuggeeWrapper.vmMirror.performCommand(packet);
94         checkReplyPacket(reply, "VirtualMachine::CapabilitiesNew command");
95 
96         boolean flag;
97         boolean testFailed = false;
98         for (int i = 0; i < 32; i++) {
99             flag = reply.getNextValueAsBoolean();
100             logWriter.println("\tReceived " + capabilitiesFlags[i][0] +  " = "
101                     + flag);
102             if ( (capabilitiesFlags[i][1] != null) !=  flag ) {
103                 testFailed = true;
104                 logWriter.println("\t   ## FAILURE: Expected " + capabilitiesFlags[i][0] +
105                         " = " + (capabilitiesFlags[i][1] != null));
106             } else {
107                 logWriter.println("\t   OK - it is expected value!");
108             }
109         }
110         if ( testFailed ) {
111             printErrorAndFail("Unexpected received capabilities values found out");
112         } else {
113             logWriter.println("testCapabilitiesNew001 - OK!");
114         }
115         assertAllDataRead(reply);
116         synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
117     }
118 }
119