summaryrefslogtreecommitdiffstats
path: root/jack-tests/tests/com/android/jack/cast
diff options
context:
space:
mode:
Diffstat (limited to 'jack-tests/tests/com/android/jack/cast')
-rw-r--r--jack-tests/tests/com/android/jack/cast/explicit001/dx/Tests.java86
-rw-r--r--jack-tests/tests/com/android/jack/cast/explicit001/jack/Data.java120
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit001/dx/Tests.java165
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit001/jack/Data.java132
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit002/dx/Tests.java59
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit002/jack/Data.java52
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit003/dx/Tests.java49
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit003/jack/Data.java30
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit004/dx/Tests.java86
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit004/jack/Data.java59
-rw-r--r--jack-tests/tests/com/android/jack/cast/implicit005/jack/Data.java30
-rw-r--r--jack-tests/tests/com/android/jack/cast/useless001/dx/Tests.java59
-rw-r--r--jack-tests/tests/com/android/jack/cast/useless001/jack/Data.java79
-rw-r--r--jack-tests/tests/com/android/jack/cast/useless002/dx/Tests.java35
-rw-r--r--jack-tests/tests/com/android/jack/cast/useless002/jack/UselessCast.java32
-rw-r--r--jack-tests/tests/com/android/jack/cast/useless003/jack/UselessCast.java31
16 files changed, 1104 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/cast/explicit001/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/explicit001/dx/Tests.java
new file mode 100644
index 0000000..a6b04ce
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/explicit001/dx/Tests.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.explicit001.dx;
+
+import com.android.jack.cast.explicit001.jack.Data;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * Tests about casts.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Object stringValue = "stringValue";
+ String string = "string";
+ Object object = new Object();
+ testByteValue((byte)159);
+ testByteValue((byte)0);
+ testByteValue((byte)-1);
+ testByteValue(Byte.MAX_VALUE);
+ testByteValue(Byte.MIN_VALUE);
+
+ testLongValue(214356475546l);
+ testLongValue(-1l);
+ testLongValue(0l);
+ testLongValue(Long.MAX_VALUE);
+ testLongValue(Long.MIN_VALUE);
+
+ testFloatValue((float) 0.0);
+ testFloatValue(-1);
+ testFloatValue((float) 158753.1574);
+ testFloatValue(Float.MAX_VALUE);
+ testFloatValue(Float.MIN_VALUE);
+
+ Assert.assertEquals((String) stringValue, Data.objectToString(stringValue));
+ Assert.assertEquals((String) string, Data.stringToString(string));
+ Assert.assertEquals((Object) object, Data.objectToObject(object));
+ }
+
+ private void testLongValue(long longValue) {
+ Assert.assertEquals((byte) longValue, Data.longToByte(longValue));
+ Assert.assertEquals((char) longValue, Data.longToChar(longValue));
+ Assert.assertEquals((short) longValue, Data.longToShort(longValue));
+ Assert.assertEquals((int) longValue, Data.longToInt(longValue));
+ Assert.assertEquals((long) longValue, Data.longToLong(longValue));
+ Assert.assertEquals((float) longValue, Data.longToFloat(longValue), 0.0);
+ Assert.assertEquals((double) longValue, Data.longToDouble(longValue), 0.0);
+ }
+
+ private void testFloatValue(float value) {
+ Assert.assertEquals((byte) value, Data.floatToByte(value));
+ Assert.assertEquals((char) value, Data.floatToChar(value));
+ Assert.assertEquals((short) value, Data.floatToShort(value));
+ Assert.assertEquals((int) value, Data.floatToInt(value));
+ Assert.assertEquals((long) value, Data.floatToLong(value));
+ Assert.assertEquals((float) value, Data.floatToFloat(value), 0.0);
+ Assert.assertEquals((double) value, Data.floatToDouble(value), 0.0);
+ }
+
+ private void testByteValue(byte byteValue) {
+ Assert.assertEquals((byte) byteValue, Data.byteToByte(byteValue));
+ Assert.assertEquals((short) byteValue, Data.byteToShort(byteValue));
+ Assert.assertEquals((char) byteValue, Data.byteToChar(byteValue));
+ Assert.assertEquals((int) byteValue, Data.byteToInt(byteValue));
+ Assert.assertEquals((long) byteValue, Data.byteToLong(byteValue));
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/cast/explicit001/jack/Data.java b/jack-tests/tests/com/android/jack/cast/explicit001/jack/Data.java
new file mode 100644
index 0000000..2d189d9
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/explicit001/jack/Data.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.explicit001.jack;
+
+public class Data {
+
+ public static char byteToChar(byte value) {
+ return (char) value;
+ }
+
+ public static byte byteToByte(byte value) {
+ return (byte) value;
+ }
+
+ public static short byteToShort(byte value) {
+ return (short) value;
+ }
+
+ public static int byteToInt(byte value) {
+ return (int) value;
+ }
+
+ public static long byteToLong(byte value) {
+ return (long) value;
+ }
+
+ public static int charToInt(char value) {
+ return (int) value;
+ }
+
+ public static int shortToInt(short value) {
+ return (int) value;
+ }
+
+ public static byte longToByte(long value) {
+ return (byte) value;
+ }
+
+ public static char longToChar(long value) {
+ return (char) value;
+ }
+
+ public static short longToShort(long value) {
+ return (short) value;
+ }
+
+ public static int longToInt(long value) {
+ return (int) value;
+ }
+
+ public static long longToLong(long value) {
+ return (long) value;
+ }
+
+ public static float longToFloat(long value) {
+ return (float) value;
+ }
+
+ public static double longToDouble(long value) {
+ return (double) value;
+ }
+
+ public static byte floatToByte(float value) {
+ return (byte) value;
+ }
+
+ public static short floatToShort(float value) {
+ return (short) value;
+ }
+
+ public static char floatToChar(float value) {
+ return (char) value;
+ }
+
+ public static int floatToInt(float value) {
+ return (int) value;
+ }
+
+ public static long floatToLong(float value) {
+ return (long) value;
+ }
+
+ public static float floatToFloat(float value) {
+ return (float) value;
+ }
+
+ public static double floatToDouble(float value) {
+ return (double) value;
+ }
+
+ public static int doubleToInt(double value) {
+ return (int) value;
+ }
+
+ public static String objectToString(Object value) {
+ return (String) value;
+ }
+
+ public static String stringToString(String value) {
+ return (String) value;
+ }
+
+ public static Object objectToObject(Object value) {
+ return (Object) value;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit001/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/implicit001/dx/Tests.java
new file mode 100644
index 0000000..9202eb5
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit001/dx/Tests.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit001.dx;
+
+
+import com.android.jack.cast.implicit001.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about arithmetic.
+ */
+public class Tests {
+
+ @SuppressWarnings("cast")
+ @Test
+ public void test1() {
+ Assert.assertEquals((float) 27, Data.returnFloat(27), 0.0);
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void test2() {
+ Assert.assertEquals((double) (27 + 54), Data.addDouble(27, 54), 0.0);
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void test3() {
+ Assert.assertEquals((double) (27 + 58.1), Data.addDouble(27, 58.1), 0.0);
+ }
+
+ @Test
+ public void test4() {
+ Assert.assertEquals( 59 + ((double) 59), Data.assignDouble(59), 0.0);
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void test5() {
+ Assert.assertEquals( (float)(31 + 65), Data.addFloat(31, 65), 0.0);
+ }
+
+ @Test
+ public void test6() {
+ Assert.assertEquals( 31 + 67L, Data.addLong(31, 67L));
+ }
+
+ @Test
+ public void test7() {
+ Assert.assertEquals( 31 + (long) 67, Data.addIntWithCall(31, 67));
+ }
+
+ @Test
+ public void test8() {
+ Assert.assertEquals( (byte)(((byte) 31) + ((byte) -1)), Data.addByte((byte) 31, (byte) -1));
+ }
+
+ @Test
+ public void test9() {
+ Assert.assertEquals(3, Data.addByte());
+ }
+
+ @Test
+ public void test10() {
+ Assert.assertEquals(~(167L), Data.not(167L));
+ }
+
+ @Test
+ public void test11() {
+ Assert.assertEquals(~((byte) -1), Data.not((byte) -1));
+ }
+
+ @Test
+ public void test12() {
+ Assert.assertEquals(-((byte) -1), Data.minus((byte) -1));
+ }
+
+ @Test
+ public void test13() {
+ Assert.assertEquals(-(-3L), Data.minus(-3L));
+ }
+
+ @Test
+ public void test14() {
+ Assert.assertEquals(-(-30.5), Data.minus(-30.5), 0.0);
+ }
+
+ @Test
+ public void test15() {
+ Assert.assertEquals(-((char)1587469), Data.minus((char) 1587469));
+ }
+
+ @SuppressWarnings("cast")
+ @Test
+ public void test16() {
+ Assert.assertEquals((double)(-((char) 1587467)), Data.minusDouble((char) 1587467), 0.0);
+ }
+
+ @Test
+ public void test17() {
+ Assert.assertEquals(75896L >> 1258632157456L, Data.shr(75896L, 1258632157456L));
+ }
+
+ @Test
+ public void test18() {
+ Assert.assertEquals(75896L >> (byte) 1258632157, Data.shr(75896L, (byte) 1258632157));
+ }
+
+ @Test
+ public void test19() {
+ int[] array = {-2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
+ Assert.assertEquals(array[(byte) 7], Data.arrayAccess(array, (byte) 7));
+ }
+
+ @Test
+ public void test20() {
+ Assert.assertEquals(31 + (long) 67, Data.addByteWithCall((byte) 31, (byte) 67));
+ }
+
+ @Test
+ public void test21() {
+ String s = "2 1";
+ Assert.assertEquals(s, Data.getObjectFromString(s));
+ }
+
+ @Test
+ public void test22() {
+ double value = 57859423453465456.0;
+ Assert.assertEquals(value, Data.inc(value), 0.0);
+ }
+
+ @Test
+ public void test23() {
+ byte value = 127;
+ Assert.assertEquals(value, Data.incPost(value));
+ }
+
+ @Test
+ public void test24() {
+ byte value = 127;
+ byte valueRef = value;
+ Assert.assertEquals(++ valueRef, Data.incPre(value));
+ }
+
+ @Test
+ public void test25() {
+ Assert.assertEquals(-1, Data.setByteArray());
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit001/jack/Data.java b/jack-tests/tests/com/android/jack/cast/implicit001/jack/Data.java
new file mode 100644
index 0000000..206af28
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit001/jack/Data.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit001.jack;
+
+public class Data {
+
+ public static float returnFloat(int a) {
+ return a;
+ }
+
+ public static double assignDouble(int a) {
+ double d = a;
+ return addDouble(a, d);
+ }
+
+ public static double addDouble(int a, int b) {
+ return a + b;
+ }
+
+ public static double addDouble(int a, double b) {
+ return a + b;
+ }
+
+ public static float addFloat(int a, long b) {
+ return a + b;
+ }
+
+ public static long addIntWithCall(int a, int b) {
+ return addLong(a, b);
+ }
+
+ public static long addByteWithCall(byte a, byte b) {
+ return addLong(a, b);
+ }
+
+ public static long addLong(int a, long b) {
+ return a + b;
+ }
+
+ public static byte addByte(byte a, byte b) {
+ byte c = (byte) (a + b);
+ return c;
+ }
+
+
+ public static byte addByte() {
+ byte a = 1;
+ byte b = 2;
+ a += b;
+ return a;
+ }
+
+ public static int not(byte value) {
+ return ~value;
+ }
+
+ public static long not(long value) {
+ return ~value;
+ }
+
+ public static int minus(byte value) {
+ return -value;
+ }
+
+ public static long minus(long value) {
+ return -value;
+ }
+
+ public static double minus(double value) {
+ return -value;
+ }
+
+ public static int minus(char value) {
+ return -value;
+ }
+
+ public static double minusDouble(char value) {
+ return -value;
+ }
+
+ public static double inc(double value) {
+ return value++;
+ }
+
+ public static byte incPost(byte value) {
+ return value++;
+ }
+
+ public static byte incPre(byte value) {
+ return ++value;
+ }
+
+ public static long shr(long a, long b) {
+ return a >> b;
+ }
+ public static long shr(long a, byte b) {
+ return a >> b;
+ }
+
+ public static int arrayAccess(int[] a, byte b) {
+ return a[b];
+ }
+
+ public static Object getObjectFromString(String s) {
+ return getObject(s);
+ }
+
+ public static Object getObject(Object o) {
+ return o;
+ }
+
+ private static byte[] arrayByte = new byte[10];
+
+ public static byte setByteArray() {
+ arrayByte[1] = (byte) -1;
+ return arrayByte[1];
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit002/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/implicit002/dx/Tests.java
new file mode 100644
index 0000000..1d11878
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit002/dx/Tests.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit002.dx;
+
+
+import com.android.jack.cast.implicit002.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about arithmetic.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ boolean cond = true;
+ boolean cond2 = false;
+ byte b = 13;
+ short s = 14;
+ char c = 15;
+ int i = 16;
+ long l = 17;
+ float f = 0.18f;
+ double d = 0.19;
+ Assert.assertEquals(cond ? b : s, Data.conditonalBS(cond, b, s));
+ Assert.assertEquals(cond ? l : b, Data.conditonalLB(cond, l, b));
+ Assert.assertEquals(cond ? b : b, Data.conditonalBB(cond, b, b));
+ Assert.assertEquals(cond ? i : b, Data.conditonalIB(cond, i, b));
+ Assert.assertEquals(cond ? b : d, Data.conditonalBD(cond, b, d), 0.0);
+ Assert.assertEquals(cond ? i : d, Data.conditonalID(cond, i, d), 0.0);
+ Assert.assertEquals(cond ? l : d, Data.conditonalLD(cond, l, d), 0.0);
+ Assert.assertEquals(cond ? i : f, Data.conditonalIF(cond, i, f), 0.0);
+
+ Assert.assertEquals(cond2 ? b : s, Data.conditonalBS(cond2, b, s));
+ Assert.assertEquals(cond2 ? l : b, Data.conditonalLB(cond2, l, b));
+ Assert.assertEquals(cond2 ? b : b, Data.conditonalBB(cond2, b, b));
+ Assert.assertEquals(cond2 ? i : b, Data.conditonalIB(cond2, i, b));
+ Assert.assertEquals(cond2 ? b : d, Data.conditonalBD(cond2, b, d), 0.0);
+ Assert.assertEquals(cond2 ? i : d, Data.conditonalID(cond2, i, d), 0.0);
+ Assert.assertEquals(cond2 ? l : d, Data.conditonalLD(cond2, l, d), 0.0);
+ Assert.assertEquals(cond2 ? i : f, Data.conditonalIF(cond2, i, f), 0.0);
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit002/jack/Data.java b/jack-tests/tests/com/android/jack/cast/implicit002/jack/Data.java
new file mode 100644
index 0000000..36dde8d
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit002/jack/Data.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit002.jack;
+
+public class Data {
+
+ public static int conditonalIB(boolean cond, int a, byte b) {
+ return cond ? a : b;
+ }
+
+ public static byte conditonalBB(boolean cond, byte a, byte b) {
+ return cond ? a : b;
+ }
+
+ public static short conditonalBS(boolean cond, byte a, short b) {
+ return cond ? a : b;
+ }
+
+ public static long conditonalLB(boolean cond, long a, byte b) {
+ return cond ? a : b;
+ }
+
+ public static float conditonalIF(boolean cond, int a, float b) {
+ return cond ? a : b;
+ }
+
+ public static double conditonalID(boolean cond, int a, double b) {
+ return cond ? a : b;
+ }
+
+ public static double conditonalBD(boolean cond, byte a, double b) {
+ return cond ? a : b;
+ }
+
+ public static double conditonalLD(boolean cond, long a, double b) {
+ return cond ? a : b;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit003/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/implicit003/dx/Tests.java
new file mode 100644
index 0000000..3ea6220
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit003/dx/Tests.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit003.dx;
+
+
+import com.android.jack.cast.implicit003.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about arithmetic.
+ */
+public class Tests {
+
+ @SuppressWarnings("boxing")
+ @Test
+ public void test1() {
+ boolean cond = true;
+ boolean cond2 = false;
+ byte b = 13;
+ Byte B = b;
+ short s = 14;
+ char c = 15;
+ int i = 16;
+ long l = 17;
+ Long L = l;
+ float f = 0.18f;
+ double d = 0.19;
+
+ Assert.assertEquals(cond ? i : B, Data.conditonalIByte(cond, i, B));
+ Assert.assertEquals((Object) (cond ? i : L), (Object) Data.conditonalILong(cond, i, L));
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit003/jack/Data.java b/jack-tests/tests/com/android/jack/cast/implicit003/jack/Data.java
new file mode 100644
index 0000000..ec38ee1
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit003/jack/Data.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit003.jack;
+
+public class Data {
+
+ @SuppressWarnings("boxing")
+ public static int conditonalIByte(boolean cond, int a, Byte b) {
+ return cond ? a : b;
+ }
+
+ @SuppressWarnings("boxing")
+ public static Long conditonalILong(boolean cond, int a, Long b) {
+ return cond ? a : b;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit004/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/implicit004/dx/Tests.java
new file mode 100644
index 0000000..8d9d98f
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit004/dx/Tests.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit004.dx;
+
+
+import com.android.jack.cast.implicit004.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about arithmetic.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ byte[] array = new byte[]{1, 2, 3};
+ int index = 2;
+ byte or = 127;
+ int m1 = array[index] | or;
+ Assert.assertEquals(m1, Data.m1(array, index, or));
+ Assert.assertEquals(m1, array[index]);
+ }
+
+ @Test
+ public void test2() {
+ double[] array = new double[]{1.0, 2.0, 3.0};
+ int index = 2;
+ byte or1 = 127;
+ byte or2 = 7;
+ double m2 = or1 | or2;
+ Assert.assertEquals(m2, Data.m2(array, index, or1, or2), 0.0);
+ Assert.assertEquals(m2, array[index], 0.0);
+ }
+
+ @Test
+ public void test3() {
+ char[] array = new char[]{1, 2, 3};
+ int index = 2;
+ byte or = 127;
+ char m3 = (char) (array[index] | or);
+ Assert.assertEquals(m3, Data.m3(array, index, or));
+ Assert.assertEquals(m3, array[index]);
+ }
+
+ @Test
+ public void test4() {
+ byte[] array = new byte[]{1, 2, 3};
+ int index = 2;
+ byte b = 127;
+ byte m4 = (byte) ~b;
+ Assert.assertEquals(m4, Data.m4(array, index, b));
+ Assert.assertEquals(m4, array[index]);
+ }
+
+ @Test
+ public void test5() {
+ byte[] array = new byte[]{1, 2, 3};
+ int index = 2;
+ byte b = 127;
+ byte m5 = (byte) (b + 1);
+ Assert.assertEquals(m5, Data.m5(array, index, b));
+ Assert.assertEquals(m5, array[index]);
+ }
+
+ @Test
+ public void test6() {
+ Assert.assertEquals(-1, Data.m6((byte) 1));
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit004/jack/Data.java b/jack-tests/tests/com/android/jack/cast/implicit004/jack/Data.java
new file mode 100644
index 0000000..c125c8e
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit004/jack/Data.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.jack.cast.implicit004.jack;
+
+public class Data {
+
+ public static byte m1(byte[] array, int index, byte or) {
+ array[index] |= or;
+ return array[index];
+ }
+
+ public static double m2(double[] array, int index, byte or1, byte or2) {
+ array[index] = or1 | or2;
+ return array[index];
+ }
+
+ public static char m3(char[] array, int index, byte or) {
+ array[index] |= or;
+ return array[index];
+ }
+
+ public static int m3(byte b2) {
+ byte b1;
+ byte b3;
+ char c;
+ int i;
+ i = b1 = b3 = b2;
+ return b1 + i;
+ }
+
+ public static byte m4(byte[] array, int index, byte b) {
+ array[index] = (byte) ~b;
+ return array[index];
+ }
+
+ public static byte m5(byte[] array, int index, byte b) {
+ array[index] = ++b;
+ return array[index];
+ }
+
+ public static int m6(byte b) {
+ int i = -b;
+ return i;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/implicit005/jack/Data.java b/jack-tests/tests/com/android/jack/cast/implicit005/jack/Data.java
new file mode 100644
index 0000000..455cc74
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/implicit005/jack/Data.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.implicit005.jack;
+
+public class Data {
+
+ public void concat() {
+ int i = 0;
+ try {
+ i = 1;
+ } finally {
+ String s = "S" + i + ':';
+ }
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/cast/useless001/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/useless001/dx/Tests.java
new file mode 100644
index 0000000..c6b180c
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/useless001/dx/Tests.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.useless001.dx;
+
+
+import com.android.jack.cast.useless001.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests useless cast.
+ */
+public class Tests {
+
+ @Test
+ public void testValue1() {
+ Data data = new Data();
+ Assert.assertEquals(2, data.getValue1());
+ }
+
+ @Test
+ public void testValue2() {
+ Data data = new Data();
+ Assert.assertEquals(3, data.getValue2());
+ }
+
+ @Test
+ public void getValue3() {
+ Data data = new Data();
+ Assert.assertEquals(3, data.getValue3());
+ }
+
+ @Test
+ public void getValue4() {
+ Data data = new Data();
+ Assert.assertEquals(3, data.getValue4());
+ }
+
+ @Test
+ public void getValue5() {
+ Data data = new Data();
+ Assert.assertEquals(3, data.getValue5(new Object[]{null,null,null}));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/useless001/jack/Data.java b/jack-tests/tests/com/android/jack/cast/useless001/jack/Data.java
new file mode 100644
index 0000000..9f58696
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/useless001/jack/Data.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.useless001.jack;
+
+
+
+public class Data {
+
+ class A {
+ private int f = 1;
+
+ public int getInt() {
+ return 1;
+ }
+
+ private int getIntPrivate() {
+ return 1;
+ }
+
+ public int getInt3(A a) {
+ return 1;
+ }
+ }
+
+ class B extends A {
+ private int f = 2;
+
+ @Override
+ public int getInt() {
+ return 2;
+ }
+
+ private int getIntPrivate() {
+ return 2;
+ }
+
+ public int getInt3(B b) {
+ return 2;
+ }
+ }
+
+ public int getValue1() {
+ B b = new B();
+ return (((A)b).getInt());
+ }
+
+ public int getValue2() {
+ B b = new B();
+ return (((A)b).getIntPrivate() + b.getIntPrivate());
+ }
+
+ public int getValue3() {
+ B b = new B();
+ return (((A)b).f + b.f);
+ }
+
+ public int getValue4() {
+ B b = new B();
+ return (b.getInt3(new B()) + ((A)b).getInt3(new B()));
+ }
+
+ public int getValue5(Object o) {
+ return ((Object[]) o).length;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/useless002/dx/Tests.java b/jack-tests/tests/com/android/jack/cast/useless002/dx/Tests.java
new file mode 100644
index 0000000..b541bee
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/useless002/dx/Tests.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.useless002.dx;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.android.jack.cast.useless002.jack.UselessCast;
+
+/**
+ * JUnit test related to useless cast.
+ */
+public class Tests {
+
+ @Test
+ public void uselessCastCodeExpansion() {
+ Assert.assertEquals(1, UselessCast.uselessCast(1, 2, 3));
+ Assert.assertEquals(0, UselessCast.uselessCast(2, 1, 3));
+ Assert.assertEquals(0, UselessCast.uselessCast(1, 2, 0));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/useless002/jack/UselessCast.java b/jack-tests/tests/com/android/jack/cast/useless002/jack/UselessCast.java
new file mode 100644
index 0000000..cb709f5
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/useless002/jack/UselessCast.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.useless002.jack;
+
+/**
+ * JUnit test allowing to verify that useless casts are not generated.
+ */
+public class UselessCast {
+
+ // Jack IR should not contains cast between int to long.
+ public static long uselessCast(int i1, int i2, int i3) {
+ if (i1 < i2) {
+ return i3 != 0 ? 1 : 0;
+ } else {
+ return 0;
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/cast/useless003/jack/UselessCast.java b/jack-tests/tests/com/android/jack/cast/useless003/jack/UselessCast.java
new file mode 100644
index 0000000..3d6cef6
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/cast/useless003/jack/UselessCast.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2013 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.
+ */
+
+package com.android.jack.cast.useless003.jack;
+
+/**
+ * Test allowing to verify that useless casts are not generated.
+ */
+public class UselessCast {
+
+ long val1;
+ long val2;
+
+ // Jack IR should not contains cast between int to long.
+ public void nestedAssign() {
+ val1 = val2 = 0;
+ }
+}