001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012: import com.sun.jdi.ArrayType;
013: import com.sun.jdi.ReferenceType;
014:
015: /**
016: * Test cases for the implementation of providing argumebnt information even if
017: * no debugging information is present in the new java 1.6 VM
018: *
019: * @since 3.3
020: */
021: public class ConstantPoolTests extends AbstractJDITest {
022:
023: ReferenceType fClass;
024:
025: /** setup test info locally **/
026: public void localSetUp() {
027: }
028:
029: /**
030: * test to see if we can get class file version info from a 1.6 VM, and
031: * that we cannot from a pre 1.6 VM
032: */
033: public void testCanGetClassFileVersion() {
034: if (fVM.version().indexOf("1.6") > -1) {
035: assertTrue("Should have classfile version info", fVM
036: .canGetClassFileVersion());
037: } else {
038: assertTrue("Should not have classfile version info", !fVM
039: .canGetClassFileVersion());
040: }
041: }
042:
043: /**
044: * test to make sure we can get constant pool information from a 1.6 VM, and
045: * that we cannot get it from a pre 1.6 VM
046: */
047: public void testCanGetConstantPool() {
048: if (fVM.version().indexOf("1.6") > -1) {
049: assertTrue("Should have constant pool info", fVM
050: .canGetConstantPool());
051: } else {
052: assertFalse("Should not have constant pool info", fVM
053: .canGetConstantPool());
054: }
055: }
056:
057: /**
058: * test to make sure that if majorVersion is unsupported an UnsupportedOperationException is
059: * thrown.
060: */
061: public void testMajorVersionUnsupported() {
062: triggerAndWait(fVM.eventRequestManager()
063: .createClassPrepareRequest(), "refclassload", true);
064: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
065: assertNotNull("RefClass1 should not be null", fClass);
066: if (fVM.version().indexOf("1.6") > -1) {
067: try {
068: fClass.majorVersion();
069: } catch (UnsupportedOperationException uoe) {
070: assertTrue("Threw unsupported exception in 1.6 VM",
071: false);
072: }
073: } else {
074: try {
075: fClass.majorVersion();
076: assertTrue("No exception for non 1.6 VM", false);
077: } catch (UnsupportedOperationException uoe) {
078: }
079: }
080: }
081:
082: /**
083: * test to make sure that majorVersion returns 0 for an arrayType.
084: * this test does not apply to non-16 VMs
085: */
086: public void testMajorVersionArrayType() {
087: if (!fVM.canGetClassFileVersion()) {
088: return;
089: }
090: ArrayType type = getArrayType();
091: assertNotNull("type should not be null", type);
092: int ver = type.majorVersion();
093: assertTrue("major verison should be 0", ver == 0);
094: }
095:
096: /**
097: * test to make sure majorVerison works.
098: * this test does not apply to non-1.6VMs
099: */
100: public void testMajorVersion() {
101: if (!fVM.canGetClassFileVersion()) {
102: return;
103: }
104: triggerAndWait(fVM.eventRequestManager()
105: .createClassPrepareRequest(), "refclassload", true);
106: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
107: assertNotNull("RefClass1 should not be null", fClass);
108: int ver = fClass.majorVersion();
109: assertTrue("version cannot be equal to -1", ver != -1);
110: }
111:
112: /**
113: * test to make sure that if minorVersion is unsupported an UnsupportedIOperationException
114: * is thrown
115: */
116: public void testMinorVersionUnsupported() {
117: triggerAndWait(fVM.eventRequestManager()
118: .createClassPrepareRequest(), "refclassload", true);
119: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
120: assertNotNull("RefClass1 should not be null", fClass);
121: if (fVM.version().indexOf("1.6") > -1) {
122: try {
123: fClass.minorVersion();
124: } catch (UnsupportedOperationException uoe) {
125: assertTrue("Threw unsupported exception in 1.6 VM",
126: false);
127: }
128: } else {
129: try {
130: fClass.minorVersion();
131: assertTrue("No exception for non 1.6 VM", false);
132: } catch (UnsupportedOperationException uoe) {
133: }
134: }
135: }
136:
137: /**
138: * test to make sure minorVerison works.
139: * this test does not apply to non-1.6VMs
140: */
141: public void testMinorVersion() {
142: if (!fVM.canGetClassFileVersion()) {
143: return;
144: }
145: triggerAndWait(fVM.eventRequestManager()
146: .createClassPrepareRequest(), "refclassload", true);
147: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
148: assertNotNull("RefClass1 should not be null", fClass);
149: int ver = fClass.minorVersion();
150: assertTrue("version cannot be equal to -1", ver != -1);
151: }
152:
153: /**
154: * test to make sure that if constantPoolCount is unsupported an UnsupportedIOperationException
155: * is thrown
156: */
157: public void testConstantPoolCountSupported() {
158: triggerAndWait(fVM.eventRequestManager()
159: .createClassPrepareRequest(), "refclassload", true);
160: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
161: assertNotNull("RefClass1 should not be null", fClass);
162: if (fVM.version().indexOf("1.6") > -1) {
163: try {
164: fClass.constantPoolCount();
165: } catch (UnsupportedOperationException uoe) {
166: assertTrue("Threw unsupported exception in 1.6 VM",
167: false);
168: }
169: } else {
170: try {
171: fClass.constantPoolCount();
172: assertTrue("No exception for non 1.6 VM", false);
173: } catch (UnsupportedOperationException uoe) {
174: }
175: }
176: }
177:
178: /**
179: * test to ensure the constant pool count is working correctly
180: * this test does not apply to non-1.6 VMs
181: */
182: public void testConstantPoolCount() {
183: if (!fVM.canGetConstantPool()) {
184: return;
185: }
186: triggerAndWait(fVM.eventRequestManager()
187: .createClassPrepareRequest(), "refclass4load", true);
188: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass4");
189: assertNotNull("RefClass4 should not be null", fClass);
190: fClass.constantPoolCount();
191: //for now we don't care about constant pool counts, not likely to have a useful debug extension for this feature,
192: //but it is here for completeness
193: }
194:
195: /**
196: * test to make sure that if constantPool is unsupported an UnsupportedIOperationException
197: * is thrown
198: */
199: public void testConstantPoolSupported() {
200: triggerAndWait(fVM.eventRequestManager()
201: .createClassPrepareRequest(), "refclassload", true);
202: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass1");
203: assertNotNull("RefClass1 should not be null", fClass);
204: if (fVM.version().indexOf("1.6") > -1) {
205: try {
206: fClass.constantPool();
207: } catch (UnsupportedOperationException uoe) {
208: assertTrue("Threw unsupported exception in 1.6 VM",
209: false);
210: }
211: } else {
212: try {
213: fClass.constantPool();
214: assertTrue("No exception for non 1.6 VM", false);
215: } catch (UnsupportedOperationException uoe) {
216: }
217: }
218: }
219:
220: /**
221: * test to ensure the constant pool is working correctly
222: * this test does not apply to non-1.6 VMs
223: */
224: public void testConstantPool() {
225: if (!fVM.canGetConstantPool()) {
226: return;
227: }
228: triggerAndWait(fVM.eventRequestManager()
229: .createClassPrepareRequest(), "refclass4load", true);
230: fClass = getClass("org.eclipse.debug.jdi.tests.program.RefClass4");
231: assertNotNull("RefClass4 should not be null", fClass);
232: byte[] bytes = fClass.constantPool();
233: assertNotNull("byte array should not be null", bytes);
234: assertTrue("byte array should not be less than 1",
235: bytes.length > 0);
236: //for now we don't care about constant pool bytes, not likely to have a useful debug extension for this feature,
237: //but it is here for completeness
238: }
239: }
|