001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Anton V. Karnachuk
021: * @version $Revision: 1.5 $
022: */
023:
024: /**
025: * Created on 09.02.2005
026: */package org.apache.harmony.jpda.tests.jdwp.ClassType;
027:
028: import java.io.UnsupportedEncodingException;
029:
030: import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
031: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
032: import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
033: import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
034: import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036: /**
037: * JDWP unit test for ClassType.SuperClass command.
038: * Contains three testcases: testSuperClass001, testSuperClass002, testSuperClass003.
039: */
040: public class SuperClassTest extends JDWPClassTypeTestCase {
041:
042: /**
043: * Starts this test by junit.textui.TestRunner.run() method.
044: */
045: public static void main(String[] args) {
046: junit.textui.TestRunner.run(SuperClassTest.class);
047: }
048:
049: private ReplyPacket jdwpGetSuperClassReply(long classID,
050: int errorExpected) {
051: CommandPacket packet = new CommandPacket(
052: JDWPCommands.ClassTypeCommandSet.CommandSetID,
053: JDWPCommands.ClassTypeCommandSet.SuperclassCommand);
054: packet.setNextValueAsClassID(classID);
055: ReplyPacket reply = debuggeeWrapper.vmMirror
056: .performCommand(packet);
057: checkReplyPacket(reply, "ClassType.Superclass command",
058: errorExpected);
059: return reply;
060: }
061:
062: private void asserSuperClassReplyIsValid(ReplyPacket reply,
063: String expectedSignature) {
064: assertTrue(reply.getErrorCode() == JDWPConstants.Error.NONE);
065: long super ClassID = reply.getNextValueAsClassID();
066: logWriter.println("superClassID=" + super ClassID);
067: if (super ClassID == 0) {
068: // for superclass of Object expectedSignature is null
069: assertNull(
070: "ClassType::Superclass command returned invalid expectedSignature that must be null",
071: expectedSignature);
072: } else {
073: String signature = getClassSignature(super ClassID);
074: logWriter.println("Signature: " + signature);
075: assertString(
076: "ClassType::Superclass command returned invalid signature,",
077: expectedSignature, signature);
078: }
079: }
080:
081: /**
082: * This testcase exercises ClassType.Superclass command.
083: * <BR>Starts <A HREF="ClassTypeDebuggee.html">ClassTypeDebuggee</A>.
084: * <BR>Then does the following checks:
085: * <BR> - superclass for java.lang.String is java.lang.Object;
086: * <BR> - superclass for array of Objects is java.lang.Object;
087: * <BR> - superclass for primitive array is java.lang.Object;
088: * <BR> - superclass for <A HREF="ClassTypeDebuggee.html">ClassTypeDebuggee</A>
089: * class is <A HREF="../../share/SyncDebuggee.html">SyncDebuggee</A> class.;
090: */
091: public void testSuperClass001() throws UnsupportedEncodingException {
092: logWriter.println("testSuperClassTest001 started");
093: synchronizer
094: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
095:
096: // check that superclass for java.lang.String is java.lang.Object
097: {
098: // test with String[] class
099: long classID = getClassIDBySignature("Ljava/lang/String;");
100:
101: ReplyPacket reply = jdwpGetSuperClassReply(classID,
102: JDWPConstants.Error.NONE);
103: // complare returned signature with superclass signature
104: asserSuperClassReplyIsValid(reply, "Ljava/lang/Object;");
105: }
106:
107: // check that superclass for array is java.lang.Object
108: {
109: // test with String[] class
110: long classID = getClassIDBySignature("[Ljava/lang/String;");
111:
112: ReplyPacket reply = jdwpGetSuperClassReply(classID,
113: JDWPConstants.Error.NONE);
114: // complare returned signature with superclass signature
115: asserSuperClassReplyIsValid(reply, "Ljava/lang/Object;");
116: }
117:
118: // check that superclass for primitive array is java.lang.Object
119: {
120: // test with int[] class
121: long classID = getClassIDBySignature("[I");
122:
123: ReplyPacket reply = jdwpGetSuperClassReply(classID,
124: JDWPConstants.Error.NONE);
125: // complare returned signature with superclass signature
126: asserSuperClassReplyIsValid(reply, "Ljava/lang/Object;");
127: }
128:
129: // check that superclass for Debuggee is SyncDebuggee
130: {
131: long classID = getClassIDBySignature(getDebuggeeSignature());
132:
133: ReplyPacket reply = jdwpGetSuperClassReply(classID,
134: JDWPConstants.Error.NONE);
135: // complare returned signature with superclass signature
136: asserSuperClassReplyIsValid(reply,
137: "Lorg/apache/harmony/jpda/tests/share/SyncDebuggee;");
138: }
139:
140: // check that there is no superclass for java.lang.Object
141: {
142: // test with java.lang.Object class
143: long classID = getClassIDBySignature("Ljava/lang/Object;");
144:
145: ReplyPacket reply = jdwpGetSuperClassReply(classID,
146: JDWPConstants.Error.NONE);
147: // complare returned signature with superclass signature
148: // (expects null for this case)
149: asserSuperClassReplyIsValid(reply, null);
150: }
151:
152: synchronizer
153: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
154: }
155:
156: /**
157: * This testcase exercises ClassType.Superclass command.
158: * <BR>Starts <A HREF="ClassTypeDebuggee.html">ClassTypeDebuggee</A>.
159: * <BR>Then does the following checks:
160: * <BR> - there is no superclass for interface;
161: * <BR> - INVALID_OBJECT is returned if classID is non-existent;
162: * <BR> - INVALID_OBJECT is returned if instead of classID FieldID is passed;
163: */
164: public void testSuperClass002() throws UnsupportedEncodingException {
165: logWriter.println("testSuperClassTest002 started");
166: synchronizer
167: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
168:
169: // check that there is no superclass for interface objects
170: {
171: long interfaceID = getClassIDBySignature("Ljava/lang/Cloneable;");
172:
173: ReplyPacket reply = jdwpGetSuperClassReply(interfaceID,
174: JDWPConstants.Error.NONE);
175: // compare returned signature with superclass signature
176: // (null for interfaces)
177: asserSuperClassReplyIsValid(reply, null);
178: }
179:
180: // check that INVALID_OBJECT returns if classID is non-existent
181: {
182: jdwpGetSuperClassReply(10000,
183: JDWPConstants.Error.INVALID_OBJECT);
184: }
185:
186: // check that reply error code is INVALID_OBJECT for a FieldID Out Data
187: {
188: long classID = getClassIDBySignature(getDebuggeeSignature());
189:
190: FieldInfo[] fields = jdwpGetFields(classID);
191: // assert stringID is not null
192: assertTrue("Invalid fields.length: 0", fields.length > 0);
193: // test with the first field
194:
195: jdwpGetSuperClassReply(fields[0].getFieldID(),
196: JDWPConstants.Error.INVALID_OBJECT);
197: }
198:
199: synchronizer
200: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
201: }
202:
203: /**
204: * This testcase exercises ClassType.Superclass command.
205: * <BR>Starts <A HREF="ClassTypeDebuggee.html">ClassTypeDebuggee</A>.
206: * <BR>Then does the following check:
207: * <BR> - INVALID_CLASS is returned if instead of classID ObjectID is passed;
208: */
209: public void testSuperClass003() throws UnsupportedEncodingException {
210: logWriter.println("testSuperClassTest003 started");
211: synchronizer
212: .receiveMessage(JPDADebuggeeSynchronizer.SGNL_READY);
213:
214: // check that reply error code is INVALID_CLASS for a StringID Out Data
215: {
216: long stringID = createString("Some test string");
217: // assert stringID is not null
218: assertFalse("Invalid stringID: 0", stringID == 0);
219: jdwpGetSuperClassReply(stringID,
220: JDWPConstants.Error.INVALID_CLASS);
221: }
222:
223: synchronizer
224: .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
225: }
226: }
|