diff options
Diffstat (limited to 'jack-tests/tests/com/android/jack/conditional/test001')
-rw-r--r-- | jack-tests/tests/com/android/jack/conditional/test001/dx/Tests.java | 49 | ||||
-rw-r--r-- | jack-tests/tests/com/android/jack/conditional/test001/jack/Conditional.java | 135 |
2 files changed, 184 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/conditional/test001/dx/Tests.java b/jack-tests/tests/com/android/jack/conditional/test001/dx/Tests.java new file mode 100644 index 0000000..db9b9da --- /dev/null +++ b/jack-tests/tests/com/android/jack/conditional/test001/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.conditional.test001.dx; + +import com.android.jack.conditional.test001.jack.Conditional; + +import junit.framework.Assert; + +import org.junit.Test; + +public class Tests { + + @Test + public void test1() { + Assert.assertEquals(1, Conditional.test_conditionalCode001(15)); + Assert.assertEquals(-1, Conditional.test_conditionalCode001(-15)); + Assert.assertEquals(15, Conditional.test_conditionalCode002(15, -15)); + Assert.assertEquals(1, Conditional.test_conditionalCode003(15, -15)); + Assert.assertEquals(-1, Conditional.test_conditionalCode004(1, 2, 3, 3, 5, 8, 6)); + Assert.assertEquals(1, Conditional.test_conditionalCode005(15, -15)); + Assert.assertEquals(1, Conditional.test_conditionalCode006(true)); + Assert.assertEquals(-1, Conditional.test_conditionalCode006(false)); + + Assert.assertEquals(4, Conditional.test_conditionalCode007(false)); + Assert.assertEquals(5, Conditional.test_conditionalCode008(false)); + Assert.assertEquals(5, Conditional.test_conditionalCode009(false)); + Assert.assertEquals(3, Conditional.test_conditionalCode010(false)); + Assert.assertEquals(4, Conditional.test_conditionalCode011(false)); + Assert.assertEquals(1, Conditional.test_conditionalCode012(false)); + Assert.assertEquals(2, Conditional.test_conditionalCode013(false)); + Assert.assertEquals(4, Conditional.test_conditionalCode014(false)); + Assert.assertEquals(3, Conditional.test_conditionalCode015(false)); + Assert.assertEquals(4, Conditional.test_conditionalCode016(false)); + } +} diff --git a/jack-tests/tests/com/android/jack/conditional/test001/jack/Conditional.java b/jack-tests/tests/com/android/jack/conditional/test001/jack/Conditional.java new file mode 100644 index 0000000..c0912d0 --- /dev/null +++ b/jack-tests/tests/com/android/jack/conditional/test001/jack/Conditional.java @@ -0,0 +1,135 @@ +/* + * 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.conditional.test001.jack; + +public class Conditional { + + public static int test_conditionalCode001(int a) { + int b = (a > 0) ? 1 : -1; + return b; + } + + public static int test_conditionalCode002(int a, int b) { + int c = (a > 0) ? ((b > a) ? b : a) : -1; + return c; + } + + public static int test_conditionalCode003(int a, int b) { + int c; + if (((a > 0) ? ((b > a) ? b : a) : -1) > 0) { + c = 1; + } else { + c = 3; + } + return c; + } + + public static int test_conditionalCode004(int a, int b, int c, int d, int e, int f, int g) { + int i = + ((c > d) ? (e == f) : (g == a)) ? ((((b == f) ? e : g) > a) ? ((a < c) ? b : g) : a) : -1; + return i; + } + + public static int test_conditionalCode005(int a, int b) { + int x = (a < b) ? (1) : (getValue((b > 0) ? 2 : 3 )); + return x; + } + + public static int test_conditionalCode006(boolean a) { + int b; + b = a ? 1 : -1; + return b; + } + + + public static int test_conditionalCode007(boolean a) { + byte b = 1; + char c = 2; + return m(a ? b : c); + } + + public static int test_conditionalCode008(boolean a) { + byte b = 1; + return m(a ? b : null); + } + + public static int test_conditionalCode009(boolean a) { + byte b = 1; + return m(a ? null : b); + } + + public static int test_conditionalCode010(boolean a) { + byte b = 1; + short c = 1; + return m(a ? c : b); + } + + public static int test_conditionalCode011(boolean a) { + byte b = 1; + return m(a ? 256 : b); + } + + public static int test_conditionalCode012(boolean a) { + byte b = 1; + return m(a ? 12 : b); + } + + public static int test_conditionalCode013(boolean a) { + char b = 1; + return m(a ? 12 : b); + } + + public static int test_conditionalCode014(boolean a) { + char b = 1; + return m(a ? -1 : b); + } + + public static int test_conditionalCode015(boolean a) { + short b = 1; + return m(a ? -1 : b); + } + + public static int test_conditionalCode016(boolean a) { + short b = 1; + return m(a ? 1234567890 : b); + } + + public static int m(byte a) { + return 1; + } + + public static int m(char a) { + return 2; + } + + public static int m(short a) { + return 3; + } + + public static int m(int a) { + return 4; + } + + public static int m(Object a) { + return 5; + } + + public static int getValue(int c) { + return 1; + } + +} |