summaryrefslogtreecommitdiffstats
path: root/test/011-array-copy/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/011-array-copy/src')
-rw-r--r--test/011-array-copy/src/Iface1.java13
-rw-r--r--test/011-array-copy/src/Iface2.java9
-rw-r--r--test/011-array-copy/src/ImplA.java14
-rw-r--r--test/011-array-copy/src/Main.java146
4 files changed, 182 insertions, 0 deletions
diff --git a/test/011-array-copy/src/Iface1.java b/test/011-array-copy/src/Iface1.java
new file mode 100644
index 0000000..ba17d45
--- /dev/null
+++ b/test/011-array-copy/src/Iface1.java
@@ -0,0 +1,13 @@
+// Copyright 2005 The Android Open Source Project
+
+/**
+ * Test stuff.
+ */
+public interface Iface1 {
+
+ public int iFunc1(int ii);
+
+ public float mFloaty = 5.0f;
+
+ public String mWahoo = new String("wahoo");
+}
diff --git a/test/011-array-copy/src/Iface2.java b/test/011-array-copy/src/Iface2.java
new file mode 100644
index 0000000..83fe650
--- /dev/null
+++ b/test/011-array-copy/src/Iface2.java
@@ -0,0 +1,9 @@
+// Copyright 2006 The Android Open Source Project
+
+/**
+ * Another interface.
+ */
+public interface Iface2 {
+
+ public int iFunc2(int ii);
+}
diff --git a/test/011-array-copy/src/ImplA.java b/test/011-array-copy/src/ImplA.java
new file mode 100644
index 0000000..9007001
--- /dev/null
+++ b/test/011-array-copy/src/ImplA.java
@@ -0,0 +1,14 @@
+// Copyright 2006 The Android Open Source Project
+
+/**
+ * Blah.
+ */
+public class ImplA implements Iface1, Iface2 {
+
+ public int iFunc1(int ii) {
+ return ii+1;
+ }
+ public int iFunc2(int ii) {
+ return ii+2;
+ }
+}
diff --git a/test/011-array-copy/src/Main.java b/test/011-array-copy/src/Main.java
new file mode 100644
index 0000000..505d8b0
--- /dev/null
+++ b/test/011-array-copy/src/Main.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * 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.
+ */
+
+import java.util.Arrays;
+
+/**
+ * System.arraycopy cases
+ */
+public class Main {
+ public static void main(String args[]) {
+ testObjectCopy();
+ testOverlappingMoves();
+ }
+
+ public static void testObjectCopy() {
+ String[] stringArray = new String[8];
+ Object[] objectArray = new Object[8];
+
+ for (int i = 0; i < stringArray.length; i++)
+ stringArray[i] = new String(Integer.toString(i));
+
+ System.out.println("string -> object");
+ System.arraycopy(stringArray, 0, objectArray, 0, stringArray.length);
+ System.out.println("object -> string");
+ System.arraycopy(objectArray, 0, stringArray, 0, stringArray.length);
+ System.out.println("object -> string (modified)");
+ objectArray[4] = new ImplA();
+ try {
+ System.arraycopy(objectArray, 0, stringArray, 0,stringArray.length);
+ }
+ catch (ArrayStoreException ase) {
+ System.out.println("caught ArrayStoreException (expected)");
+ }
+ }
+
+ static final int ARRAY_SIZE = 8;
+
+ static void initByteArray(byte[] array) {
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ array[i] = (byte) i;
+ }
+ }
+ static void initShortArray(short[] array) {
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ array[i] = (short) i;
+ }
+ }
+ static void initIntArray(int[] array) {
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ array[i] = (int) i;
+ }
+ }
+ static void initLongArray(long[] array) {
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ array[i] = (long) i;
+ }
+ }
+
+ /*
+ * Perform an array copy operation on primitive arrays with different
+ * element widths.
+ */
+ static void makeCopies(int srcPos, int dstPos, int length) {
+ byte[] byteArray = new byte[ARRAY_SIZE];
+ short[] shortArray = new short[ARRAY_SIZE];
+ int[] intArray = new int[ARRAY_SIZE];
+ long[] longArray = new long[ARRAY_SIZE];
+
+ initByteArray(byteArray);
+ initShortArray(shortArray);
+ initIntArray(intArray);
+ initLongArray(longArray);
+
+ System.arraycopy(byteArray, srcPos, byteArray, dstPos, length);
+ System.arraycopy(shortArray, srcPos, shortArray, dstPos, length);
+ System.arraycopy(intArray, srcPos, intArray, dstPos, length);
+ System.arraycopy(longArray, srcPos, longArray, dstPos, length);
+
+ for (int i = 0; i < ARRAY_SIZE; i++) {
+ if (intArray[i] != byteArray[i]) {
+ System.out.println("mismatch int vs byte at " + i + " : " +
+ Arrays.toString(byteArray));
+ break;
+ } else if (intArray[i] != shortArray[i]) {
+ System.out.println("mismatch int vs short at " + i + " : " +
+ Arrays.toString(shortArray));
+ break;
+ } else if (intArray[i] != longArray[i]) {
+ System.out.println("mismatch int vs long at " + i + " : " +
+ Arrays.toString(longArray));
+ break;
+ }
+ }
+
+ System.out.println("copy: " + srcPos + "," + dstPos + "," + length +
+ ": " + Arrays.toString(intArray));
+ }
+
+ public static void testOverlappingMoves() {
+ /* do nothing */
+ makeCopies(0, 0, 0);
+
+ /* do more nothing */
+ makeCopies(0, 0, ARRAY_SIZE);
+
+ /* copy forward, even alignment */
+ makeCopies(0, 2, 4);
+
+ /* copy backward, even alignment */
+ makeCopies(2, 0, 4);
+
+ /* copy forward, odd alignment */
+ makeCopies(1, 3, 4);
+
+ /* copy backward, odd alignment */
+ makeCopies(3, 1, 4);
+
+ /* copy backward, odd length */
+ makeCopies(3, 1, 5);
+
+ /* copy forward, odd length */
+ makeCopies(1, 3, 5);
+
+ /* copy forward, mixed alignment */
+ makeCopies(0, 3, 5);
+
+ /* copy backward, mixed alignment */
+ makeCopies(3, 0, 5);
+
+ /* copy forward, mixed alignment, trivial length */
+ makeCopies(0, 5, 1);
+ }
+}