summaryrefslogtreecommitdiffstats
path: root/test/407-arrays
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-07-23 16:04:16 +0100
committerNicolas Geoffray <ngeoffray@google.com>2014-07-28 15:44:28 +0100
commit3c7bb98698f77af10372cf31824d3bb115d9bf0f (patch)
tree1cd4cc18babfbb16ab908f23929fa88d7678f06b /test/407-arrays
parent98cc1e552c2ccbe5d51bc81d49e79119280f5416 (diff)
downloadart-3c7bb98698f77af10372cf31824d3bb115d9bf0f.tar.gz
art-3c7bb98698f77af10372cf31824d3bb115d9bf0f.tar.bz2
art-3c7bb98698f77af10372cf31824d3bb115d9bf0f.zip
Implement array get and array put in optimizing.
Also fix a couple of assembler/disassembler issues. Change-Id: I705c8572988c1a9c4df3172b304678529636d5f6
Diffstat (limited to 'test/407-arrays')
-rw-r--r--test/407-arrays/expected.txt0
-rw-r--r--test/407-arrays/info.txt1
-rw-r--r--test/407-arrays/src/Main.java127
-rw-r--r--test/407-arrays/src/TestCase.java199
4 files changed, 327 insertions, 0 deletions
diff --git a/test/407-arrays/expected.txt b/test/407-arrays/expected.txt
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/407-arrays/expected.txt
diff --git a/test/407-arrays/info.txt b/test/407-arrays/info.txt
new file mode 100644
index 0000000000..f30b6674c2
--- /dev/null
+++ b/test/407-arrays/info.txt
@@ -0,0 +1 @@
+Simple tests for array accesses.
diff --git a/test/407-arrays/src/Main.java b/test/407-arrays/src/Main.java
new file mode 100644
index 0000000000..5d27e6dbde
--- /dev/null
+++ b/test/407-arrays/src/Main.java
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+// Simple test for array accesses.
+
+public class Main extends TestCase {
+ public static void main(String[] args) {
+ $opt$testReads(new boolean[1], new byte[1], new char[1], new short[1],
+ new int[1], new Object[1], new long[1], 0);
+ $opt$testWrites(new boolean[2], new byte[2], new char[2], new short[2],
+ new int[2], new Object[2], new long[2], 1);
+ ensureThrows(new boolean[2], 2);
+ ensureThrows(new boolean[2], 4);
+ ensureThrows(new boolean[2], -1);
+ ensureThrows(new boolean[2], Integer.MIN_VALUE);
+ ensureThrows(new boolean[2], Integer.MAX_VALUE);
+ }
+
+ static void $opt$testReads(boolean[] bools, byte[] bytes, char[] chars, short[] shorts,
+ int[] ints, Object[] objects, long[] longs, int index) {
+ assertEquals(false, bools[0]);
+ assertEquals(false, bools[index]);
+
+ assertEquals(0, bytes[0]);
+ assertEquals(0, bytes[index]);
+
+ assertEquals(0, chars[0]);
+ assertEquals(0, chars[index]);
+
+ assertEquals(0, shorts[0]);
+ assertEquals(0, shorts[index]);
+
+ assertEquals(0, ints[0]);
+ assertEquals(0, ints[index]);
+
+ assertNull(objects[0]);
+ assertNull(objects[index]);
+
+ assertEquals(0, longs[0]);
+ assertEquals(0, longs[index]);
+ }
+
+ static void $opt$testWrites(boolean[] bools, byte[] bytes, char[] chars, short[] shorts,
+ int[] ints, Object[] objects, long[] longs, int index) {
+ bools[0] = true;
+ assertEquals(true, bools[0]);
+ bools[1] = true;
+ assertEquals(true, bools[index]);
+
+ bytes[0] = -4;
+ assertEquals(-4, bytes[0]);
+ bytes[index] = -8;
+ assertEquals(-8, bytes[index]);
+
+ chars[0] = 'c';
+ assertEquals('c', chars[0]);
+ chars[index] = 'd';
+ assertEquals('d', chars[index]);
+
+ shorts[0] = -42;
+ assertEquals(-42, shorts[0]);
+ shorts[index] = -84;
+ assertEquals(-84, shorts[index]);
+
+ ints[0] = -32;
+ assertEquals(-32, ints[0]);
+ ints[index] = -64;
+ assertEquals(-64, ints[index]);
+
+ Object o1 = new Object();
+ objects[0] = o1;
+ assertEquals(o1, objects[0]);
+ Object o2 = new Object();
+ objects[index] = o2;
+ assertEquals(o2, objects[index]);
+
+ long l = -21876876876876876L;
+ longs[0] = l;
+ assertEquals(l, longs[0]);
+ l = -21876876876876877L;
+ longs[index] = l;
+ assertEquals(l, longs[index]);
+ }
+
+ public static void ensureThrows(boolean[] array, int index) {
+ ArrayIndexOutOfBoundsException exception = null;
+ try {
+ $opt$doArrayLoad(array, index);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exception = e;
+ }
+
+ assertNotNull(exception);
+ assertTrue(exception.toString().contains(Integer.toString(index)));
+
+ exception = null;
+ try {
+ $opt$doArrayStore(array, index);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exception = e;
+ }
+
+ assertNotNull(exception);
+ assertTrue(exception.toString().contains(Integer.toString(index)));
+ }
+
+ public static void $opt$doArrayLoad(boolean[] array, int index) {
+ boolean res = array[index];
+ }
+
+ public static void $opt$doArrayStore(boolean[] array, int index) {
+ array[index] = false;
+ }
+}
diff --git a/test/407-arrays/src/TestCase.java b/test/407-arrays/src/TestCase.java
new file mode 100644
index 0000000000..ef77f71f3f
--- /dev/null
+++ b/test/407-arrays/src/TestCase.java
@@ -0,0 +1,199 @@
+/*
+ * Copyright (C) 2014 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.
+ */
+
+/**
+ * Common superclass for test cases.
+ */
+
+import java.util.Arrays;
+
+public abstract class TestCase {
+ public static void assertSame(Object expected, Object value) {
+ if (expected != value) {
+ throw new AssertionError("Objects are not the same: expected " +
+ String.valueOf(expected) + ", got " + String.valueOf(value));
+ }
+ }
+
+ public static void assertNotSame(Object expected, Object value) {
+ if (expected == value) {
+ throw new AssertionError(
+ "Objects are the same: " + String.valueOf(expected));
+ }
+ }
+
+ public static void assertEquals(String message, int expected, int actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(int expected, int actual) {
+ if (expected != actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertTrue(String message, boolean condition) {
+ if (!condition) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertTrue(boolean condition) {
+ assertTrue("Expected true", condition);
+ }
+
+ public static void assertFalse(String message, boolean condition) {
+ if (condition) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertFalse(boolean condition) {
+ assertFalse("Expected false", condition);
+ }
+
+ public static void assertEquals(Object expected, Object actual) {
+ if (!expected.equals(actual)) {
+ String msg = "Expected \"" + expected + "\" but got \"" + actual + "\"";
+ throw new AssertionError(msg);
+ }
+ }
+
+ public static void assertNotEquals(int expected, int actual) {
+ if (expected == actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertNotEquals(Object expected, Object actual) {
+ if (expected.equals(actual)) {
+ String msg = "Objects are the same: " + String.valueOf(expected);
+ throw new AssertionError(msg);
+ }
+ }
+
+ public static <T> void assertArrayEquals(T[] actual, T... expected) {
+ assertTrue(Arrays.equals(expected, actual));
+ }
+
+ public static void assertEquals(
+ String message, Object expected, Object actual) {
+ if (!expected.equals(actual)) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(
+ String message, long expected, long actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(long expected, long actual) {
+ if (expected != actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertEquals(
+ String message, boolean expected, boolean actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(boolean expected, boolean actual) {
+ if (expected != actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertEquals(
+ String message, float expected, float actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(float expected, float actual) {
+ if (expected != actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertEquals(float expected, float actual,
+ float tolerance) {
+ if ((actual < expected - tolerance) || (expected + tolerance < actual)) {
+ throw new AssertionError("Expected " + expected + " got " + actual +
+ " tolerance " + tolerance);
+ }
+ }
+
+ public static void assertEquals(
+ String message, double expected, double actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertEquals(double expected, double actual) {
+ if (expected != actual) {
+ throw new AssertionError("Expected " + expected + " got " + actual);
+ }
+ }
+
+ public static void assertEquals(double expected, double actual,
+ double tolerance) {
+ if ((actual < expected - tolerance) || (expected + tolerance < actual)) {
+ throw new AssertionError("Expected " + expected + " got " + actual +
+ " tolerance " + tolerance);
+ }
+ }
+
+ public static void assertSame(
+ String message, Object expected, Object actual) {
+ if (expected != actual) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertNull(String message, Object object) {
+ if (object != null) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertNull(Object object) {
+ assertNull("Expected null", object);
+ }
+
+ public static void assertNotNull(String message, Object object) {
+ if (object == null) {
+ throw new AssertionError(message);
+ }
+ }
+
+ public static void assertNotNull(Object object) {
+ assertNotNull("Expected non-null", object);
+ }
+
+ public static void fail(String msg) {
+ throw new AssertionError(msg);
+ }
+}