You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by cc...@apache.org on 2009/03/16 16:42:41 UTC
svn commit: r754945 [7/8] - in
/incubator/kato/trunk/import/org.apache.kato.tck.tests: ./ .settings/ src/
src/com/ src/com/ibm/ src/com/ibm/dtfj/ src/com/ibm/dtfj/tck/
src/com/ibm/dtfj/tck/tests/ src/com/ibm/dtfj/tck/tests/javaruntime/
src/com/ibm/dtfj...
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaClassTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaClassTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaClassTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaClassTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,531 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.ImagePointer;
+import com.ibm.dtfj.image.MemoryAccessException;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaField;
+import com.ibm.dtfj.java.JavaMethod;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaReference;
+import com.ibm.dtfj.tests.scenarios.ArrayletTest;
+
+public class JavaClassTest extends AbstractDTFJTestcase
+{
+
+ public class Super {
+ int superField1 = 3;
+ String superField2 = "Ciao";
+ }
+
+ public class Sub extends Super {
+ long subField1 = 100;
+ char[] subField2 = new char[]{'c','c'};
+
+ public Sub() {
+ System.out.println("Sub instantiated");
+ }
+ }
+
+ private JavaClass _testClass;
+ private JavaObject _arrayInstance; //array classes aren't loaded like normal classes and only come into existence when an array object is created
+ private static Sub _subClassObject = null;
+ private static ArrayletTest _testDeadlock = null;
+
+ protected void setUp() throws Exception
+ {
+ try {
+ _testClass = defaultJavaClass();
+ _arrayInstance = defaultJavaObject(true);
+ super.setUp();
+ } catch (TestNotImplementedException e) {
+ throw e;
+ }
+ }
+
+ public void configureDeclareFieldsNotInherited() {
+ _subClassObject = new Sub();
+ }
+
+ public void configureArraylets() {
+ _testDeadlock = new ArrayletTest();
+ }
+
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getObject()'
+ */
+ public void testGetObject()
+ {
+ try {
+ JavaObject object = _testClass.getObject();
+ assertNotNull(object);
+ /* validate that the object is an instance of java/lang/Class */
+ JavaClass javaLangClass = object.getJavaClass();
+ assertNotNull(javaLangClass);
+ assertEquals(javaLangClass.getName(), "java/lang/Class");
+
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getClassLoader()'
+ */
+ public void testGetClassLoader()
+ {
+ try {
+ JavaClassLoader loader = _testClass.getClassLoader();
+ assertNotNull(loader);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getName()'
+ */
+ public void testGetName()
+ {
+ try {
+ String name = _testClass.getName();
+ assertNotNull(name);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getSuperclass()'
+ */
+ public void testGetSuperclass()
+ {
+ try {
+ JavaClass superClass = _testClass.getSuperclass();
+ assertNotNull(superClass);
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getInterfaces()'
+ */
+ public void testGetInterfaces()
+ {
+ try {
+ Iterator iter = _testClass.getInterfaces();
+ assertNotNull(iter);
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getModifiers()'
+ */
+ public void testGetModifiers()
+ {
+ try {
+ _testClass.getModifiers();
+ //fill in any checks that could be used for validity here
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaClass.isArray()'
+ */
+ public void testIsArray()
+ {
+ //any result is safe so long as it doesn't throw something unexpected
+ try {
+ _testClass.isArray();
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getComponentType()'
+ *
+ * Ensures that we get a non-null component type which has a non-null, non-empty length
+ */
+ public void testGetComponentType()
+ {
+ JavaClass arrayClass = null;
+ JavaClass component = null;
+ try {
+ arrayClass = _arrayInstance.getJavaClass();
+ component = arrayClass.getComponentType();
+ } catch (CorruptDataException e) {
+ //allowed by the spec
+ }
+ assertNotNull(component);
+ String name=null;
+ try {
+ name = component.getName();
+ } catch (CorruptDataException e) {
+ }
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getDeclaredFields()'
+ *
+ * Ensures that we get a non-null iterator and anything in the iterator is an instance
+ * of JavaField or CorruptData
+ */
+ public void testGetDeclaredFields()
+ {
+ try {
+ Iterator fields = _testClass.getDeclaredFields();
+ assertNotNull(fields);
+ while (fields.hasNext()) {
+ Object element = fields.next();
+ assertTrue((element instanceof JavaField) || (element instanceof CorruptData));
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getDeclaredMethods()'
+ *
+ * Ensures that the declared methods iterator is non-null and any methods in it
+ * are either JavaMethod or CorruptData
+ */
+ public void testGetDeclaredMethods()
+ {
+ try {
+ Iterator methods = _testClass.getDeclaredMethods();
+ assertNotNull(methods);
+ while (methods.hasNext()) {
+ Object instance = methods.next();
+ assertTrue((instance instanceof JavaMethod) || (instance instanceof CorruptData));
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getConstantPoolReferences()'
+ *
+ * Ensures that the test class returns a non-null iterator and that any elements
+ * in it are either JavaObject or CorruptData
+ */
+ public void testGetConstantPoolReferences()
+ {
+ try {
+ Iterator references = _testClass.getConstantPoolReferences();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaObject) || (instance instanceof CorruptData));
+ if (instance instanceof JavaObject) {
+ // ensure that these are valid objects by reading the class
+ JavaObject object = (JavaObject)instance;
+ JavaClass clazz = object.getJavaClass();
+ assertNotNull(clazz);
+ }
+ }
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getID()'
+ *
+ * Ensures that the pointer is non-null and that the underlying address is non-zero
+ */
+ public void testGetID()
+ {
+ try {
+ ImagePointer id = _testClass.getID();
+ assertNotNull(id);
+ assertTrue(0 != id.getAddress());
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.getReferences()'
+ *
+ * Ensures that the test class returns a non-null iterator, that any elements in it are
+ * either JavaReference or CorruptData, and that any JavaReference objects have a non-null
+ * description.
+ */
+ public void testGetReferences()
+ {
+ try {
+ Iterator references = _testClass.getReferences();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
+ if (instance instanceof JavaReference) {
+ // sniff these objects by getting the description
+ JavaReference object = (JavaReference)instance;
+ String description = object.getDescription();
+ assertNotNull(description);
+ }
+ }
+ } catch (Exception e) {
+ // if we caught anything else, this is a failure
+ fail();
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_testClass.equals(_testClass));
+ } catch (Throwable t) {
+ //if we fail internally, we want to flag that as a test failure, not just an error
+ t.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _testClass.hashCode());
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ public void testDeclaredFieldsNotInherited()
+ {
+ try {
+ //search all the loaders for a class which we know we had in the address space
+ String candidateClass = this.getClass().getName()+"$Sub";
+ candidateClass = candidateClass.replace('.', '/');
+ JavaClass subclass = _findClassForName(candidateClass);
+ if (null == subclass) {
+ //not finding this testing class makes this test useless
+ //note that this can also happen if we are working with a corrupt core file
+ throw new TestNotImplementedException();
+ }
+ JavaClass superclass = null;
+ try {
+ superclass = subclass.getSuperclass();
+ } catch (CorruptDataException e) {
+ //even though this would be valid, it isn't helpful for our case
+ throw new TestNotImplementedException();
+ }
+ if (null == superclass) {
+ //not finding this testing class makes this test useless
+ throw new TestNotImplementedException();
+ }
+ //now make sure that none of the fields in subclass are in superclass
+ Iterator subfields = subclass.getDeclaredFields();
+ while (subfields.hasNext()) {
+ Object subtest = subfields.next();
+ Iterator superfields = superclass.getDeclaredFields();
+
+ while (superfields.hasNext()) {
+ Object supertest = superfields.next();
+ assertFalse(supertest.equals(subtest));
+ }
+ }
+ } catch (TestNotImplementedException t) {
+ //we wanted this exception to break the test case with error instead of failure so re-throw
+ throw t;
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ }
+
+ private JavaClass _findClassForName(String candidateClass)
+ {
+ Iterator allLoaders = defaultJavaRuntime().getJavaClassLoaders();
+ JavaClass subclass = null;
+ while (allLoaders.hasNext() && (null == subclass)) {
+ JavaClassLoader loader = (JavaClassLoader) allLoaders.next();
+ Iterator classes = loader.getDefinedClasses();
+ while (classes.hasNext() && (null == subclass)) {
+ JavaClass oneClass = (JavaClass) classes.next();
+ try {
+ if (oneClass.getName().equals(candidateClass)) {
+ subclass = oneClass;
+ break;
+ }
+ } catch (CorruptDataException e) {
+ //even though this would be valid, it isn't helpful for our case
+ throw new TestNotImplementedException();
+ }
+ }
+ }
+ return subclass;
+ }
+
+ /**
+ * This test should eventually be moved out to a stand-alone high-level test since it is looking for a specific
+ * field to verify that arraycopy and arraylets (in the RTJ case) work properly.
+ */
+ public void testArraylets()
+ {
+ String staticSizeName = "DTFJ_ARRAYLET_LENGTH";
+ String staticName = "DTFJ_ARRAYLET_TEST_INSTANCE";
+ JavaClass candidateClass = _findClassForName("com/ibm/dtfj/tests/scenarios/ArrayletTest");
+
+ if (null != candidateClass) {
+ int size = 0;
+ JavaObject container = null;
+ Iterator fields = candidateClass.getDeclaredFields();
+
+ try {
+ while (fields.hasNext()) {
+ JavaField field = (JavaField) fields.next();
+ String fieldName = field.getName();
+
+ if (fieldName.equals(staticSizeName)) {
+ size = field.getInt(null);
+ } else if (fieldName.equals(staticName)) {
+ container = (JavaObject) field.get(null);
+ }
+ }
+ //now ensure that we actually have something to test with
+ if ((0 != size) && (null != container)) {
+ //now, pull apart the fields of the container
+ JavaClass containerClass = container.getJavaClass();
+ Iterator theseFields = containerClass.getDeclaredFields();
+ while (theseFields.hasNext()) {
+ JavaField oneField = (JavaField) theseFields.next();
+ if (oneField.getName().equals("DTFJ_ARRAYLET_INTS")) {
+ //run the int test
+ JavaObject array = (JavaObject) oneField.get(container);
+ int remote[] = new int[size];
+ int whole[] = new int[size];
+ for (int i = 0; i < size; i++) {
+ array.arraycopy(i, remote, i, 1);
+ assertTrue(remote[i] == (size -i));
+ }
+ array.arraycopy(0, whole, 0, size);
+ assertTrue(Arrays.equals(whole, remote));
+ } else if (oneField.getName().equals("DTFJ_ARRAYLET_BYTES")) {
+ //run the byte test
+ JavaObject array = (JavaObject) oneField.get(container);
+ byte remote[] = new byte[size];
+ byte whole[] = new byte[size];
+ for (int i = 0; i < size; i++) {
+ array.arraycopy(i, remote, i, 1);
+ assertTrue(remote[i] == ((byte)(size -i)));
+ }
+ array.arraycopy(0, whole, 0, size);
+ assertTrue(Arrays.equals(whole, remote));
+ } else if (oneField.getName().equals("DTFJ_ARRAYLET_STRINGCONTAINER")) {
+ //run the byte test
+ JavaObject array = (JavaObject) oneField.get(container);
+ JavaObject whole[] = new JavaObject[size];
+ array.arraycopy(0, whole, 0, size);
+ JavaField stringField = null;
+ Iterator iter = whole[0].getJavaClass().getDeclaredFields();
+ while(iter.hasNext()) {
+ JavaField testField = (JavaField) iter.next();
+ if (testField.getName().equals("_stringField")) {
+ //this is the field
+ stringField = testField;
+ }
+ }
+ assertNotNull(stringField);
+ //now extract the string fields
+ for (int i = 0; i < whole.length; i++) {
+ String stringContent = stringField.getString(whole[i]);
+ assertTrue(stringContent.equals(Integer.toString(size-i)));
+ }
+ }
+ }
+ } else {
+ //we are missing something required to run the test
+ throw new TestNotImplementedException();
+ }
+ } catch (CorruptDataException e) {
+ //if anything went wrong, we can't run the test
+ throw new TestNotImplementedException();
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //if anything went wrong, we can't run the test
+ throw new TestNotImplementedException();
+ } catch (Exception e) {
+ //if we caught anything else, this is an error
+ fail();
+ }
+ } else {
+ //the class isn't there so say we can't run the test
+ throw new TestNotImplementedException();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaClass.toString()'
+ *
+ */
+ public void testToString()
+ {
+ String theString = _testClass.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaFieldTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaFieldTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaFieldTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaFieldTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,285 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.MemoryAccessException;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaClassLoader;
+import com.ibm.dtfj.java.JavaField;
+import com.ibm.dtfj.java.JavaObject;
+
+public class JavaFieldTest extends AbstractDTFJTestcase
+{
+ private JavaObject _testInstance;
+ private JavaField _field;
+ private JavaField _anotherField;
+
+ public static JavaField defaultJavaField(JavaClass clazz)
+ {
+ return (JavaField) clazz.getDeclaredFields().next();
+ }
+
+ protected void setUp() throws Exception
+ {
+ try {
+ _testInstance = defaultJavaObject(false);
+ Iterator declaredFields=_testInstance.getJavaClass().getDeclaredFields();
+ _field = (JavaField)declaredFields.next(); //guaranteed to exist - see JavaObjectTest#defaultJavaObject()
+ _anotherField=(JavaField)declaredFields.next(); //guaranteed to exist - see JavaObjectTest#defaultJavaObject()
+ super.setUp();
+ } catch (TestNotImplementedException e) {
+ throw e;
+ } catch (Throwable t) {
+ //we weren't expecting any exceptions during startup so that is a test failure
+ t.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.get(JavaObject)'
+ *
+ * This test will fail if a runtime exception is thrown (i.e. if _field does not represent a proper field of _testInstance)
+ */
+ public void testGet()
+ {
+ try {
+ Object field = _field.get(_testInstance);
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getBoolean(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetBoolean()
+ {
+ try {
+ _field.getBoolean(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getByte(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetByte()
+ {
+ try {
+ _field.getByte(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getChar(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetChar()
+ {
+ try {
+ _field.getChar(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getDouble(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetDouble()
+ {
+ try {
+ _field.getDouble(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getFloat(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetFloat()
+ {
+ try {
+ _field.getFloat(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getInt(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetInt()
+ {
+ try {
+ _field.getInt(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getLong(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetLong()
+ {
+ try {
+ _field.getLong(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getShort(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetShort()
+ {
+ try {
+ _field.getShort(_testInstance);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaField.getString(JavaObject)'
+ *
+ * Ensures that we succeed or get expected exceptions
+ */
+ public void testGetString()
+ {
+ try {
+ String string = _field.getString(_testInstance);
+ assertNotNull(string);
+ } catch (IllegalArgumentException e) {
+ } catch (CorruptDataException e) {
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertFalse(_field.equals(_anotherField));
+ assertTrue(_field.equals(_field));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _testInstance.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * This test is to cover an issue where a static field is not parsed correctly. It is very specialized
+ * because of this interest in very special information.
+ * It looks up the PI constant on java.lang.Math and compares it to the running VM's notion of that constant
+ */
+ public void testJavaStaticFieldDouble()
+ {
+ JavaClass math = null;
+ Iterator loaders = defaultJavaRuntime().getJavaClassLoaders();
+
+ while (loaders.hasNext()) {
+ JavaClassLoader loader = (JavaClassLoader) loaders.next();
+ try {
+ for (Iterator iter = loader.getDefinedClasses(); iter.hasNext();) {
+ JavaClass clazz = (JavaClass) iter.next();
+ if (clazz.getName().equals("java/lang/Math")) {
+ math = clazz;
+ break;
+ }
+ }
+ } catch (CorruptDataException e) {
+ // Ignore.
+ }
+ }
+
+ if (null != math) {
+ Iterator fields = math.getDeclaredFields();
+ while (fields.hasNext()) {
+ JavaField field = (JavaField) fields.next();
+ try {
+ if (field.getName().equals("PI")) {
+ double pi = field.getDouble(null);
+ assertTrue(Math.PI == pi);
+ }
+ } catch (CorruptDataException e) {
+ //ignore
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //fail
+ assertTrue(false);
+ }
+ }
+ } else {
+ throw new TestNotImplementedException();
+ }
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaHeapTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaHeapTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaHeapTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaHeapTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.java.JavaHeap;
+
+public class JavaHeapTest extends AbstractDTFJTestcase
+{
+ private JavaHeap _heap = null;
+
+ protected void setUp() throws Exception
+ {
+ _heap = defaultJavaHeap();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaHeap.getSections()'
+ *
+ * Ensure that the heap has at least one section
+ */
+ public void testGetSections()
+ {
+ Iterator iter = _heap.getSections();
+ assertNotNull(iter);
+ assertTrue(iter.hasNext());
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaHeap.getName()'
+ *
+ * Ensure that the heap has a non-empty name
+ */
+ public void testGetName()
+ {
+ String name = _heap.getName();
+ assertNotNull(name);
+ assertTrue(name.length() > 0);
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaHeap.getObjects()'
+ *
+ * Ensure that we return a non-empty iterator
+ */
+ public void testGetObjects()
+ {
+ Iterator it = _heap.getObjects();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_heap.equals(_heap));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _heap.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaLocationTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaLocationTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaLocationTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaLocationTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,150 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.ImagePointer;
+import com.ibm.dtfj.java.JavaLocation;
+import com.ibm.dtfj.java.JavaStackFrame;
+
+public class JavaLocationTest extends AbstractDTFJTestcase
+{
+ private JavaLocation _location;
+
+ public JavaLocation defaultLocation()
+ {
+ try {
+ return ((JavaStackFrame)defaultJavaThread().getStackFrames().next()).getLocation();
+ } catch (CorruptDataException e) {
+ //XXX: how should this be handled?
+ throw new TestNotImplementedException();
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ _location = defaultLocation();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaLocation.getAddress()'
+ *
+ * Ensures that the address is non-null
+ */
+ public void testGetAddress()
+ {
+ try {
+ ImagePointer address = _location.getAddress();
+ assertNotNull(address);
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaLocation.getLineNumber()'
+ *
+ * Ensures that the line number is >0
+ */
+ public void testGetLineNumber()
+ {
+ try {
+ assertTrue(_location.getLineNumber() > 0);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaLocation.getFilename()'
+ *
+ * Ensures that the filename is non-null and non-empty
+ */
+ public void testGetFilename()
+ {
+ try {
+ String filename = _location.getFilename();
+ assertNotNull(filename);
+ assertTrue(filename.length() > 0);
+ } catch (DataUnavailable e) {
+ //acceptable
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaLocation.getCompilationLevel()'
+ *
+ * Ensures that the call succeeds
+ */
+ public void testGetCompilationLevel()
+ {
+ try {
+ _location.getCompilationLevel();
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaLocation.getMethod()'
+ *
+ * Ensures that a non-null method is returned
+ */
+ public void testGetMethod()
+ {
+ try {
+ assertNotNull(_location.getMethod());
+ } catch (CorruptDataException e) {
+ //acceptable
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_location.equals(_location));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _location.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ public void testToString()
+ {
+ String theString = _location.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMethodTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMethodTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMethodTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMethodTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.ImageSection;
+import com.ibm.dtfj.java.JavaField;
+import com.ibm.dtfj.java.JavaMethod;
+
+public class JavaMethodTest extends AbstractDTFJTestcase
+{
+ private JavaMethod _method = null;
+
+ protected void setUp() throws Exception
+ {
+ _method = defaultJavaMethod();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMethod.getBytecodeSections()'
+ *
+ * Ensures that a non-null iterator is returned and every element of the iterator is ImageSection.
+ * (note that the iterator can be empty in the case of natives)
+ */
+ public void testGetBytecodeSections()
+ {
+ Iterator it = _method.getBytecodeSections();
+ assertNotNull(it);
+ while (it.hasNext()) {
+ assertTrue(it.next() instanceof ImageSection);
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMethod.getCompiledSections()'
+ *
+ * Ensures that a non-null, non-empty iterator is returned
+ */
+ public void testGetCompiledSections()
+ {
+ Iterator it = _method.getCompiledSections();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMember.getModifiers()'
+ *
+ * Ensures that the call succeeds
+ */
+ public void testGetModifiers()
+ {
+ try {
+ _method.getModifiers();
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMember.getDeclaringClass()'
+ *
+ * Ensures that the class has a non-null address
+ */
+ public void testGetDeclaringClass()
+ {
+ try {
+ assertTrue(0 != _method.getDeclaringClass().getID().getAddress());
+ } catch (CorruptDataException e) {
+ } catch (DataUnavailable e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMember.getName()'
+ *
+ * Ensure that the method has a non-empty name
+ */
+ public void testGetName()
+ {
+ try {
+ assertTrue(_method.getName().length() > 0);
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMember.getSignature()'
+ *
+ * Ensure that the signature is non-empty
+ */
+ public void testGetSignature()
+ {
+ try {
+ assertTrue(_method.getSignature().length() > 0);
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_method.equals(_method));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _method.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ public void testToString()
+ {
+ String theString=_method.toString();
+ assertNotNull(theString);
+ assertTrue(theString.length() >= 0 );
+ }
+
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMonitorTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMonitorTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMonitorTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaMonitorTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,171 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.java.JavaMonitor;
+import com.ibm.dtfj.java.JavaThread;
+
+public class JavaMonitorTest extends AbstractDTFJTestcase
+{
+ private JavaMonitor _monitor = null;
+
+ public JavaMonitor defaultJavaMonitor()
+ {
+ Iterator it = defaultJavaRuntime().getMonitors();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ return (JavaMonitor) it.next();
+ }
+
+ protected void setUp() throws Exception
+ {
+ _monitor = defaultJavaMonitor();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getObject()'
+ *
+ * Ensures that no unexpected exceptions are thrown
+ */
+ public void testGetObject()
+ {
+ _monitor.getObject();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getName()'
+ *
+ * Ensures that a non-null name is returned
+ */
+ public void testGetName()
+ {
+ try {
+ String name = _monitor.getName();
+ assertNotNull(name);
+ } catch (CorruptDataException e) {
+ //this is technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getOwner()'
+ *
+ * Ensures that no unexpected exceptions are thrown
+ */
+ public void testGetOwner()
+ {
+ try {
+ _monitor.getOwner();
+ } catch (CorruptDataException e) {
+ //this is technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getEnterWaiters()'
+ *
+ * Ensures that either an empty iterator is returned, or a non-empty iterator where all the
+ * elements are JavaThread of CorruptData is returned.
+ */
+ public void testGetEnterWaiters()
+ {
+ Iterator iter = _monitor.getEnterWaiters();
+ assertNotNull(iter);
+ while (iter.hasNext()) {
+ Object element = iter.next();
+ assertTrue((element instanceof JavaThread) || (element instanceof CorruptData));
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getNotifyWaiters()'
+ *
+ * Ensures that either an empty iterator is returned, or a non-empty iterator where all the
+ * elements are JavaThread of CorruptData is returned.
+ */
+ public void testGetNotifyWaiters()
+ {
+ Iterator iter = _monitor.getNotifyWaiters();
+ assertNotNull(iter);
+ while (iter.hasNext()) {
+ Object element = iter.next();
+ assertTrue((element instanceof JavaThread) || (element instanceof CorruptData));
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaMonitor.getID()'
+ *
+ * Ensures that the pointer we receive is non-null.
+ */
+ public void testGetID()
+ {
+ assertNotNull(_monitor.getID());
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_monitor.equals(_monitor));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _monitor.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Ensure that all the monitors we find which have owners have valid owners.
+ *
+ * Note: This test may have to be removed or further qualified in the future if we want to restrict this test suite to only deal
+ * with spec behaviour (which would allow getOwner() to throw CorruptDataException) or to test corner cases and past bugs in the
+ * (since this test suite currently addresses both needs).
+ */
+ public void testAllMonitorOwners()
+ {
+ try {
+ Iterator it = defaultJavaRuntime().getMonitors();
+
+ while (it.hasNext()) {
+ JavaMonitor monitor = (JavaMonitor) it.next();
+ JavaThread owner = monitor.getOwner();
+
+ if (null != owner) {
+ assertNotNull(owner.getName());
+ }
+ }
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaObjectTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaObjectTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaObjectTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaObjectTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,800 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.MemoryAccessException;
+import com.ibm.dtfj.java.JavaClass;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaReference;
+import com.ibm.dtfj.tck.api.ICheckpoint;
+
+public class JavaObjectTest extends AbstractDTFJTestcase
+{
+ protected static final char SIG_BOOLEAN = 'Z';
+ protected static final char SIG_BYTE = 'B';
+ protected static final char SIG_CHAR = 'C';
+ protected static final char SIG_SHORT = 'S';
+ protected static final char SIG_INT = 'I';
+ protected static final char SIG_LONG = 'J';
+ protected static final char SIG_FLOAT = 'F';
+ protected static final char SIG_DOUBLE = 'D';
+ protected static final char SIG_OBJECT = 'L';
+ protected static final char SIG_ARRAY = '[';
+
+ private JavaObject _object = null;
+ private JavaObject _array = null;
+
+
+ /**
+ * Add array object with values to dumo
+ */
+ public void configureArrayObject(ICheckpoint point) {
+
+ Object o[]=new Object[]{new Object(),"ZZZ",new Hashtable()};
+ point.checkpoint();
+
+ }
+
+ protected void setUp() throws Exception
+ {
+ try {
+ _object = defaultJavaObject(false);
+ _array = defaultJavaObject(true);
+ super.setUp();
+ } catch (TestNotImplementedException e) {
+ throw e;
+ } catch (Throwable t) {
+ //we weren't expecting any exceptions during startup so that is a test failure
+ t.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getJavaClass()'
+ *
+ * Ensures that we get a class which has a name (that should imply that it is sane)
+ */
+ public void testGetJavaClass()
+ {
+ JavaClass theClass = null;
+ try {
+ theClass = _object.getJavaClass();
+ } catch (CorruptDataException e) {
+ }
+ assertNotNull(theClass);
+ try {
+ assertNotNull(theClass.getName());
+ } catch (CorruptDataException e) {
+ //this would be wrong since we are supposed to get a sane object back
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.isArray()'
+ *
+ * Ensures that this call returns something
+ */
+ public void testIsArray()
+ {
+ try {
+ _object.isArray();
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getArraySize()'
+ *
+ * Ensures that we only get specced behaviour for this call
+ */
+ public void testGetArraySize()
+ {
+ try {
+ _array.getArraySize();
+ } catch (CorruptDataException e) {
+ } catch (IllegalArgumentException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy one element from a an array
+ */
+ public void testArraycopy()
+ {
+ try {
+ Object destination = destArray(1);
+
+ _array.arraycopy(0, destination, 0, 1);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy all the elements from an array
+ */
+ public void testArraycopy2()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ _array.arraycopy(0, destination, 0, size);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy most of the elements from an array
+ */
+ public void testArraycopy2a()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ _array.arraycopy(0, destination, 0, size-1);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy most of the elements from an array
+ */
+ public void testArraycopy2b()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ _array.arraycopy(1, destination, 0, size-1);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy most of the elements from an array
+ */
+ public void testArraycopy2c()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ _array.arraycopy(1, destination, 1, size-1);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures that we can copy most of the elements from an array
+ */
+ public void testArraycopy2d()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ _array.arraycopy(0, destination, 1, size-1);
+ } catch (CorruptDataException e) {
+ //technically allowed
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ //technically allowed
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures source index out of range is detected
+ */
+ public void testArraycopy3()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(-1, destination, 0, size);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures source index out of range is detected (at the end)
+ */
+ public void testArraycopy4()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size+1);
+ try {
+ _array.arraycopy(1, destination, 0, size);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size+1, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures source index out of range is detected
+ */
+ public void testArraycopy5()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size+1);
+ try {
+ _array.arraycopy(size, destination, 0, 1);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size+1, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures destination index out of range is detected
+ */
+ public void testArraycopy6()
+ {
+
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, destination, -1, size);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures destination index out of range is detected
+ */
+ public void testArraycopy7()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, destination, 1, size);
+ fail("Expected destination index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures source index out of range is detected
+ */
+ public void testArraycopy8()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(size+1, destination, 0, 0);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures negative length is detected
+ */
+ public void testArraycopy9()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, destination, 0, -1);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures null destination is detected
+ */
+ public void testArraycopy10()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, null, 0, size);
+ fail("Expected source index out of bounds");
+ } catch (NullPointerException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures bad destination is detected
+ */
+ public void testArraycopy11()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, new JavaClass[size], 0, size);
+ fail("Expected source index out of bounds");
+ } catch (IllegalArgumentException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures out of range source index is detected
+ */
+ public void failing_testArraycopy12()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(Integer.MAX_VALUE, destination, 0, 1);
+ fail("Expected source index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures out of range destination index is detected
+ */
+ public void testArraycopy13()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(0, destination, Integer.MAX_VALUE, 1);
+ fail("Expected destination index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.arraycopy(int, Object, int, int)'
+ *
+ * Ensures out of range size is detected
+ */
+ public void failing_testArraycopy14()
+ {
+ try {
+ int size = _array.getArraySize();
+ Object destination = destArray(size);
+ try {
+ _array.arraycopy(1, destination, 1, Integer.MAX_VALUE);
+ fail("Expected destination index out of bounds");
+ } catch (IndexOutOfBoundsException e) {
+ // Expected array unchanged
+ testArray(size, destination);
+ } catch (MemoryAccessException e) {
+ assertNotNull(e.getPointer());
+ throw new Error(e);
+ } catch (CorruptDataException e) {
+ throw new Error(e);
+ }
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ private Object destArray(int size) throws CorruptDataException {
+ return destArray(_array, 0, size, null);
+ }
+
+ private void testArray(int size, Object comp) throws CorruptDataException {
+ destArray(_array, 0, size, comp);
+ }
+
+
+ /**
+ * @param size size of array
+ *
+ * @throws CorruptDataException
+ */
+ private Object destArray(JavaObject array, int start, int end, Object comp) throws CorruptDataException {
+ boolean fill = comp == null;
+ int size = end;
+ Object destination;
+
+ String componentType = array.getJavaClass().getComponentType().getName();
+
+ if (componentType.equals("boolean")) {
+ boolean[] destination1 = fill ? new boolean[size] : (boolean[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (i & 1) != 0;
+ assertEquals("index "+i,
+ destination1[i] , (i & 1) != 0);
+ }
+ destination = destination1;
+ } else if (componentType.equals("byte")) {
+ byte[] destination1 = fill ? new byte[size] : (byte[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (byte)(i*3);
+ assertEquals("index "+i,
+ destination1[i] , (byte)(i*3));
+ }
+ destination = destination1;
+ } else if (componentType.equals("char")) {
+ char[] destination1 = fill ? new char[size] : (char[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (char)(i*3);
+ assertEquals("index "+i,
+ destination1[i] , (char)(i*3));
+ }
+ destination = destination1;
+ } else if (componentType.equals("double")) {
+ double[] destination1 = fill ? new double[size] : (double[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = i*0.1;
+ assertEquals("index "+i,
+ destination1[i] , i*0.1, 0.0);
+ }
+ destination = destination1;
+ } else if (componentType.equals("float")) {
+ float[] destination1 = fill ? new float[size] : (float[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = i*0.1f;
+ assertEquals("index "+i,
+ destination1[i] , i*0.1f, 0.0f);
+ }
+ destination = destination1;
+ } else if (componentType.equals("int")) {
+ int[] destination1 = fill ? new int[size] : (int[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (int)(i*3);
+ assertEquals("index "+i,
+ destination1[i] , (int)(i*3));
+ }
+ destination = destination1;
+ } else if (componentType.equals("long")) {
+ long[] destination1 = fill ? new long[size] : (long[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (long)(i*3);
+ assertEquals("index "+i,
+ destination1[i] , (long)(i*3));
+ }
+ destination = destination1;
+ } else if (componentType.equals("short")) {
+ short[] destination1 = fill ? new short[size] : (short[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = (short)(i*3);
+ assertEquals("index "+i,
+ destination1[i] , (short)(i*3));
+ }
+ destination = destination1;
+ } else {
+ // component type is array or object
+ Object destination1[] = fill ? new Object[size] : (Object[])comp;
+ for (int i = start; i < end; ++i) {
+ if (fill)
+ destination1[i] = new Integer(i*3);
+ assertEquals("index "+i,
+ destination1[i] , new Integer(i*3));
+ }
+ destination = destination1;
+ }
+ return destination;
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getSize()'
+ *
+ * Ensures that a positive integer is returned
+ */
+ public void testGetSize()
+ {
+ try {
+ assertTrue(_object.getSize() > 0);
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getHashcode()'
+ *
+ * Ensures that the call succeeds
+ */
+ public void testGetHashcode()
+ {
+ try {
+ _object.getHashcode();
+ } catch (DataUnavailable e) {
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getPersistentHashcode()'
+ *
+ * Ensures that the call succeeeds
+ */
+ public void testGetPersistentHashcode()
+ {
+ try {
+ _object.getPersistentHashcode();
+ } catch (DataUnavailable e) {
+ } catch (CorruptDataException e) {
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getID()'
+ *
+ * Ensures that a non-zero pointer is returned
+ */
+ public void testGetID()
+ {
+ assertTrue(0 != _object.getID().getAddress());
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getHeap()'
+ *
+ * Ensures that a non-null heap is returned
+ */
+ public void testGetHeap()
+ {
+ try {
+ assertTrue(null != _object.getHeap());
+ } catch (CorruptDataException e) {
+ } catch (DataUnavailable e) {
+ }
+ }
+
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getSections()'
+ *
+ * Ensures that at least one section is in the returned iterator
+ */
+ public void testGetSections()
+ {
+ Iterator sections = _object.getSections();
+
+ assertNotNull(sections);
+ assertTrue(sections.hasNext());
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaObject.getReferences()'
+ *
+ * Ensures that the test object and test array object return non-null iterators, that any elements
+ * are either JavaReference or CorruptData, and that any JavaReference objects have a non-null
+ * description.
+ */
+ public void testGetReferences()
+ {
+ try {
+ // test references from a non-array object
+ Iterator references = _object.getReferences();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
+ if (instance instanceof JavaReference) {
+ // sniff these objects by getting the description
+ JavaReference object = (JavaReference)instance;
+ String description = object.getDescription();
+ assertNotNull(description);
+ }
+ }
+
+ // test references from an array object
+ references = _array.getReferences();
+ assertNotNull(references);
+ while (references.hasNext()) {
+ Object instance = references.next();
+ assertTrue((instance instanceof JavaReference) || (instance instanceof CorruptData));
+ if (instance instanceof JavaReference) {
+ // sniff these objects by getting the description
+ JavaReference object = (JavaReference)instance;
+ String description = object.getDescription();
+ assertNotNull(description);
+ }
+ }
+ } catch (Exception e) {
+ // if we caught anything else, this is a failure
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_object.equals(_object));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _object.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaRuntimeTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaRuntimeTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaRuntimeTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaRuntimeTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,383 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.image.ImageAddressSpace;
+import com.ibm.dtfj.image.ImagePointer;
+import com.ibm.dtfj.image.ImageSection;
+import com.ibm.dtfj.image.MemoryAccessException;
+import com.ibm.dtfj.java.JavaHeap;
+import com.ibm.dtfj.java.JavaMonitor;
+import com.ibm.dtfj.java.JavaObject;
+import com.ibm.dtfj.java.JavaReference;
+import com.ibm.dtfj.java.JavaRuntime;
+import com.ibm.dtfj.java.JavaVMInitArgs;
+import com.ibm.dtfj.java.JavaVMOption;
+
+public class JavaRuntimeTest extends AbstractDTFJTestcase
+{
+ private JavaRuntime _runtime = null;
+
+ protected void setUp() throws Exception
+ {
+ _runtime = defaultJavaRuntime();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getJavaVM()'
+ *
+ * Ensure that the pointer exists
+ */
+ public void testGetJavaVM()
+ {
+ try {
+ assertNotNull(_runtime.getJavaVM());
+ } catch (CorruptDataException e) {
+ //allowed by spec
+ } catch (Exception e) {
+ //no other exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getJavaClassLoaders()'
+ *
+ * Ensures that there is at least one class loader in the VM
+ */
+ public void testGetJavaClassLoaders()
+ {
+ try {
+ Iterator loaders = _runtime.getJavaClassLoaders();
+ assertNotNull(loaders);
+ assertTrue(loaders.hasNext());
+ } catch (Exception e) {
+ //no exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getetObjectAtAddress()'
+ *
+ * Ensures that every object in the heap is also accessible by address,
+ * and that addresses outside the heap or not pointing to an object start
+ * throw the expected exceptions.
+ */
+ public void testGetObjectAtAddress()
+ {
+ JavaHeap heap = defaultJavaHeap();
+ JavaRuntime runtime = defaultJavaRuntime();
+ ImageAddressSpace addressSpace = defaultAddressSpace();
+ ImagePointer address=null;
+ ImagePointer unalignedAddress=null;
+ Iterator heapSections = heap.getSections();
+
+
+ //determine the heap start and end address
+ long heapStartAddress = Long.MAX_VALUE;
+ long heapEndAddress = 0;
+
+ Object nextElement = null;
+
+ ImageSection currentSection = null;
+ long sectionStart = 0;
+
+ while (heapSections.hasNext()) {
+ nextElement = heapSections.next();
+ if (nextElement instanceof ImageSection) {
+ currentSection = (ImageSection) nextElement;
+ sectionStart = currentSection.getBaseAddress().getAddress();
+ if (sectionStart < heapStartAddress) {
+ heapStartAddress = sectionStart;
+ }
+ if (sectionStart + currentSection.getSize() > heapEndAddress) {
+ heapEndAddress = sectionStart + currentSection.getSize();
+ }
+
+ }
+
+ }
+
+ //check that every object in the heap can be retrieved by address
+ boolean exception=false;
+ for (Iterator objects = heap.getObjects();objects.hasNext();) {
+ Object potentialObject = objects.next();
+ JavaObject object = null;
+ if (potentialObject instanceof JavaObject) {
+ object = (JavaObject)potentialObject;
+ } else {
+ continue;
+ }
+ address=(ImagePointer)object.getID();
+ try {
+ runtime.getObjectAtAddress(address).getJavaClass();
+ if (unalignedAddress == null) {
+ unalignedAddress = address.add(1);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ exception=true;
+ break;
+ }
+
+ }
+ assertFalse(exception);
+
+
+ // Check an address BEFORE the start of the heap. For some JVMs, off-heap objects are supported
+ exception=false;
+ try {
+ long addr1 = ((heapStartAddress-1000) & (Long.MAX_VALUE-7L));
+ runtime.getObjectAtAddress(addressSpace.getPointer(addr1));
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ exception=true;
+ } catch (Exception e) {
+ }
+ assertFalse(exception);
+
+ // Check an address AFTER the first object but not aligned with an object boundary.
+ // unalignedAddress is expected to throw a IllegalArgumentException
+
+ exception=false;
+ try {
+ runtime.getObjectAtAddress(unalignedAddress);
+ } catch (IllegalArgumentException e) {
+ // IllegalArgumentException is the expected behaviour
+ } catch (CorruptDataException e) {
+ exception=true;
+ e.printStackTrace();
+ } catch (MemoryAccessException e) {
+ exception=true;
+ e.printStackTrace();
+ } catch (DataUnavailable e) {
+ exception=true;
+ e.printStackTrace();
+ }
+ assertFalse(exception);
+
+ }
+
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getThreads()'
+ *
+ * Ensures that there is at least one known thread in the runtime
+ */
+ public void testGetThreads()
+ {
+ try {
+ Iterator it = _runtime.getThreads();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ } catch (Exception e) {
+ //no exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getCompiledMethods()'
+ *
+ * Ensures that the iterator is non-null
+ */
+ public void testGetCompiledMethods()
+ {
+ try {
+ Iterator it = _runtime.getCompiledMethods();
+ assertNotNull(it);
+ } catch (Exception e) {
+ //no exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getMonitors()'
+ *
+ * Ensures that the iterator is non-null, has at least one element and it is a JavaMonitor object.
+ */
+ public void testGetMonitors()
+ {
+ try {
+ Iterator it = _runtime.getMonitors();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ assertTrue(it.next() instanceof JavaMonitor);
+ } catch (Exception e) {
+ //no exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getHeaps()'
+ *
+ * Ensures that the iterator is non-null, has at least one element and it is a JavaHeap object.
+ */
+ public void testGetHeaps()
+ {
+ try {
+ Iterator it = _runtime.getHeaps();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ assertTrue(it.next() instanceof JavaHeap);
+ } catch (Exception e) {
+ //no exceptions should be thrown so catch it as a failure instead of an error
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaRuntime.getTraceBuffer(String, boolean)'
+ *
+ * Ensure that something non-null comes back when we ask for the trace buffers
+ */
+ public void testGetTraceBuffer()
+ {
+ try {
+ assertNotNull(_runtime.getTraceBuffer("trace", false));
+ } catch (CorruptDataException e) {
+ //this is considered safe since it is in the spec
+ } catch (Exception e) {
+ //no other exceptions should be thrown
+ fail();
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.runtime.ManagedRuntime.getVersion()'
+ *
+ * Makes sure that the full version is non-NULL.
+ * TODO: Make this test more strict
+ */
+ public void testGetVersion()
+ {
+ try {
+ assertNotNull(_runtime.getVersion());
+ } catch (CorruptDataException e) {
+ //this is considered safe since it is in the spec
+ } catch (Exception e) {
+ //no other exceptions should be thrown
+ fail();
+ }
+ }
+
+ public void testGetJavaVMInitArgs()
+ {
+ try {
+ JavaVMInitArgs args = _runtime.getJavaVMInitArgs();
+ assertNotNull(args);
+
+ int version = args.getVersion();
+ assertTrue((version == JavaVMInitArgs.JNI_VERSION_1_1)
+ || (version == JavaVMInitArgs.JNI_VERSION_1_2)
+ || (version == JavaVMInitArgs.JNI_VERSION_1_4));
+
+ Iterator options = args.getOptions();
+ assertNotNull(options);
+
+ // make sure there's at least one option (not strictly required)
+ //assertTrue(options.hasNext());
+
+ while (options.hasNext()) {
+ JavaVMOption option = (JavaVMOption)options.next();
+ assertNotNull(option.getOptionString());
+ // just make sure getExtraInfo() doesn't throw an exception
+ option.getExtraInfo();
+ }
+ } catch (CorruptDataException e) {
+ // this is permitted by the spec
+ } catch (DataUnavailable e) {
+ // this is permitted by the spec
+ } catch (Exception e) {
+ //no other exceptions should be thrown
+ fail();
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_runtime.equals(_runtime));
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _runtime.hashCode());
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ /**
+ * Ensures that we can walk over every object in every heap in the VM. Note that this may take a long time on large heaps!
+ */
+ public void AtestWalkAllHeaps()
+ {
+ try {
+ Iterator it = _runtime.getHeaps();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ while (it.hasNext()) {
+ Object next = it.next();
+ assertTrue(next instanceof JavaHeap);
+ JavaHeap heap = (JavaHeap) next;
+ Iterator objects = heap.getObjects();
+ assertNotNull(objects);
+ while (objects.hasNext()) {
+ Object one = objects.next();
+ assertTrue(one instanceof JavaObject);
+ }
+ }
+ } catch (Exception e) {
+ //no exceptions should be thrown from here
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ /**
+ * Ensures that we get at least one root Reference object from the JavaRuntime
+ *
+ */
+ public void testGetHeapRoots()
+ {
+
+ Iterator it = _runtime.getHeapRoots();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ Object first = it.next();
+ assertTrue( first instanceof JavaReference || first instanceof CorruptData);
+
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaStackFrameTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaStackFrameTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaStackFrameTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaStackFrameTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptData;
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.java.JavaReference;
+import com.ibm.dtfj.java.JavaStackFrame;
+import com.ibm.dtfj.java.JavaThread;
+
+public class JavaStackFrameTest extends AbstractDTFJTestcase
+{
+ private JavaStackFrame _frame = null;
+
+ public JavaStackFrame defaultJavaStackFrame()
+ {
+ JavaThread thread = defaultJavaThread();
+ Iterator it = thread.getStackFrames();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ return (JavaStackFrame) it.next();
+ }
+
+ protected void setUp() throws Exception
+ {
+ _frame = defaultJavaStackFrame();
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaStackFrame.getBasePointer()'
+ *
+ * Ensures that a non-null base pointer is returned
+ */
+ public void testGetBasePointer()
+ {
+ try {
+ assertNotNull(_frame.getBasePointer());
+ } catch (CorruptDataException e) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaStackFrame.getLocation()'
+ *
+ * Ensures that a non-null location is returned
+ */
+ public void testGetLocation()
+ {
+ try {
+ assertNotNull(_frame.getLocation());
+ } catch (CorruptDataException e) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_frame.equals(_frame));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+
+ assertTrue(0 != _frame.hashCode());
+
+ }
+
+ /**
+ * Ensures that we get at least one root Reference object from the JavaStackFrame
+ *
+ */
+ public void testGetHeapRoots()
+ {
+ try {
+ Iterator it = _frame.getHeapRoots();
+ assertNotNull(it);
+ /* some frames may legitimately not have any roots */
+ if (it.hasNext()){
+ Object first = it.next();
+ assertTrue( first instanceof JavaReference || first instanceof CorruptData);
+ }
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+}
Added: incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaThreadTest.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaThreadTest.java?rev=754945&view=auto
==============================================================================
--- incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaThreadTest.java (added)
+++ incubator/kato/trunk/import/org.apache.kato.tck.tests/src/com/ibm/dtfj/tests/junit/JavaThreadTest.java Mon Mar 16 16:42:39 2009
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.ibm.dtfj.tests.junit;
+
+import java.util.Iterator;
+
+import com.ibm.dtfj.image.CorruptDataException;
+import com.ibm.dtfj.image.DataUnavailable;
+import com.ibm.dtfj.java.JavaThread;
+
+public class JavaThreadTest extends AbstractDTFJTestcase
+{
+ private JavaThread _thread = null;
+ private JavaThread _sameThread = null;
+
+ protected void setUp() throws Exception
+ {
+ _thread = defaultJavaThread();
+ _sameThread= defaultJavaThread();
+ assertNotNull(_thread);
+ super.setUp();
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getJNIEnv()'
+ *
+ * Ensures that the JNIEnv is non-null
+ */
+ public void testGetJNIEnv()
+ {
+ try {
+ assertNotNull(_thread.getJNIEnv());
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getPriority()'
+ */
+ public void testGetPriority()
+ {
+ try {
+ int priority = _thread.getPriority();
+ assertTrue((priority >= 1) && (priority <= 10));
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getObject()'
+ */
+ public void testGetObject()
+ {
+ //anything returned here is legal. In fact, even null is ok
+ try {
+ _thread.getObject();
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getState()'
+ */
+ public void testGetState()
+ {
+ try {
+ assertTrue(_thread.getState() > 0);
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getImageThread()'
+ *
+ * Ensures that a non-null image thread can be pulled from this thread
+ */
+ public void testGetImageThread()
+ {
+ try {
+ assertNotNull(_thread.getImageThread());
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ } catch (DataUnavailable e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getStackSections()'
+ *
+ * Ensures that a non-null, non-empty iterator is returned
+ */
+ public void testGetStackSections()
+ {
+ Iterator it = _thread.getStackSections();
+ assertNotNull(it);
+ assertTrue(it.hasNext());
+ }
+
+ /**
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getStackFrames()'
+ *
+ * Ensures that the frame iterator is non-null even though it may be empty
+ */
+ public void testGetStackFrames()
+ {
+ Iterator frames = _thread.getStackFrames();
+ assertNotNull(frames);
+ //it is legal for there to be no frames
+ }
+
+ /*
+ * Test method for 'com.ibm.dtfj.java.JavaThread.getName()'
+ */
+ public void testGetName()
+ {
+ try {
+ assertNotNull(_thread.getName());
+ } catch (CorruptDataException e) {
+ //this is acceptable by the spec
+ }
+ }
+
+ /**
+ * Verify that the equals call doesn't throw
+ */
+ public void testEquals()
+ {
+ try{
+ assertTrue(_thread.equals(_thread));
+ assertTrue(_thread.equals(_sameThread));
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Verify that hashCode() doesn't throw and returns non-zero (technically zero is ok but it will be
+ * flagged here to ensure that we aren't doing anything bad to create the hashcode)
+ */
+ public void testHashCode()
+ {
+ try {
+ assertTrue(0 != _thread.hashCode());
+ assertTrue(_thread.hashCode() == _sameThread.hashCode());
+ } catch (Throwable t) {
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * A test to make sure that all the threads in the runtime have a name and priority.
+ *
+ * This exists to prove that we can get the name and priority even in cases where the threads are subclasses of java/lang/Thread
+ */
+ public void testAllThreadsNamed()
+ {
+ Iterator threads = defaultJavaRuntime().getThreads();
+
+ while (threads.hasNext()) {
+ JavaThread thread = (JavaThread) threads.next();
+
+ try {
+ assertNotNull(thread.getName());
+ thread.getPriority();
+ } catch (CorruptDataException e) {
+ assertTrue(false);
+ }
+ }
+ }
+}