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 17.02.2005 25 */ 26 package org.apache.harmony.jpda.tests.jdwp.ReferenceType; 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 ReferenceType.Modifiers command. 37 */ 38 public class ModifiersTest extends JDWPSyncTestCase { 39 40 static final int testStatusPassed = 0; 41 static final int testStatusFailed = -1; 42 static final String thisCommandName = "ReferenceType.Modifiers command"; 43 static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorld;"; 44 static final String debuggeeInterfaceSignature = "Lorg/apache/harmony/jpda/tests/jdwp/share/debuggee/HelloWorldInterface;"; 45 static final String debuggeeInterfaceClassName = "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorldInterface"; 46 47 @Override getDebuggeeClassName()48 protected String getDebuggeeClassName() { 49 return "org.apache.harmony.jpda.tests.jdwp.share.debuggee.HelloWorld"; 50 } 51 52 /** 53 * This testcase exercises ReferenceType.Modifiers command. 54 * <BR>The test starts HelloWorld debuggee, requests referenceTypeId 55 * for it by VirtualMachine.ClassesBySignature command, then 56 * performs ReferenceType.Modifiers command and checks that returned 57 * Modifiers contain expected flags: ACC_PUBLIC 58 * but do NOT contain flags: ACC_FINAL, ACC_INTERFACE, ACC_ABSTRACT 59 * 60 * NB ACC_SUPER is not a valid modifier in ART and is not meaningful in other runtimes. 61 * Therefore we will simply ignore it in this test. 62 */ testModifiers001()63 public void testModifiers001() { 64 String thisTestName = "testModifiers001"; 65 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 66 String failMessage = ""; 67 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 68 69 long refTypeID = getClassIDBySignature(debuggeeSignature); 70 71 logWriter.println("=> Debuggee class = " + getDebuggeeClassName()); 72 logWriter.println("=> referenceTypeID for Debuggee class = " + refTypeID); 73 logWriter.println("=> CHECK1: send " + thisCommandName + " and check reply..."); 74 75 CommandPacket modifiersCommand = new CommandPacket( 76 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 77 JDWPCommands.ReferenceTypeCommandSet.ModifiersCommand); 78 modifiersCommand.setNextValueAsReferenceTypeID(refTypeID); 79 80 ReplyPacket modifiersReply = debuggeeWrapper.vmMirror.performCommand(modifiersCommand); 81 modifiersCommand = null; 82 checkReplyPacket(modifiersReply, thisCommandName); 83 84 int returnedModifiers = modifiersReply.getNextValueAsInt(); 85 /* 86 * The value of the access_flags item is a mask of modifiers used with class and 87 * interface declarations. The access_flags modifiers are: 88 * Flag Name Value Meaning Used By 89 * ACC_PUBLIC 0x0001 Is public; may be accessed from outside its package. Class, interface 90 * ACC_FINAL 0x0010 Is final; no subclasses allowed. Class 91 * ACC_SUPER 0x0020 Treat superclass methods specially in invokespecial. Class, interface 92 * ACC_INTERFACE 0x0200 Is an interface. Interface 93 * ACC_ABSTRACT 0x0400 Is abstract; may not be instantiated. Class, interface 94 */ 95 logWriter.println("=> Returned modifiers = 0x" + Integer.toHexString(returnedModifiers)); 96 97 int publicFlag = 0x0001; // expected 98 int finalFlag = 0x0010; // unexpected 99 // int superFlag = 0x0020; // (do not care) 100 int interfaceFlag = 0x0200; // unexpected 101 int abstractFlag = 0x0400; // unexpected 102 103 if ( (returnedModifiers & publicFlag) == 0 ) { 104 logWriter.println 105 ("## CHECK1: FAILURE: Returned modifiers do NOT contain expected ACC_PUBLIC flag(0x0001)"); 106 failMessage = failMessage + 107 "Returned modifiers do NOT contain expected ACC_PUBLIC flag(0x0001);\n"; 108 } 109 if ( (returnedModifiers & finalFlag) != 0 ) { 110 logWriter.println 111 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_FINAL flag(0x0010)"); 112 failMessage = failMessage + 113 "Returned modifiers contain unexpected ACC_FINAL flag(0x0010);\n"; 114 } 115 if ( (returnedModifiers & interfaceFlag) != 0 ) { 116 logWriter.println 117 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_INTERFACE flag(0x0200)"); 118 failMessage = failMessage + 119 "Returned modifiers contain unexpected ACC_INTERFACE flag(0x0200);\n"; 120 } 121 if ( (returnedModifiers & abstractFlag) != 0 ) { 122 logWriter.println 123 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_ABSTRACT flag(0x0400)"); 124 failMessage = failMessage + 125 "Returned modifiers contain unexpected ACC_ABSTRACT flag(0x0400);\n"; 126 } 127 128 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 129 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 130 131 if (failMessage.length() > 0) { 132 fail(failMessage); 133 } else { 134 logWriter.println 135 ("=> CHECK1: PASSED: expected modifiers are returned: ACC_PUBLIC flag(0x0001), ACC_SUPER flag(0x0020)"); 136 } 137 138 assertAllDataRead(modifiersReply); 139 } 140 141 /** 142 * This testcase exercises ReferenceType.Modifiers command. 143 * <BR>The test starts HelloWorld debuggee, requests referenceTypeId 144 * for an interface HelloWorldInterface by VirtualMachine.ClassesBySignature command, 145 * then performs ReferenceType.Modifiers command and checks that returned 146 * Modifiers contain expected flags: ACC_ABSTRACT, ACC_INTERFACE; 147 * but do NOT contain flags: ACC_PUBLIC, ACC_FINAL, ACC_SUPER, ACC_ABSTRACT 148 */ testModifiers002()149 public void testModifiers002() { 150 String thisTestName = "testModifiers002"; 151 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": START..."); 152 String failMessage = ""; 153 synchronizer.receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY); 154 155 long refTypeID = getClassIDBySignature(debuggeeInterfaceSignature); 156 157 logWriter.println("=> Debuggee Interface class = " + debuggeeInterfaceClassName); 158 logWriter.println("=> referenceTypeID for Debuggee interface = " + refTypeID); 159 logWriter.println("=> CHECK1: send " + thisCommandName + " and check reply..."); 160 161 CommandPacket modifiersCommand = new CommandPacket( 162 JDWPCommands.ReferenceTypeCommandSet.CommandSetID, 163 JDWPCommands.ReferenceTypeCommandSet.ModifiersCommand); 164 modifiersCommand.setNextValueAsReferenceTypeID(refTypeID); 165 166 ReplyPacket modifiersReply = debuggeeWrapper.vmMirror.performCommand(modifiersCommand); 167 modifiersCommand = null; 168 checkReplyPacket(modifiersReply, thisCommandName); 169 170 int returnedModifiers = modifiersReply.getNextValueAsInt(); 171 /* 172 * The value of the access_flags item is a mask of modifiers used with class and 173 * interface declarations. The access_flags modifiers are: 174 * Flag Name Value Meaning Used By 175 * ACC_PUBLIC 0x0001 Is public; may be accessed from outside its package. Class, interface 176 * ACC_FINAL 0x0010 Is final; no subclasses allowed. Class 177 * ACC_SUPER 0x0020 Treat superclass methods specially in invokespecial. Class, interface 178 * ACC_INTERFACE 0x0200 Is an interface. Interface 179 * ACC_ABSTRACT 0x0400 Is abstract; may not be instantiated. Class, interface 180 */ 181 logWriter.println("=> Returned modifiers = 0x" + Integer.toHexString(returnedModifiers)); 182 183 int publicFlag = 0x0001; // expected 184 int finalFlag = 0x0010; // unexpected 185 int superFlag = 0x0020; // unexpected 186 int interfaceFlag = 0x0200; // expected 187 int abstractFlag = 0x0400; // unexpected 188 189 if ( (returnedModifiers & publicFlag) != 0 ) { 190 logWriter.println 191 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_PUBLIC flag(0x0001)"); 192 failMessage = failMessage + 193 "Returned modifiers contain unexpected ACC_PUBLIC flag(0x0001);\n"; 194 } 195 if ( (returnedModifiers & superFlag) != 0 ) { 196 logWriter.println 197 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_SUPER flag(0x0020)"); 198 failMessage = failMessage + 199 "Returned modifiers contain unexpected ACC_SUPER flag(0x0020);\n"; 200 } 201 if ( (returnedModifiers & finalFlag) != 0 ) { 202 logWriter.println 203 ("## CHECK1: FAILURE: Returned modifiers contain unexpected ACC_FINAL flag(0x0010)"); 204 failMessage = failMessage + 205 "Returned modifiers contain unexpected ACC_FINAL flag(0x0010);\n"; 206 } 207 if ( (returnedModifiers & interfaceFlag) == 0 ) { 208 logWriter.println 209 ("## CHECK1: FAILURE: Returned modifiers do not contain expected ACC_INTERFACE flag(0x0200)"); 210 failMessage = failMessage + 211 "Returned modifiers do not contain expected ACC_INTERFACE flag(0x0200);\n"; 212 } 213 if ( (returnedModifiers & abstractFlag) == 0 ) { 214 logWriter.println 215 ("## CHECK1: FAILURE: Returned modifiers do not contain expected ACC_ABSTRACT flag(0x0400)"); 216 failMessage = failMessage + 217 "Returned modifiers do not contain expected ACC_ABSTRACT flag(0x0400);\n"; 218 } 219 220 synchronizer.sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE); 221 logWriter.println("==> " + thisTestName + " for " + thisCommandName + ": FINISH"); 222 223 if (failMessage.length() > 0) { 224 fail(failMessage); 225 } else { 226 logWriter.println 227 ("=> CHECK1: PASSED: expected modifiers are returned: ACC_INTERFACE flag(0x0200), ACC_ABSTRACT flag(0x0400)"); 228 } 229 230 assertAllDataRead(modifiersReply); 231 } 232 } 233