Package org.apache.kato.tck.scenario142.javaruntime

Source Code of org.apache.kato.tck.scenario142.javaruntime.TestJavaObject_arraycopy

/*******************************************************************************
* 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.scenario142.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));   
  }

}
TOP

Related Classes of org.apache.kato.tck.scenario142.javaruntime.TestJavaObject_arraycopy

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.