diff options
Diffstat (limited to 'jack-tests/tests/com/android/jack/cast/implicit001')
-rw-r--r-- | jack-tests/tests/com/android/jack/cast/implicit001/dx/Tests.java | 165 | ||||
-rw-r--r-- | jack-tests/tests/com/android/jack/cast/implicit001/jack/Data.java | 132 |
2 files changed, 297 insertions, 0 deletions
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]; + } +} |