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 sp...@apache.org on 2009/11/24 12:27:11 UTC
svn commit: r883669 [3/6] - in
/incubator/kato/trunk/org.apache.kato/kato.tck: ./ src/test/ant/
src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/kato/
src/test/java/org/apache/kato/tck/ src/test/java/org/apache/kato/tck/tests/
src/...
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_arraycopy.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_arraycopy.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_arraycopy.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_arraycopy.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,1414 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaObject_arraycopy;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaObject_arraycopy.TestArrays;
+
+
+/**
+ * Sets up an object containing references to an array of each type.
+ * Then finds it in DTFJ and the compares the contents of the arrays with
+ * the contents of the arrays from DTFJ using JavaObject.arraycopy()
+ *
+ * TODO testcase should be expanded to test the boundary conditions, and expected error conditions.
+ *
+ */
+public class TestJavaObject_arraycopy extends TCKJavaRuntimeTestcase {
+
+
+
+ static JavaObject booleanDumpArray, byteDumpArray, shortDumpArray,
+ charDumpArray, intDumpArray, longDumpArray,
+ floatDumpArray, doubleDumpArray, integerDumpArray,
+ nonDumpArray, arrayDumpArray;
+
+ static JavaField valueField = null;
+ static JavaRuntime staticRuntime = null;
+
+ static int testArraysElementCount=SetupJavaObject_arraycopy.testArraysElementCount;
+ static TestArrays theTestObject=SetupJavaObject_arraycopy.theTestObject;
+
+ /**
+ * Setups if the test classe's statics.
+ * this is called before every test method. This method is extremely
+ * expensive as it searches the heap for objects.
+ * To speed this up, the variables are stored in statics.
+ * If the JavaRuntime object returned by getJavaRuntime() changes,
+ * the setup method is run, otherwise it exists early as it will already
+ * have run.
+ */
+ protected void setUp() throws Exception {
+ JavaRuntime runtime=getJavaRuntime();
+ // return if JavaRuntime changes. This is unsafe and bad.
+ if (runtime.equals(staticRuntime)) {
+ return;
+ }
+ staticRuntime = runtime;
+
+ JavaObject theJavaObject=null;
+ Iterator heaps = runtime.getHeaps().iterator();
+ JavaClass theJavaClass = null;
+
+ while (heaps.hasNext()) {
+ Object nextHeap = heaps.next();
+ if (nextHeap instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextHeap + "'");
+ break;
+ }
+
+ JavaHeap aJavaHeap = (JavaHeap) nextHeap;
+ Iterator objects = aJavaHeap.getObjects().iterator();
+
+ while (objects.hasNext()) {
+ Object nextObject = objects.next();
+ if (nextObject instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextObject + "'");
+ break;
+ }
+
+ JavaObject aJavaObject = (JavaObject) nextObject;
+ theJavaClass = aJavaObject.getJavaClass();
+ String theClassName = (theJavaClass).getName();
+ if (theClassName.equals(SetupJavaObject_arraycopy.TestArraysClassName)){
+ theJavaObject = aJavaObject;
+ break;
+ }
+
+ }
+ }
+
+ if (theJavaObject == null) {
+ fail("Didn't find TestArrays object");
+ return;
+ }
+
+ Iterator fields = theJavaClass.getDeclaredFields().iterator();
+
+ while (fields.hasNext()) {
+
+
+ Object nextField = fields.next();
+
+ if (nextField instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextField + "'");
+ break;
+ }
+
+ JavaField theField = (JavaField) nextField;
+ String theFieldName = theField.getName();
+
+ if(theFieldName.equals("booleanArray")) {
+ booleanDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("byteArray")) {
+ byteDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("shortArray")) {
+ shortDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("charArray")) {
+ charDumpArray = (JavaObject) theField.get(theJavaObject);
+ }else if(theFieldName.equals("intArray")) {
+ intDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("longArray")) {
+ longDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("floatArray")) {
+ floatDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("doubleArray")) {
+ doubleDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if(theFieldName.equals("integerArray")) {
+ integerDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if (theFieldName.equals("nonArray")) {
+ nonDumpArray = (JavaObject) theField.get(theJavaObject);
+ } else if (theFieldName.equals("arrayArray")) {
+ arrayDumpArray = (JavaObject) theField.get(theJavaObject);
+ }
+ }
+
+
+ // Find the JavaField "value" in "java/lang/Integer"
+ Iterator classLoaders = getJavaRuntime().getJavaClassLoaders().iterator();
+ JavaClass integerClass = null;
+
+ CLASSLOADERS:
+ while (classLoaders.hasNext()) {
+ Object next = classLoaders.next();
+
+ if (next instanceof CorruptData) {
+ throw new Exception("CorruptData found instead of JavaClassLoader");
+ }
+
+ JavaClassLoader loader = (JavaClassLoader) next;
+
+ Iterator classes = loader.getDefinedClasses().iterator();
+
+ while (classes.hasNext()) {
+ Object next2 = classes.next();
+
+ if (next2 instanceof CorruptData) {
+ throw new Exception("CorruptData found instead of JavaClass java.lang.Integer");
+ }
+
+ JavaClass aClass = (JavaClass) next2;
+
+ if (aClass.getName().equals("java/lang/Integer")) {
+ integerClass = aClass;
+ break CLASSLOADERS;
+ }
+ }
+ }
+
+ if (integerClass == null) {
+ throw new Exception("Couldn't find java/lang/Integer JavaClass");
+ }
+
+ Iterator integerFields = integerClass.getDeclaredFields().iterator();
+
+ // Find the value field in the class.
+ while (integerFields.hasNext()) {
+ Object next = integerFields.next();
+
+ if (next instanceof CorruptData) {
+ throw new Exception("CorruptData found instead of JavaField in java.lang.Integer");
+ }
+
+ JavaField aField = (JavaField) next;
+
+ if (aField.getName().equals("value")) {
+ valueField = aField;
+ break;
+ }
+ }
+ }
+
+ public void tearDown() throws Exception {
+ // do nothing
+
+ }
+
+ public void testNonArray_arraycopy() throws Exception {
+ Object[] dst = new Object[1];
+
+ try {
+ nonDumpArray.arraycopy(0, dst, 0, 1);
+ fail("arraycopy from nonArray didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+
+ }
+
+ public void testBoolean_arraycopy_notNull() throws Exception {
+ assertNotNull("booleanArray was not found.", booleanDumpArray);
+ }
+
+ public void testBoolean_arraycopy_isArray() throws Exception {
+ assertTrue("booleanArray is not an array.",booleanDumpArray.isArray());
+ }
+
+ public void testBoolean_arraycopy_arraySize() throws Exception {
+ assertEquals("booleanArray is wrong size -> "+booleanDumpArray.getArraySize(), booleanDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testBoolean_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ booleanDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testBoolean_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(booleanDumpArray);
+ try {
+ booleanDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testBoolean_arraycopy_simplecopy() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ booleanDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("booleanArray did not match.",Arrays.equals(array, theTestObject.booleanArray));
+ }
+
+ public void testBoolean_arraycopy_negativelength() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(0, array, 0, -1);
+ fail("booleanArray negative length copy failed - no IndexOutOfBoundsException");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_negativeSrcStart() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(-1, array, 0, testArraysElementCount);
+ fail("booleanArray negative src copy failed - no IndexOutOfBoundsException");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_negativeDstStart() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(0, array, -1, testArraysElementCount);
+ fail("booleanArray negative dst copy failed - no IndexOutOfBoundsException");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_largeSrcStart() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(testArraysElementCount, array, 0, testArraysElementCount);
+ fail("booleanArray large src copy failed - no IndexOutOfBoundsException");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_largeDstStart() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(0, array, testArraysElementCount, testArraysElementCount);
+ fail("booleanArray large src copy failed - no IndexOutOfBoundsException");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_lengthPlusOne() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ // copying too many elements...
+ try {
+ booleanDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("booleanArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_srcPlusOne() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ try {
+ booleanDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("booleanArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_dstPlusOne() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ try {
+ booleanDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("booleanArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testBoolean_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ boolean[] array = new boolean[testArraysElementCount];
+ boolean[] array2 = new boolean[testArraysElementCount];
+ booleanDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.booleanArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("booleanArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testBoolean_arraycopy_removeLastElement() throws Exception {
+ boolean[] array = new boolean[testArraysElementCount];
+ boolean[] array2 = new boolean[testArraysElementCount];
+ booleanDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.booleanArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("booleanArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testBoolean_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ boolean[] array = new boolean[testArraysElementCount];
+ boolean[] array2 = new boolean[testArraysElementCount];
+ booleanDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.booleanArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("booleanArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testBoolean_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ boolean[] array = new boolean[testArraysElementCount];
+ boolean[] array2 = new boolean[testArraysElementCount];
+ booleanDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.booleanArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("booleanArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testByte_arraycopy_notNull() throws Exception {
+ assertNotNull("byteArray was not found.", byteDumpArray);
+ }
+
+ public void testByte_arraycopy_isArray() throws Exception {
+ assertTrue("byteArray is not an array.",byteDumpArray.isArray());
+ }
+
+ public void testByte_arraycopy_arraySize() throws Exception {
+ assertEquals("byteArray is wrong size -> "+byteDumpArray.getArraySize(), byteDumpArray.getArraySize(), testArraysElementCount);
+ }
+ public void testByte_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ byteDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testByte_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(byteDumpArray);
+ try {
+ byteDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testByte_arraycopy_simplecopy() throws Exception {
+ byte[] array = new byte[testArraysElementCount];
+ byteDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("byteArray did not match.",Arrays.equals(array, theTestObject.byteArray));
+ }
+
+ public void testByte_arraycopy_lengthPlusOne() throws Exception {
+ byte[] array = new byte[testArraysElementCount];
+ // copying too many elements...
+ try {
+ byteDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("byteArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testByte_arraycopy_srcPlusOne() throws Exception {
+ byte[] array = new byte[testArraysElementCount];
+ try {
+ byteDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("byteArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testByte_arraycopy_dstPlusOne() throws Exception {
+ byte[] array = new byte[testArraysElementCount];
+ try {
+ byteDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("byteArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testByte_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ byte[] array = new byte[testArraysElementCount];
+ byte[] array2 = new byte[testArraysElementCount];
+ byteDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.byteArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("byteArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testByte_arraycopy_removeLastElement() throws Exception {
+ byte[] array = new byte[testArraysElementCount];
+ byte[] array2 = new byte[testArraysElementCount];
+ byteDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.byteArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("byteArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testByte_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ byte[] array = new byte[testArraysElementCount];
+ byte[] array2 = new byte[testArraysElementCount];
+ byteDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.byteArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("byteArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testByte_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ byte[] array = new byte[testArraysElementCount];
+ byte[] array2 = new byte[testArraysElementCount];
+ byteDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.byteArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("byteArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testShort_arraycopy_notNull() throws Exception {
+ assertNotNull("shortArray was not found.", shortDumpArray);
+ }
+
+ public void testShort_arraycopy_isArray() throws Exception {
+ assertTrue("shortArray is not an array.",shortDumpArray.isArray());
+ }
+
+ public void testShort_arraycopy_arraySize() throws Exception {
+ assertEquals("shortArray is wrong size -> "+shortDumpArray.getArraySize(), shortDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testShort_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ shortDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testShort_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(shortDumpArray);
+ try {
+ shortDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testShort_arraycopy_simplecopy() throws Exception {
+ short[] array = new short[testArraysElementCount];
+ shortDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("shortArray did not match.",Arrays.equals(array, theTestObject.shortArray));
+ }
+
+ public void testShort_arraycopy_lengthPlusOne() throws Exception {
+ short[] array = new short[testArraysElementCount];
+ // copying too many elements...
+ try {
+ shortDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("shortArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testShort_arraycopy_srcPlusOne() throws Exception {
+ short[] array = new short[testArraysElementCount];
+ try {
+ shortDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("shortArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testShort_arraycopy_dstPlusOne() throws Exception {
+ short[] array = new short[testArraysElementCount];
+ try {
+ shortDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("shortArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testShort_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ short[] array = new short[testArraysElementCount];
+ short[] array2 = new short[testArraysElementCount];
+ shortDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.shortArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("shortArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testShort_arraycopy_removeLastElement() throws Exception {
+ short[] array = new short[testArraysElementCount];
+ short[] array2 = new short[testArraysElementCount];
+ shortDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.shortArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("shortArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testShort_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ short[] array = new short[testArraysElementCount];
+ short[] array2 = new short[testArraysElementCount];
+ shortDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.shortArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("shortArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testShort_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ short[] array = new short[testArraysElementCount];
+ short[] array2 = new short[testArraysElementCount];
+ shortDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.shortArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("shortArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testChar_arraycopy_notNull() throws Exception {
+ assertNotNull("charArray was not found.", charDumpArray);
+ }
+
+ public void testChar_arraycopy_isArray() throws Exception {
+ assertTrue("charArray is not an array.",charDumpArray.isArray());
+ }
+
+ public void testChar_arraycopy_arraySize() throws Exception {
+ assertEquals("charArray is wrong size -> "+charDumpArray.getArraySize(), charDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testChar_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ charDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testChar_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(charDumpArray);
+ try {
+ charDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testChar_arraycopy_simplecopy() throws Exception {
+ char[] array = new char[testArraysElementCount];
+ charDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("charArray did not match.",Arrays.equals(array, theTestObject.charArray));
+ }
+
+ public void testChar_arraycopy_lengthPlusOne() throws Exception {
+ char[] array = new char[testArraysElementCount];
+ // copying too many elements...
+ try {
+ charDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("charArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testChar_arraycopy_srcPlusOne() throws Exception {
+ char[] array = new char[testArraysElementCount];
+ try {
+ charDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("charArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testChar_arraycopy_dstPlusOne() throws Exception {
+ char[] array = new char[testArraysElementCount];
+ try {
+ charDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("charArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testChar_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ char[] array = new char[testArraysElementCount];
+ char[] array2 = new char[testArraysElementCount];
+ charDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.charArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("charArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testChar_arraycopy_removeLastElement() throws Exception {
+ char[] array = new char[testArraysElementCount];
+ char[] array2 = new char[testArraysElementCount];
+ charDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.charArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("charArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testChar_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ char[] array = new char[testArraysElementCount];
+ char[] array2 = new char[testArraysElementCount];
+ charDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.charArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("charArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testChar_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ char[] array = new char[testArraysElementCount];
+ char[] array2 = new char[testArraysElementCount];
+ charDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.charArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("charArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testInt_arraycopy_notNull() throws Exception {
+ assertNotNull("intArray was not found.", intDumpArray);
+ }
+
+ public void testInt_arraycopy_isArray() throws Exception {
+ assertTrue("intArray is not an array.",intDumpArray.isArray());
+ }
+
+ public void testInt_arraycopy_arraySize() throws Exception {
+ assertEquals("intArray is wrong size -> "+intDumpArray.getArraySize(), intDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testInt_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ intDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testInt_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(intDumpArray);
+ try {
+ intDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testInt_arraycopy_simplecopy() throws Exception {
+ int[] array = new int[testArraysElementCount];
+ intDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("intArray did not match.",Arrays.equals(array, theTestObject.intArray));
+ }
+
+ public void testInt_arraycopy_lengthPlusOne() throws Exception {
+ int[] array = new int[testArraysElementCount];
+ // copying too many elements...
+ try {
+ intDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("intArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInt_arraycopy_srcPlusOne() throws Exception {
+ int[] array = new int[testArraysElementCount];
+ try {
+ intDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("intArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInt_arraycopy_dstPlusOne() throws Exception {
+ int[] array = new int[testArraysElementCount];
+ try {
+ intDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("intArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInt_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ int[] array = new int[testArraysElementCount];
+ int[] array2 = new int[testArraysElementCount];
+ intDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.intArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("intArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testInt_arraycopy_removeLastElement() throws Exception {
+ int[] array = new int[testArraysElementCount];
+ int[] array2 = new int[testArraysElementCount];
+ intDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.intArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("intArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testInt_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ int[] array = new int[testArraysElementCount];
+ int[] array2 = new int[testArraysElementCount];
+ intDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.intArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("intArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testInt_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ int[] array = new int[testArraysElementCount];
+ int[] array2 = new int[testArraysElementCount];
+ intDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.intArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("intArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+
+ public void testLong_arraycopy_notNull() throws Exception {
+ assertNotNull("longArray was not found.", longDumpArray);
+ }
+
+ public void testLong_arraycopy_isArray() throws Exception {
+ assertTrue("longArray is not an array.",longDumpArray.isArray());
+ }
+
+ public void testLong_arraycopy_arraySize() throws Exception {
+ assertEquals("longArray is wrong size -> "+longDumpArray.getArraySize(), longDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testLong_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ longDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testLong_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(longDumpArray);
+ try {
+ longDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testLong_arraycopy_simplecopy() throws Exception {
+ long[] array = new long[testArraysElementCount];
+ longDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("longArray did not match.",Arrays.equals(array, theTestObject.longArray));
+ }
+
+ public void testLong_arraycopy_lengthPlusOne() throws Exception {
+ long[] array = new long[testArraysElementCount];
+ // copying too many elements...
+ try {
+ longDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("longArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testLong_arraycopy_srcPlusOne() throws Exception {
+ long[] array = new long[testArraysElementCount];
+ try {
+ longDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("longArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testLong_arraycopy_dstPlusOne() throws Exception {
+ long[] array = new long[testArraysElementCount];
+ try {
+ longDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("longArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testLong_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ long[] array = new long[testArraysElementCount];
+ long[] array2 = new long[testArraysElementCount];
+ longDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.longArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("longArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testLong_arraycopy_removeLastElement() throws Exception {
+ long[] array = new long[testArraysElementCount];
+ long[] array2 = new long[testArraysElementCount];
+ longDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.longArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("longArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testLong_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ long[] array = new long[testArraysElementCount];
+ long[] array2 = new long[testArraysElementCount];
+ longDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.longArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("longArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testLong_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ long[] array = new long[testArraysElementCount];
+ long[] array2 = new long[testArraysElementCount];
+ longDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.longArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("longArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testFloat_arraycopy_notNull() throws Exception {
+ assertNotNull("floatArray was not found.", floatDumpArray);
+ }
+
+ public void testFloat_arraycopy_isArray() throws Exception {
+ assertTrue("floatArray is not an array.",floatDumpArray.isArray());
+ }
+
+ public void testFloat_arraycopy_arraySize() throws Exception {
+ assertEquals("floatArray is wrong size -> "+floatDumpArray.getArraySize(), floatDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testFloat_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ floatDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testFloat_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(floatDumpArray);
+ try {
+ floatDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testFloat_arraycopy_simplecopy() throws Exception {
+ float[] array = new float[testArraysElementCount];
+ floatDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("floatArray did not match.",Arrays.equals(array, theTestObject.floatArray));
+ }
+
+ public void testFloat_arraycopy_lengthPlusOne() throws Exception {
+ float[] array = new float[testArraysElementCount];
+ // copying too many elements...
+ try {
+ floatDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("floatArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testFloat_arraycopy_srcPlusOne() throws Exception {
+ float[] array = new float[testArraysElementCount];
+ try {
+ floatDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("floatArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testFloat_arraycopy_dstPlusOne() throws Exception {
+ float[] array = new float[testArraysElementCount];
+ try {
+ floatDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("floatArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testFloat_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ float[] array = new float[testArraysElementCount];
+ float[] array2 = new float[testArraysElementCount];
+ floatDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.floatArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("floatArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testFloat_arraycopy_removeLastElement() throws Exception {
+ float[] array = new float[testArraysElementCount];
+ float[] array2 = new float[testArraysElementCount];
+ floatDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.floatArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("floatArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testFloat_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ float[] array = new float[testArraysElementCount];
+ float[] array2 = new float[testArraysElementCount];
+ floatDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.floatArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("floatArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testFloat_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ float[] array = new float[testArraysElementCount];
+ float[] array2 = new float[testArraysElementCount];
+ floatDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.floatArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("floatArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testDouble_arraycopy_notNull() throws Exception {
+ assertNotNull("doubleArray was not found.", doubleDumpArray);
+ }
+
+ public void testDouble_arraycopy_isArray() throws Exception {
+ assertTrue("doubleArray is not an array.",doubleDumpArray.isArray());
+ }
+
+ public void testDouble_arraycopy_arraySize() throws Exception {
+ assertEquals("doubleArray is wrong size -> "+doubleDumpArray.getArraySize(), doubleDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ public void testDouble_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ doubleDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testDouble_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(doubleDumpArray);
+ try {
+ doubleDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testDouble_arraycopy_simplecopy() throws Exception {
+ double[] array = new double[testArraysElementCount];
+ doubleDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("doubleArray did not match.",Arrays.equals(array, theTestObject.doubleArray));
+ }
+
+ public void testDouble_arraycopy_lengthPlusOne() throws Exception {
+ double[] array = new double[testArraysElementCount];
+ // copying too many elements...
+ try {
+ doubleDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("doubleArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testDouble_arraycopy_srcPlusOne() throws Exception {
+ double[] array = new double[testArraysElementCount];
+ try {
+ doubleDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("doubleArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testDouble_arraycopy_dstPlusOne() throws Exception {
+ double[] array = new double[testArraysElementCount];
+ try {
+ doubleDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("doubleArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testDouble_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ double[] array = new double[testArraysElementCount];
+ double[] array2 = new double[testArraysElementCount];
+ doubleDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.doubleArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("doubleArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testDouble_arraycopy_removeLastElement() throws Exception {
+ double[] array = new double[testArraysElementCount];
+ double[] array2 = new double[testArraysElementCount];
+ doubleDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.doubleArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("doubleArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testDouble_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ double[] array = new double[testArraysElementCount];
+ double[] array2 = new double[testArraysElementCount];
+ doubleDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.doubleArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("doubleArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ public void testDouble_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ double[] array = new double[testArraysElementCount];
+ double[] array2 = new double[testArraysElementCount];
+ doubleDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.doubleArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("doubleArray with removed first element not equal",Arrays.equals(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testInteger_notNull() throws Exception {
+ assertNotNull("integerArray was not found.", integerDumpArray);
+ }
+
+ public void testInteger_isArray() throws Exception {
+ assertTrue("integerArray is not an array.",integerDumpArray.isArray());
+ }
+ public void testInteger_getArraySize() throws Exception {
+ assertEquals("integerArray is wrong size -> "+integerDumpArray.getArraySize(), integerDumpArray.getArraySize(), testArraysElementCount);
+ }
+
+ /**
+ * Compares that an array of JavaObject[]s is DTFJ's representation of an Integer[],
+ * and the passed Integer[] are equivalent.
+ *
+ * @param dump Array of DTFJ JavaObjects of type Integer
+ * @param real Integer[]
+ * @return true if arrays are equivalent
+ * @throws Exception
+ */
+ public boolean compareIntegerArrays(JavaObject[] dump, Integer[] real) throws Exception {
+
+ if ((real == null) & (dump == null)) {
+ return true;
+ }
+
+ if ((real == null) ^ (dump == null)) {
+ return false;
+ }
+
+ if (real.length != dump.length) {
+ return true;
+ }
+
+ // Step through both arrays, compare value in each.
+ for (int i =0; i < testArraysElementCount; i++) {
+ if (dump[i] == null && real[i] == null) {
+ continue;
+ } else if ((dump[i] == null) ^ (real[i] == null)) {
+ return false;
+ }
+
+ int value = valueField.getInt(dump[i]);
+
+ if(value != real[i].intValue()) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public void testinteger_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ integerDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testInteger_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(integerDumpArray);
+
+ try {
+ integerDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testInteger_arraycopy_simplecopy() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ integerDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("integerArray did not match.",compareIntegerArrays(array, theTestObject.integerArray));
+ }
+
+ public void testInteger_arraycopy_lengthPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ // copying too many elements...
+ try {
+ integerDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("integerArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInteger_arraycopy_srcPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ try {
+ integerDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("integerArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInteger_arraycopy_dstPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ try {
+ integerDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("integerArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testInteger_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ Integer[] array2 = new Integer[testArraysElementCount];
+ integerDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.integerArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("integerArray with removed first element not equal",compareIntegerArrays(array, array2));
+ }
+
+ public void testInteger_arraycopy_removeLastElement() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ Integer[] array2 = new Integer[testArraysElementCount];
+ integerDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.integerArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("integerArray with removed first element not equal",compareIntegerArrays(array, array2));
+ }
+
+ public void testInteger_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ Integer[] array2 = new Integer[testArraysElementCount];
+ integerDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.integerArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("integerArray with removed first element not equal",compareIntegerArrays(array, array2));
+ }
+
+ public void testInteger_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ Integer[] array2 = new Integer[testArraysElementCount];
+ integerDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.integerArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("integerArray with removed first element not equal",compareIntegerArrays(array, array2));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////////////////////
+ public void testArray_notNull() throws Exception {
+ assertNotNull("arrayArray was not found.", arrayDumpArray);
+ }
+
+ public void testArray_isArray() throws Exception {
+ assertTrue("arrayArray is not an array.", arrayDumpArray.isArray());
+ }
+ public void testArray_getArraySize() throws Exception {
+ assertEquals("arrayArray is wrong size -> "+arrayDumpArray.getArraySize(), arrayDumpArray.getArraySize(), testArraysElementCount);
+ }
+ public boolean compareShortArrayArrays(JavaObject[] dump, short[][] real) throws Exception {
+
+ if ((real == null) & (dump == null)) {
+ return true;
+ }
+
+ if ((real == null) ^ (dump == null)) {
+ return false;
+ }
+
+ if (real.length != dump.length) {
+ return true;
+ }
+
+ // Step through both arrays, compare value in each.
+ for (int i =0; i < testArraysElementCount; i++) {
+ JavaObject array = dump[i];
+
+ short[] shortArray = new short[testArraysElementCount];
+
+ if (array == null && real[i] == null) {
+ continue;
+ }
+ if ( array == null ^ real[i] == null) {
+ return false;
+ }
+
+ array.arraycopy(0, shortArray, 0, testArraysElementCount);
+
+ if (!Arrays.equals(shortArray, real[i])) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public void testArray_arraycopy_badDst() throws Exception {
+ String badDest = new String("Hello mum");
+ try {
+ arrayDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(IllegalArgumentException e) {
+ // This is correct
+ }
+ }
+
+ public void testArray_arraycopy_nullDst() throws Exception {
+ Object[] badDest = null;
+ assertNotNull(arrayDumpArray);
+
+ try {
+ arrayDumpArray.arraycopy(0, badDest, 0, testArraysElementCount);
+ fail("arraycopy to a String didn't throw IllegalArgumentException");
+ } catch(NullPointerException e) {
+ // This is correct
+ }
+ }
+
+ public void testArray_arraycopy_simplecopy() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ arrayDumpArray.arraycopy(0, array, 0, testArraysElementCount);
+ assertTrue("arrayArray did not match.",compareShortArrayArrays(array, theTestObject.arrayArray));
+ }
+
+ public void testArray_arraycopy_lengthPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ // copying too many elements...
+ try {
+ arrayDumpArray.arraycopy(0, array, 0, testArraysElementCount+1);
+ fail("arrayArray length+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testArray_arraycopy_srcPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ try {
+ arrayDumpArray.arraycopy(1, array, 0, testArraysElementCount);
+ fail("arrayArray length src+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testArray_arraycopy_dstPlusOne() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ try {
+ arrayDumpArray.arraycopy(0, array, 1, testArraysElementCount);
+ fail("arrayArray length dst+1 copy failed.");
+ } catch(IndexOutOfBoundsException e) {
+ // Expected.
+ }
+ }
+
+ public void testArray_arraycopy_removeFirstElement() throws Exception {
+ // remove first element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ short[][] array2 = new short[testArraysElementCount][];
+ arrayDumpArray.arraycopy(1, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.arrayArray, 1, array2, 1, testArraysElementCount-1);
+ assertTrue("arrayArray with removed first element not equal",compareShortArrayArrays(array, array2));
+ }
+
+ public void testArray_arraycopy_removeLastElement() throws Exception {
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ short[][] array2 = new short[testArraysElementCount][];
+
+ arrayDumpArray.arraycopy(0, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.arrayArray, 0, array2, 0, testArraysElementCount-1);
+ assertTrue("arrayArray with removed first element not equal", compareShortArrayArrays(array, array2));
+ }
+
+ public void testArray_arraycopy_shiftLeft() throws Exception {
+ // Shift left by one element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ short[][] array2 = new short[testArraysElementCount][];
+ arrayDumpArray.arraycopy(1, array, 0, testArraysElementCount-1);
+ System.arraycopy(theTestObject.arrayArray, 1, array2, 0, testArraysElementCount-1);
+ assertTrue("arrayArray with removed first element not equal",compareShortArrayArrays(array, array2));
+ }
+
+ public void testArray_arraycopy_shiftRight() throws Exception {
+ // Shift right by one element
+ JavaObject[] array = new JavaObject[testArraysElementCount];
+ short[][] array2 = new short[testArraysElementCount][];
+ arrayDumpArray.arraycopy(0, array, 1, testArraysElementCount-1);
+ System.arraycopy(theTestObject.arrayArray, 0, array2, 1, testArraysElementCount-1);
+ assertTrue("arrayArray with removed first element not equal",compareShortArrayArrays(array, array2));
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getDeclaredFields_getName.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptData;
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaHeap;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaObject_getDeclaredFields_getName;
+
+
+
+public class TestJavaObject_getDeclaredFields_getName extends TCKJavaRuntimeTestcase {
+
+
+
+ /**
+ *
+ */
+public void testJavaObject_get()
+ {
+ boolean foundObject = false;
+
+ JavaRuntime runtime=getJavaRuntime();
+
+ Iterator heaps = runtime.getHeaps().iterator();
+
+ while (heaps.hasNext()) {
+ Object nextHeap = heaps.next();
+ if (nextHeap instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextHeap + "'");
+ break;
+ }
+
+ JavaHeap aJavaHeap = (JavaHeap) nextHeap;
+ Iterator objects = aJavaHeap.getObjects().iterator();
+
+ while (objects.hasNext()) {
+ Object nextObject = objects.next();
+ if (nextObject instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextObject + "'");
+ break;
+ }
+
+ JavaObject aJavaObject = (JavaObject) nextObject;
+ try {
+ JavaClass theJavaClass = aJavaObject.getJavaClass();
+ String theClassName = (theJavaClass).getName();
+ if (theClassName.equals(SetupJavaObject_getDeclaredFields_getName.TestObjectClassName)){
+
+ Iterator fields = theJavaClass.getDeclaredFields().iterator();
+
+ while (fields.hasNext()) {
+ Object nextField = fields.next();
+
+ if (nextField instanceof CorruptData) {
+ System.err.println("returned CorruptData `" + nextField + "'");
+ break;
+ }
+
+ JavaField theField = (JavaField) nextField;
+ String theFieldName = theField.getName();
+ if (theFieldName.equals("JavaObject_getDeclaredFields_getName")){
+ foundObject=true;
+ }
+
+ }
+ }
+
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ assertTrue(foundObject);
+ }
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaObject_getReferences.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.image.MemoryAccessException;
+import javax.tools.diagnostics.runtime.java.JavaField;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+
+public class TestJavaObject_getReferences extends TCKJavaRuntimeTestcase {
+
+ public void testMultiDimensionalArrayReferences() {
+ try {
+ JavaObject thisObject = getScenerioReference();
+ JavaField multiDimArrayField = getJavaField(thisObject, "multiDimArray");
+ Object multiDimArrayObject = multiDimArrayField.get(thisObject);
+ if (multiDimArrayObject instanceof JavaObject) {
+ JavaObject mdObject = (JavaObject)multiDimArrayObject;
+ Iterator refs = mdObject.getReferences().iterator();
+ while (refs.hasNext()) {
+ Object next = refs.next();
+ if (next instanceof JavaReference) {
+ JavaReference ref = (JavaReference) next;
+ try {
+ Object target = ref.getTarget();
+ if (target instanceof JavaObject) {
+ JavaObject targetObject = (JavaObject) target;
+ System.out.println(targetObject.getJavaClass().getName());
+ }
+ System.out.println(ref.getDescription());
+ } catch (DataUnavailable e) {
+ e.printStackTrace();
+ }
+ } else {
+ fail ("Found reference which is NOT an instance of JavaReference.");
+ }
+ }
+ } else {
+ fail("Wrong object type for multiDimArray.");
+ }
+ } catch (CorruptDataException e) {
+ assertNotNull(e.getCorruptData());
+ //allowed by the API
+ } catch (MemoryAccessException mae) {
+ assertNotNull(mae.getPointer());
+ mae.printStackTrace();
+ }
+ }
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaReferences.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,262 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.runtime.java.JavaClass;
+import javax.tools.diagnostics.runtime.java.JavaClassLoader;
+import javax.tools.diagnostics.runtime.java.JavaObject;
+import javax.tools.diagnostics.runtime.java.JavaReference;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+public class TestJavaReferences extends TCKJavaRuntimeTestcase {
+
+
+ public void testReferences_getDescription() {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ assertNotNull("Reference description is null", ref.getDescription());
+ }
+ }
+
+ public void testReferences_getReachability() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (!(target instanceof JavaObject)) {
+ continue;
+ }
+ JavaObject targetObject = (JavaObject)target;
+ if ("java/lang/ref/WeakReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for weak referent different from \"Weak\"", JavaReference.REACHABILITY_WEAK == referent.getReachability());
+
+
+ } else if ("java/lang/ref/SoftReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for soft referent different from \"Soft\"", JavaReference.REACHABILITY_SOFT == referent.getReachability());
+
+ } else if ("java/lang/ref/PhantomReference".equals(targetObject.getJavaClass().getName())) {
+ JavaReference referent = getReferent(targetObject);
+ assertTrue("Reachability for phantom referent different from \"Phantom\"", JavaReference.REACHABILITY_PHANTOM == referent.getReachability());
+
+ } else if (targetObject.getJavaClass().getName().endsWith("StrongReferent")) {
+ assertTrue("Reachability for strong field reference different from \"Strong\"", JavaReference.REACHABILITY_STRONG == ref.getReachability());
+ }
+ }
+ }
+
+ public void testReferences_isClassReference() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (ref.isClassReference()) {
+ assertTrue("Supposed class reference has a non-JavaClass target",target instanceof JavaClass);
+ }
+ }
+
+ }
+
+ public void testReferences_isObjectReference() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ Object target = ref.getTarget();
+ if (ref.isObjectReference()) {
+ assertTrue("Supposed object reference has a non-JavaObject target",target instanceof JavaObject);
+ }
+ }
+
+ }
+
+ public void testReferences_getReferenceType() throws Exception {
+ JavaObject thisObj = getScenerioReference();
+ Iterator references = thisObj.getReferences().iterator();
+
+ while (references.hasNext()) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ int type = ref.getReferenceType();
+ Object source = ref.getSource();
+ Object target = ref.getTarget();
+
+ switch (type) {
+ case JavaReference.REFERENCE_FIELD:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a field reference not equal to this object.");
+ }
+
+ if (target instanceof JavaObject) {
+ JavaObject targetObject = (JavaObject)target;
+ String objectsClassName = targetObject.getJavaClass().getName();
+ if (!(objectsClassName.endsWith("Reference") ||
+ objectsClassName.endsWith("Referent") ||
+ objectsClassName.endsWith("ArrayElement;") ||
+ objectsClassName.endsWith("ClassLoader"))) {
+ fail("Unexpected field reference of type: "+ objectsClassName);
+ }
+ if (objectsClassName.endsWith("ArrayElement;") && targetObject.isArray()) {
+ //found the array field.
+ Iterator refs = targetObject.getReferences().iterator();
+ boolean arrayElementFound = false;
+ while (refs.hasNext()) {
+ Object next2 = refs.next();
+ if (!(next2 instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref2 = (JavaReference)next2;
+ int type2 = ref2.getReferenceType();
+ Object target2 = ref2.getTarget();
+
+ if (type2 == JavaReference.REFERENCE_ARRAY_ELEMENT) {
+ if (target2 instanceof JavaObject) {
+ JavaObject targetObject2 = (JavaObject)target2;
+ String objectsClassName2 = targetObject2.getJavaClass().getName();
+ if (objectsClassName2.endsWith("ArrayElement") && !targetObject2.isArray()) {
+ arrayElementFound = true;
+ }
+ } else {
+ fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
+ }
+ }
+ }
+ assertTrue("Array element reference not found.", arrayElementFound);
+ }
+
+ } else {
+ fail("Target object of a REFERENCE_ARRAY_ELEMENT reference has the wrong type.");
+ }
+
+ } else {
+ fail("Source object of a field reference is not a valid JavaObject.");
+ }
+ break;
+ case JavaReference.REFERENCE_CLASS:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a CLASS reference not equal to this object.");
+ }
+
+ if (!(target instanceof JavaClass)) {
+ fail("Target object for a CLASS reference not a JavaClass object.");
+ }
+ JavaClass targetClass = (JavaClass)target;
+ assertTrue("Target class for the CLASS reference of this object different from expected.", targetClass.getName().endsWith("TestJavaReferences"));
+ Iterator refs = targetClass.getReferences().iterator();
+ boolean classLoaderFound = false;
+ while (refs.hasNext()) {
+ Object next2 = refs.next();
+ if (!(next2 instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref2 = (JavaReference)next2;
+ int type2 = ref2.getReferenceType();
+ Object target2 = ref2.getTarget();
+
+ if (type2 == JavaReference.REFERENCE_CLASS_LOADER) {
+ if (!(target2 instanceof JavaObject)) {
+ fail("Target object for a CLASSLOADER reference does not represent a JavaObject.");
+ }
+ JavaObject targetObject2 = (JavaObject)target2;
+ if (targetObject2.getClass().getName().endsWith("ClassLoader")) {
+ fail("Target object for a CLASSLOADER reference does not represent a ClassLoader.");
+ } else {
+ classLoaderFound = true;
+ }
+ }
+ }
+ assertTrue("ClassLoader reference not found.", classLoaderFound);
+
+ } else {
+ fail("Source object of a CLASS reference is not a valid JavaObject.");
+ }
+ break;
+ case JavaReference.REFERENCE_CLASS_LOADER:
+ if (source instanceof JavaObject) {
+ JavaObject sourceObject = (JavaObject)source;
+ if (!(sourceObject.equals(thisObj))) {
+ fail("Source object for a CLASSLOADER reference not equal to this object.");
+ }
+
+ if (!(target instanceof JavaClassLoader)) {
+ fail("Target object for a CLASSLOADER reference not a JavaClass object.");
+ }
+ } else {
+ fail("Source object of a CLASS reference is not a valid JavaObject.");
+ }
+ break;
+
+ }
+ }
+
+ }
+
+
+ private JavaReference getReferent (JavaObject obj) {
+ Iterator references = obj.getReferences().iterator();
+ JavaReference referent = null;
+ while (references.hasNext() && referent == null) {
+ Object next = references.next();
+ if (!(next instanceof JavaReference)) {
+ continue;
+ }
+ JavaReference ref = (JavaReference)next;
+ String description = ref.getDescription();
+ if (description.indexOf("referent") == -1) {
+ continue;
+ }
+ referent = ref;
+ }
+ return referent;
+
+ }
+
+
+}
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.image.DataUnavailable;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaVMInitArgs;
+import javax.tools.diagnostics.runtime.java.JavaVMOption;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntime;
+
+
+/**
+ *
+ *
+ */
+public class TestJavaRuntime extends TCKJavaRuntimeTestcase {
+
+
+ public void testJavaJavaRuntime_getVersion() throws CorruptDataException, DataUnavailable
+ {
+
+ JavaRuntime runtime=getJavaRuntime();
+ String version=runtime.getVersion();
+ System.out.println("runtime.getVersion "+version);
+ assertNotNull(version);
+ }
+
+ public void testJavaJavaRuntime_getVersionDetail() throws CorruptDataException, DataUnavailable
+ {
+
+ JavaRuntime runtime=getJavaRuntime();
+ String version=runtime.getVersion();
+
+
+ JavaVMInitArgs args=runtime.getJavaVMInitArgs();
+ Iterator i=args.getOptions().iterator();
+ while(i.hasNext()) {
+ JavaVMOption option=(JavaVMOption) i.next();
+ String data=option.getOptionString();
+ if(data.startsWith(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION)) {
+ String received=data.substring(SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION.length());
+ assertTrue(version.indexOf(received) != -1);
+ return; // test passed
+ }
+
+ }
+
+ fail("expected to see vm option for system property starting "+SetupJavaRuntime.DTCK_TEST_RUNTIME_VERSION);
+ }
+
+ public void testJavaRuntime_getFullVersion()
+ {
+ JavaRuntime runtime=(JavaRuntime) getJavaRuntime();
+ String theFV=null;
+ try {
+ theFV=runtime.getFullVersion();
+ } catch (CorruptDataException e) {
+ fail();
+ }
+ assertNotNull(theFV);
+ assertTrue(theFV.length() > 0);
+ }
+
+
+}
+
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntimeThreads.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,164 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaLocation;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+import javax.tools.diagnostics.runtime.java.JavaStackFrame;
+import javax.tools.diagnostics.runtime.java.JavaThread;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+import org.apache.kato.tck.scenario142.javaruntime.SetupJavaRuntimeThreads;
+
+
+/**
+ *
+ *
+ */
+public class TestJavaRuntimeThreads extends TCKJavaRuntimeTestcase {
+
+ /**
+ * Test has at least one thread
+ *
+ */
+
+ public void testHasThreads() {
+
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator threadIterator=runtime.getThreads().iterator();
+ assertNotNull(threadIterator);
+ assertTrue(threadIterator.hasNext());
+
+
+ }
+
+
+ /**
+ * Test has configured threads
+ * @throws CorruptDataException
+ *
+ */
+
+ public void testHasExpectedThreads() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1));
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T2));
+ assertNotNull(getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T3));
+
+ }
+
+ public void testExpectedThreadState() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ int state=t1.getState();
+ assertEquals(JavaThread.STATE_ALIVE | JavaThread.STATE_WAITING | JavaThread.STATE_SLEEPING,state);
+
+ }
+
+ public void testHasThreadStack() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ assertTrue(i.hasNext());
+
+
+ }
+ public void testThreadStackFrameLocation() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ assertNotNull(location);
+
+
+ }
+ public void testThreadStackFrameLocationMethod() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ JavaMethod method=location.getMethod();
+ assertNotNull(method);
+
+
+ }
+public void testThreadStackFrameLocationMethodName() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+
+ JavaThread t1=getThread(allThreads,SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+ Iterator i=t1.getStackFrames().iterator();
+ JavaStackFrame frame=(JavaStackFrame) i.next();
+ JavaLocation location=frame.getLocation();
+ JavaMethod method=location.getMethod();
+ String name=method.getName();
+ assertEquals(name,"sleep");
+
+
+
+ }
+
+ private List getThreads() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator threadIterator=runtime.getThreads().iterator();
+
+ List allThreads=new LinkedList();
+
+ while(threadIterator.hasNext()) {
+ JavaThread thread=(JavaThread) threadIterator.next();
+ allThreads.add(thread);
+ }
+ return allThreads;
+ }
+
+
+ public void testThreadGroupMembership() throws CorruptDataException {
+
+ List allThreads = getJavaRuntime().getThreads();
+ JavaThread t1=getThread(allThreads, SetupJavaRuntimeThreads.DTFJ_TCK_T1);
+
+
+ }
+ private JavaThread getThread(List allThreads, String threadname) throws CorruptDataException {
+
+ Iterator i=allThreads.iterator();
+ while(i.hasNext()) {
+ JavaThread thread=(JavaThread) i.next();
+ String name=thread.getName();
+ if(name.equals(threadname)) return thread;
+ }
+ return null;
+ }
+
+
+}
+
Added: incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java?rev=883669&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java (added)
+++ incubator/kato/trunk/org.apache.kato/kato.tck/src/test/java/org/apache/kato/tck/tests/javaruntime/TestJavaRuntime_getCompiledMethods.java Tue Nov 24 12:27:01 2009
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * 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 org.apache.kato.tck.tests.javaruntime;
+
+import java.util.Iterator;
+
+import javax.tools.diagnostics.image.CorruptDataException;
+import javax.tools.diagnostics.runtime.java.JavaMethod;
+import javax.tools.diagnostics.runtime.java.JavaRuntime;
+
+import org.apache.kato.tck.harness.TCKJavaRuntimeTestcase;
+
+
+public class TestJavaRuntime_getCompiledMethods extends TCKJavaRuntimeTestcase {
+ public void testHasCompiledMethods() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator compiledMethods=runtime.getCompiledMethods().iterator();
+ assertNotNull(compiledMethods);
+ assertTrue(compiledMethods.hasNext());
+ }
+
+ public void testConfiguredCompiledMethods() {
+ JavaRuntime runtime=getJavaRuntime();
+ Iterator compiledMethods=runtime.getCompiledMethods().iterator();
+ boolean found = false;
+ while (compiledMethods.hasNext() && !found) {
+ Object next = compiledMethods.next();
+ if (!(next instanceof JavaMethod)) {
+ continue;
+ }
+ JavaMethod method = (JavaMethod)next;
+ try {
+ String methodName = method.getName();
+ // System.out.println("Current method is: "+ methodName);
+ if ("jitMe".equals(methodName)) {
+ return;
+ }
+ } catch (CorruptDataException cde) {
+ assertNotNull(cde.getCorruptData());
+ continue;
+ }
+ }
+ fail("Compiled method not found");
+ }
+}