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