diff options
author | Yohann Roussel <yroussel@google.com> | 2014-03-19 16:25:37 +0100 |
---|---|---|
committer | Yohann Roussel <yroussel@google.com> | 2014-03-20 15:13:33 +0100 |
commit | 4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch) | |
tree | ee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /jack-tests/tests/com/android/jack/ifstatement | |
parent | 3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff) | |
download | toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.zip toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.gz toolchain_jack-4eceb95409e844fdc33c9c706e1dc307bfd40303.tar.bz2 |
Initial Jack import.
Change-Id: I953cf0a520195a7187d791b2885848ad0d5a9b43
Diffstat (limited to 'jack-tests/tests/com/android/jack/ifstatement')
8 files changed, 788 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/ifstatement/advancedTest/dx/Tests.java b/jack-tests/tests/com/android/jack/ifstatement/advancedTest/dx/Tests.java new file mode 100644 index 0000000..effbfc6 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/advancedTest/dx/Tests.java @@ -0,0 +1,117 @@ +/* + * 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.ifstatement.advancedTest.dx; + +import com.android.jack.ifstatement.advancedTest.jack.IfAdvanced; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests about advanced if statement. + */ +public class Tests { + + @Test + public void testOr() { + Assert.assertEquals(1, IfAdvanced.testOr(true, true)); + Assert.assertEquals(1, IfAdvanced.testOr(true, false)); + Assert.assertEquals(1, IfAdvanced.testOr(false, true)); + Assert.assertEquals(0, IfAdvanced.testOr(false, false)); + } + + @Test + public void testAnd() { + Assert.assertEquals(1, IfAdvanced.testAnd(true, true)); + Assert.assertEquals(0, IfAdvanced.testAnd(true, false)); + Assert.assertEquals(0, IfAdvanced.testAnd(false, true)); + Assert.assertEquals(0, IfAdvanced.testOr(false, false)); + } + + @Test + public void testConditional() { + Assert.assertEquals(0, IfAdvanced.testConditional(false)); + Assert.assertEquals(1, IfAdvanced.testConditional(true)); + } + + @Test + public void testElseIf() { + Assert.assertEquals(0, IfAdvanced.testElseIf(0)); + Assert.assertEquals(1, IfAdvanced.testElseIf(1)); + Assert.assertEquals(-1, IfAdvanced.testElseIf(3)); + } + + @Test + public void testMix() { + Assert.assertEquals(0, IfAdvanced.testMix(0, 8)); + Assert.assertEquals(1, IfAdvanced.testMix(2, 6)); + Assert.assertEquals(1, IfAdvanced.testMix(2, 5)); + } + + @Test + public void testBraces() { + Assert.assertFalse(IfAdvanced.testBraces()); + } + + @Test + public void testNoReturnInBranch() { + Assert.assertEquals(IfAdvanced.testNoReturnInBranch(5), 5); + Assert.assertEquals(IfAdvanced.testNoReturnInBranch(-7), 7); + } + + @Test + public void testIfFalse1() { + Assert.assertEquals(2, new IfAdvanced().testIfFalse1()); + } + + @Test + public void testIfFalse2() { + Assert.assertEquals(2, new IfAdvanced().testIfFalse2()); + } + + @Test + public void testIfFalse3() { + Assert.assertEquals(2, new IfAdvanced().testIfFalse3()); + } + + @Test + public void testIfTrue1() { + Assert.assertEquals(1, new IfAdvanced().testIfTrue1()); + } + + @Test + public void testIfTrue2() { + Assert.assertEquals(1, new IfAdvanced().testIfTrue2()); + } + + @Test + public void testIfTrue3() { + Assert.assertEquals(1, new IfAdvanced().testIfTrue3()); + } + + @Test + public void testEmptyIfThen() { + Assert.assertEquals(1, new IfAdvanced().emptyIfThen(true)); + Assert.assertEquals(2, new IfAdvanced().emptyIfThen(false)); + } + + @Test + public void testEmptyIfElse() { + Assert.assertEquals(2, new IfAdvanced().emptyIfElse(true)); + Assert.assertEquals(1, new IfAdvanced().emptyIfElse(false)); + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/advancedTest/jack/IfAdvanced.java b/jack-tests/tests/com/android/jack/ifstatement/advancedTest/jack/IfAdvanced.java new file mode 100644 index 0000000..dc34770 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/advancedTest/jack/IfAdvanced.java @@ -0,0 +1,154 @@ +/* + * 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.ifstatement.advancedTest.jack; + +public class IfAdvanced { + + public static int testOr(boolean a, boolean b) { + if (a || b) { + return 1; + } else { + return 0; + } + } + + public static int testAnd(boolean a, boolean b) { + if (a && b) { + return 1; + } else { + return 0; + } + } + + public static int testMix(int a, int b) { + if (a == 2 || b == 5) { + return 1; + } else { + return 0; + } + } + + public static int testConditional(boolean a) { + if (a ? true : false) { + return 1; + } else { + return 0; + } + } + + public static int testElseIf(int a) { + if (a == 0) { + return 0; + } else if (a == 1) { + return 1; + } else { + return -1; + } + } + + @SuppressWarnings("unused") + public static boolean testBraces() { + if (7 == 9) + return true; + else + return false; + } + + public static int testNoReturnInBranch(int a) { + int b; + if (a > 0) { + b = a; + } else { + b = -a; + } + return b; + } + + private static final boolean DEBUG = false; + private static final boolean NOT_DEBUG = true; + private boolean value = true; + + public boolean getMethod() { + return false; + } + + @SuppressWarnings("unused") + public int testIfFalse1() { + if (DEBUG && value) { + return 1; + } + return 2; + } + + @SuppressWarnings("unused") + public int testIfFalse3() { + if (DEBUG && getMethod()) { + return 1; + } + return 2; + } + + @SuppressWarnings("unused") + public int testIfFalse2() { + if (DEBUG && value) { + return 1; + } else { + return 2; + } + } + + @SuppressWarnings("unused") + public int testIfTrue1() { + if (true || value) { + return 1; + } else { + return 2; + } + } + + @SuppressWarnings("unused") + public int testIfTrue2() { + if (NOT_DEBUG || value) { + return 1; + } else { + return 2; + } + } + + @SuppressWarnings("unused") + public int testIfTrue3() { + if (NOT_DEBUG || value) { + return 1; + } + return 2; + } + + public int emptyIfThen(boolean val) { + if (val); + else { + return 2; + } + return 1; + } + + public int emptyIfElse(boolean val) { + if (val) { + return 2; + } else ; + return 1; + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/cfgTest/dx/Tests.java b/jack-tests/tests/com/android/jack/ifstatement/cfgTest/dx/Tests.java new file mode 100644 index 0000000..9032147 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/cfgTest/dx/Tests.java @@ -0,0 +1,84 @@ +/* + * 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.ifstatement.cfgTest.dx; + +import org.junit.Assert; +import org.junit.Test; + +import com.android.jack.ifstatement.cfgTest.jack.IfCfg; + +/** + * Tests about if statement and cfg builder. + */ +public class Tests { + + @Test + public void ifWithEndedThen() { + Assert.assertEquals(1, IfCfg.ifWithEndedThen(true)); + Assert.assertEquals(2, IfCfg.ifWithEndedThen(false)); + } + + @Test + public void ifWithEndedThenElse() { + Assert.assertEquals(1, IfCfg.ifWithEndedThenElse(true)); + Assert.assertEquals(2, IfCfg.ifWithEndedThenElse(false)); + } + + @Test + public void ifWithThen() { + Assert.assertEquals(2, IfCfg.ifWithThen(true)); + Assert.assertEquals(0, IfCfg.ifWithThen(false)); + } + + @Test + public void ifWithThenElse() { + Assert.assertEquals(2, IfCfg.ifWithThenElse(true)); + Assert.assertEquals(3, IfCfg.ifWithThenElse(false)); + } + + @Test + public void ifThenNested() { + Assert.assertEquals(4, IfCfg.ifThenNested(1)); + Assert.assertEquals(2, IfCfg.ifThenNested(2)); + } + + @Test + public void ifElseNested() { + Assert.assertEquals(4, IfCfg.ifElseNested(1)); + Assert.assertEquals(4, IfCfg.ifElseNested(2)); + Assert.assertEquals(2, IfCfg.ifElseNested(3)); + } + + @Test + public void ifEmptyThen() { + Assert.assertEquals(2, IfCfg.ifEmptyThen(1)); + Assert.assertEquals(2, IfCfg.ifEmptyThen(2)); + } + + @Test + public void ifEmptyElse() { + Assert.assertEquals(4, IfCfg.ifEmptyElse(1)); + Assert.assertEquals(2, IfCfg.ifEmptyElse(2)); + } + + @Test + public void ifThenElseNested() { + Assert.assertEquals(1, IfCfg.ifThenElseNested(1)); + Assert.assertEquals(2, IfCfg.ifThenElseNested(2)); + Assert.assertEquals(3, IfCfg.ifThenElseNested(3)); + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/cfgTest/jack/IfCfg.java b/jack-tests/tests/com/android/jack/ifstatement/cfgTest/jack/IfCfg.java new file mode 100644 index 0000000..8c611f0 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/cfgTest/jack/IfCfg.java @@ -0,0 +1,115 @@ +/* + * 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.ifstatement.cfgTest.jack; + +/** + * Tests about if statement and cfg builder. + */ +public class IfCfg { + + public static int ifWithEndedThen(boolean val) { + if (val) { + return 1; + } + return 2; + } + + public static int ifWithEndedThenElse(boolean val) { + if (val) { + return 1; + } else { + return 2; + } + } + + public static int ifWithThen(boolean val) { + int result = 0; + if (val) { + result = result + 2; + } + return result; + } + + public static int ifWithThenElse(boolean val) { + int result = 0; + if (val) { + result = result + 2; + } else { + result = result + 3; + } + return result; + } + + public static int ifThenNested(int val) { + int result = 0; + if (val == 1) { + result = result + 2; + if (val != 1) { + result = result + 2; + } + } + result = result + 2; + return result; + } + + public static int ifElseNested(int val) { + int result = 0; + if (val == 1) { + result = result + 2; + } else { + if (val == 2) { + result = result + 2; + } + } + result = result + 2; + return result; + } + + public static int ifEmptyThen(int val) { + int result = 2; + if (val == 1) { + } + return result; + } + + public static int ifEmptyElse(int val) { + int result = 2; + if (val == 1) { + result = 4; + } else { + } + return result; + } + + public static int ifThenElseNested(int val) { + int result = 0; + if (val == 1) { + result = 3; + if (val == 2) { + result = 2; + } + result = 1; + } else { + if (val == 2) { + result = 2; + } else { + result = 3; + } + } + return result; + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/fastpath/dx/Tests.java b/jack-tests/tests/com/android/jack/ifstatement/fastpath/dx/Tests.java new file mode 100644 index 0000000..f07d42a --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/fastpath/dx/Tests.java @@ -0,0 +1,36 @@ +/* + * 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.ifstatement.fastpath.dx; + +import org.junit.Assert; +import org.junit.Test; + +import com.android.jack.ifstatement.fastpath.jack.Data; + +/** + * Tests about arithmetic. + */ +public class Tests { + + @Test + public void testIfFastPath() { + Assert.assertEquals(1, Data.test1(false, true)); + Assert.assertEquals(2, Data.test1(false, false)); + Assert.assertEquals(2, Data.test1(true, false)); + Assert.assertEquals(2, Data.test1(true, true)); + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/fastpath/jack/Data.java b/jack-tests/tests/com/android/jack/ifstatement/fastpath/jack/Data.java new file mode 100644 index 0000000..91c9d02 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/fastpath/jack/Data.java @@ -0,0 +1,36 @@ +/* + * 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.ifstatement.fastpath.jack; + +public class Data { + + public static int test1 (boolean a, boolean b) { + if (!a && b) { + return 1; + } else { + return 2; + } + } + + public static int test2 (Object o, boolean b) { + if (o == null || b) { + return 1; + } else { + return 2; + } + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/simpleTest/dx/Tests.java b/jack-tests/tests/com/android/jack/ifstatement/simpleTest/dx/Tests.java new file mode 100644 index 0000000..550219d --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/simpleTest/dx/Tests.java @@ -0,0 +1,112 @@ +/* + * 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.ifstatement.simpleTest.dx; + +import com.android.jack.ifstatement.simpleTest.jack.If; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Tests about arithmetic. + */ +public class Tests { + + @Test + public void testTrue() { + Assert.assertEquals(1, If.testTrue()); + } + + @Test + public void testTrue2() { + Assert.assertEquals(-1, If.testTrue2()); + } + + @Test + public void testFalse() { + Assert.assertEquals(2, If.testFalse()); + } + + @Test + public void testFalse2() { + Assert.assertEquals(-1, If.testFalse2()); + } + + @Test + public void testFalseEmpty() { + Assert.assertEquals(3, If.testFalseEmpty()); + } + + @Test + public void testParam() { + Assert.assertEquals(3, If.testParam(true)); + Assert.assertEquals(4, If.testParam(false)); + } + + @Test + public void testLt() { + Assert.assertEquals(1, If.testLt(1, 2)); + Assert.assertEquals(0, If.testLt(4, 3)); + Assert.assertEquals(0, If.testLt(5, 5)); + } + + @Test + public void testGt() { + Assert.assertEquals(0, If.testGt(1, 2)); + Assert.assertEquals(1, If.testGt(4, 3)); + Assert.assertEquals(0, If.testGt(5, 5)); + } + + @Test + public void testLte() { + Assert.assertEquals(1, If.testLte(1, 2)); + Assert.assertEquals(0, If.testLte(4, 3)); + Assert.assertEquals(1, If.testLte(5, 5)); + } + + @Test + public void testGte() { + Assert.assertEquals(0, If.testGte(1, 2)); + Assert.assertEquals(1, If.testGte(4, 3)); + Assert.assertEquals(1, If.testGte(5, 5)); + } + + @Test + public void testEq() { + Assert.assertEquals(0, If.testEq(1, 2)); + Assert.assertEquals(0, If.testEq(4, 3)); + Assert.assertEquals(1, If.testEq(5, 5)); + } + + @Test + public void testNeq() { + Assert.assertEquals(1, If.testNeq(1, 2)); + Assert.assertEquals(1, If.testNeq(4, 3)); + Assert.assertEquals(0, If.testNeq(5, 5)); + } + + @Test + public void testCst() { + Assert.assertTrue(If.testCst(5)); + Assert.assertFalse(If.testCst(7)); + } + + @Test + public void testNested() { + Assert.assertTrue(If.testNested()); + } +} diff --git a/jack-tests/tests/com/android/jack/ifstatement/simpleTest/jack/If.java b/jack-tests/tests/com/android/jack/ifstatement/simpleTest/jack/If.java new file mode 100644 index 0000000..ad2dbf6 --- /dev/null +++ b/jack-tests/tests/com/android/jack/ifstatement/simpleTest/jack/If.java @@ -0,0 +1,134 @@ +/* + * 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.ifstatement.simpleTest.jack; + +/** + * Tests about if statement. + */ +public class If { + @SuppressWarnings("unused") + public static int testTrue() { + if (true) { + return 1; + } else { + return 2; + } + } + + public static int testTrue2() { + if (true); + return -1; + } + + @SuppressWarnings("unused") + public static int testFalse() { + if (false) { + return 1; + } else { + return 2; + } + } + + @SuppressWarnings("unused") + public static int testFalse2() { + if (false); + return -1; + } + + @SuppressWarnings("unused") + public static int testFalseEmpty() { + if (false) { + } + return 3; + } + + public static int testParam(boolean b) { + if (b) { + return 3; + } else { + return 4; + } + } + + public static int testLt(int a, int b) { + if (a < b) { + return 1; + } else { + return 0; + } + } + + public static int testGt(int a, int b) { + if (a > b) { + return 1; + } else { + return 0; + } + } + + public static int testLte(int a, int b) { + if (a <= b) { + return 1; + } else { + return 0; + } + } + + public static int testGte(int a, int b) { + if (a >= b) { + return 1; + } else { + return 0; + } + } + + public static int testEq(int a, int b) { + if (a == b) { + return 1; + } else { + return 0; + } + } + + public static int testNeq(int a, int b) { + if (a != b) { + return 1; + } else { + return 0; + } + } + + public static boolean testCst(int a) { + if (a == 5) { + return true; + } else { + return false; + } + } + + public static boolean testNested() { + if (true) { + if (false) { + return false; + } + else { + return true; + } + } + return false; + } +} |