summaryrefslogtreecommitdiffstats
path: root/jack-tests/tests/com/android/jack/switchstatement
diff options
context:
space:
mode:
authorYohann Roussel <yroussel@google.com>2014-03-19 16:25:37 +0100
committerYohann Roussel <yroussel@google.com>2014-03-20 15:13:33 +0100
commit4eceb95409e844fdc33c9c706e1dc307bfd40303 (patch)
treeee9f4f3fc79f757c79081c336bce4f1782c6ccd8 /jack-tests/tests/com/android/jack/switchstatement
parent3d2402901b1a6462e2cf47a6fd09711f327961c3 (diff)
downloadtoolchain_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/switchstatement')
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test001/dx/Tests.java174
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test001/jack/Switches001.java275
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test002/dx/Tests.java36
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test002/jack/Switches002.java45
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test003/dx/Tests.java45
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test003/jack/Switches003.java39
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test004/dx/Tests.java30
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test004/jack/Data.java36
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test005/dx/Tests.java56
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test005/jack/Switch.java77
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test006/dx/Tests.java64
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test006/jack/Switch.java65
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test007/dx/Tests.java33
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test007/jack/Switch.java33
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test008/dx/Tests.java35
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test008/jack/Switch.java48
-rw-r--r--jack-tests/tests/com/android/jack/switchstatement/test009/jack/Switch.java50
17 files changed, 1141 insertions, 0 deletions
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test001/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test001/dx/Tests.java
new file mode 100644
index 0000000..24c18b2
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test001/dx/Tests.java
@@ -0,0 +1,174 @@
+/*
+ * 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.switchstatement.test001.dx;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.android.jack.switchstatement.test001.jack.Switches001;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Assert.assertEquals(1, Switches001.switch001(1));
+ Assert.assertEquals(2, Switches001.switch001(2));
+ Assert.assertEquals(3, Switches001.switch001(3));
+ }
+
+ @Test
+ public void testNoDefault() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch003(-1));
+ Assert.assertEquals(2, t.switch003(15));
+ Assert.assertEquals(-1, t.switch003(2));
+ }
+
+ @Test
+ public void testNested() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(11, t.switch004(1, 10));
+ Assert.assertEquals(12, t.switch004(1, 20));
+ Assert.assertEquals(21, t.switch004(2, 10));
+ Assert.assertEquals(22, t.switch004(2, 20));
+ Assert.assertEquals(-1, t.switch004(2, 30));
+ }
+
+ @Test
+ public void testWithBlocks() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(2, t.switch005(1));
+ Assert.assertEquals(4, t.switch005(3));
+ Assert.assertEquals(-1, t.switch005(5));
+ }
+
+ @Test
+ public void testN1() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(2, t.switch002(-1));
+
+ Assert.assertEquals(-1, t.switch002(9));
+ Assert.assertEquals(20, t.switch002(10));
+ Assert.assertEquals(-1, t.switch002(11));
+
+ Assert.assertEquals(-1, t.switch002(14));
+ Assert.assertEquals(20, t.switch002(15));
+ Assert.assertEquals(-1, t.switch002(16));
+ }
+
+ @Test
+ public void testB1() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(-1, t.switch002(Integer.MAX_VALUE));
+ }
+
+ @Test
+ public void testB2() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(-1, t.switch002(Integer.MIN_VALUE));
+ }
+
+ @Test
+ public void unorderedSwitch() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch006(1));
+ Assert.assertEquals(2, t.switch006(2));
+ Assert.assertEquals(3, t.switch006(3));
+ }
+
+ @Test
+ public void switchWithFallThrough() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(4, t.switch007(1));
+ Assert.assertEquals(2, t.switch007(2));
+ Assert.assertEquals(4, t.switch007(3));
+ }
+
+ @Test
+ public void nestedSwitch() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(6, t.switch008(1));
+ Assert.assertEquals(2, t.switch008(2));
+ Assert.assertEquals(8, t.switch008(3));
+ }
+
+ @Test
+ public void switchWithChar() {
+ Switches001 t = new Switches001();
+ Assert.assertTrue('#' == t.switch009('#'));
+ Assert.assertTrue('A' == t.switch009('A'));
+ }
+
+ @Test
+ public void switchWithByteShort() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch010((byte)1));
+ Assert.assertEquals(2, t.switch010((byte)2));
+ }
+
+ @Test
+ public void switchWithOnlyDefault() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(2, t.switch011(1));
+ Assert.assertEquals(2, t.switch011(2));
+ }
+
+ @Test
+ public void switchWithNoCases() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch012(1));
+ Assert.assertEquals(1, t.switch012(2));
+ }
+
+ @Test
+ public void switchWithOnlyDefault2() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch013(1));
+ Assert.assertEquals(1, t.switch013(2));
+ }
+
+ @Test
+ public void switchWithOnlyDefault3() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch014(1));
+ Assert.assertEquals(1, t.switch015(2));
+ }
+
+ @Test
+ public void switchWithOnlyDefaultWithSwitch() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(1, t.switch016(1));
+ Assert.assertEquals(2, t.switch016(2));
+ }
+
+ @Test
+ public void switchWithOnlyDefaultWithLoopBreak() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(6, t.switch017(1));
+ Assert.assertEquals(2, t.switch017(2));
+ }
+
+ @Test
+ public void switchWithOnlyDefaultWithLabledBreak() {
+ Switches001 t = new Switches001();
+ Assert.assertEquals(2, t.switch018(1));
+ Assert.assertEquals(2, t.switch018(2));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test001/jack/Switches001.java b/jack-tests/tests/com/android/jack/switchstatement/test001/jack/Switches001.java
new file mode 100644
index 0000000..d418de7
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test001/jack/Switches001.java
@@ -0,0 +1,275 @@
+/*
+ * 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.switchstatement.test001.jack;
+
+/**
+ * Switch tests.
+ */
+public class Switches001 {
+
+ public static int switch001(int a) {
+ switch (a) {
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+ }
+
+ public int switch002(int i) {
+ switch (i) {
+ case -1:
+ return 2;
+ case 10:
+ case 15:
+ return 20;
+ default:
+ return -1;
+ }
+ }
+
+ public int switch003(int i) {
+ switch (i) {
+ case -1:
+ return 1;
+ case 15:
+ return 2;
+ }
+ return -1;
+ }
+
+ public int switch004(int i, int j) {
+ switch (i) {
+ case 1:
+ switch (j) {
+ case 10:
+ return 11;
+ case 20:
+ return 12;
+ default:
+ break;
+ }
+ case 2:
+ switch (j) {
+ case 10:
+ return 21;
+ case 20:
+ return 22;
+ default:
+ break;
+ }
+ default:
+ return -1;
+ }
+ }
+
+ public int switch005(int i) {
+ switch (i) {
+ case 1: {
+ return 2;
+ }
+ case 3: {
+ return 4;
+ }
+ default: {
+ break;
+ }
+ }
+ return -1;
+ }
+
+ public int switch006(int i) {
+ switch (i) {
+ case 3: {
+ return 3;
+ }
+ case 1: {
+ return 1;
+ }
+ case 2: {
+ return 2;
+ }
+ default: {
+ break;
+ }
+ }
+ return -1;
+ }
+
+ public int switch007(int i) {
+ int result = 0;
+ switch (i) {
+ case 3:
+ case 1: {
+ result = result + 2;
+ break;
+ }
+ case 2: {
+ return 2;
+ }
+ default: {
+ break;
+ }
+ }
+ result = result + 2;
+ return result;
+ }
+
+ public int switch008(int i) {
+ int result = 0;
+ switch (i) {
+ case 3:
+ case 1: {
+ result = result + 2;
+ switch (i) {
+ case 3:
+ result = result + 2;
+ break;
+ case 1:
+ }
+ result = result + 2;
+ break;
+ }
+ case 2: {
+ return 2;
+ }
+ default: {
+ break;
+ }
+ }
+ result = result + 2;
+ return result;
+ }
+
+ public char switch009(char c) {
+ switch (c) {
+ case '#':
+ return '#';
+ case 'A':
+ return 'A';
+ }
+ return ' ';
+ }
+
+ public int switch010(byte c) {
+ switch (c) {
+ case (byte) 1:
+ return 1;
+ case (short) 2:
+ return 2;
+ }
+ return 3;
+ }
+
+ public int switch011(int c) {
+ switch (c) {
+ default:
+ return 2;
+ }
+ }
+
+ public int switch012(int c) {
+ switch (c) {
+ }
+ return 1;
+ }
+
+ public int switch013(int c) {
+ switch (c) {
+ default:
+ }
+ return 1;
+ }
+
+ public int switch014(int c) {
+ switch (c) {
+ default:
+ break;
+ }
+ return 1;
+ }
+
+ public int switch015(int c) {
+ switch (c) {
+ default:
+ if (c == 5) {
+ break;
+ }
+ break;
+ }
+ return 1;
+ }
+
+ public int switch016(int c) {
+ switch (c) {
+ default:
+ if (c == 1) {
+ switch (c) {
+ case 1:
+ return 1;
+ case 3 :
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ break;
+ }
+ return 2;
+ }
+
+ public int switch017(int c) {
+ switch (c) {
+ default:
+ if (c == 1) {
+ int lv = c;
+ while (true) {
+ lv += 5;
+ break;
+ }
+ return lv;
+ }
+ break;
+ }
+ return 2;
+ }
+
+ public int switch018(int c) {
+ labelSwitch: switch (c) {
+ default:
+ if (c == 1) {
+ int lv = c;
+ while (true) {
+ lv += 5;
+ break;
+ }
+ switch (c) {
+ case 1:
+ break labelSwitch;
+ default:
+ break;
+ }
+ return 1;
+ }
+ break;
+ }
+ return 2;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test002/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test002/dx/Tests.java
new file mode 100644
index 0000000..78cd45e
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test002/dx/Tests.java
@@ -0,0 +1,36 @@
+/*
+ * 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.switchstatement.test002.dx;
+
+import com.android.jack.switchstatement.test002.jack.Switches002;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Switches002 s = new Switches002();
+ Assert.assertEquals(3, s.f);
+ Assert.assertEquals(0, s.m(new int[]{1,2,3}));
+ Assert.assertEquals(0, s.m(5, 8));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test002/jack/Switches002.java b/jack-tests/tests/com/android/jack/switchstatement/test002/jack/Switches002.java
new file mode 100644
index 0000000..978dd09
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test002/jack/Switches002.java
@@ -0,0 +1,45 @@
+/*
+ * 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.switchstatement.test002.jack;
+
+/**
+ * Switch tests.
+ */
+public class Switches002 {
+ public int f = 2;
+
+ {
+ int a = 0;
+ switch (a) {
+ case 0:
+ f = 3;
+ }
+ }
+
+ public static int m(int[] tab) {
+ switch (tab.length) {
+ }
+
+ return 0;
+ }
+
+ public static int m(int a, int b) {
+ switch (a+b) {
+ }
+ return 0;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test003/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test003/dx/Tests.java
new file mode 100644
index 0000000..b7784ed
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test003/dx/Tests.java
@@ -0,0 +1,45 @@
+/*
+ * 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.switchstatement.test003.dx;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.android.jack.switchstatement.test003.jack.Switches003;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test2() {
+ Switches003 s = new Switches003();
+ try {
+ s.getValue(null);
+ Assert.fail();
+ } catch (NullPointerException npe) {
+ // OK
+ }
+ }
+
+ @Test
+ public void test3() {
+ Assert.assertEquals(0, Switches003.getValue2(2));
+ Assert.assertEquals(Integer.MIN_VALUE, Switches003.getValue2(Integer.MIN_VALUE));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test003/jack/Switches003.java b/jack-tests/tests/com/android/jack/switchstatement/test003/jack/Switches003.java
new file mode 100644
index 0000000..ad65064
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test003/jack/Switches003.java
@@ -0,0 +1,39 @@
+/*
+ * 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.switchstatement.test003.jack;
+
+/**
+ * Switch tests.
+ */
+public class Switches003 {
+ public void getValue(int[] a) {
+ switch(a[0]) {
+ default :
+ }
+ }
+
+ public static int getValue2(int a) {
+ switch(a) {
+ case Integer.MIN_VALUE:
+ return Integer.MIN_VALUE;
+ case 1:
+ return 1;
+ default :
+ return 0;
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test004/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test004/dx/Tests.java
new file mode 100644
index 0000000..0488f16
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test004/dx/Tests.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.switchstatement.test004.dx;
+
+import com.android.jack.switchstatement.test004.jack.Data;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class Tests {
+
+ @Test
+ public void test() {
+ Assert.assertEquals(2, Data.get(0));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test004/jack/Data.java b/jack-tests/tests/com/android/jack/switchstatement/test004/jack/Data.java
new file mode 100644
index 0000000..19a556c
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test004/jack/Data.java
@@ -0,0 +1,36 @@
+/*
+ * 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.switchstatement.test004.jack;
+
+public class Data {
+
+ private static final int SHIFT = 30;
+ public static final int VALUE1 = 1 << SHIFT;
+ public static final int VALUE2 = 2 << SHIFT;
+
+ public static int getSwitchValue() {
+ return VALUE2;
+ }
+
+ public static int get(int v) {
+ switch(getSwitchValue()) {
+ case VALUE1: return 1;
+ case VALUE2: return 2;
+ default: return 0;
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test005/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test005/dx/Tests.java
new file mode 100644
index 0000000..252b4eb
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test005/dx/Tests.java
@@ -0,0 +1,56 @@
+/*
+ * 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.switchstatement.test005.dx;
+
+import com.android.jack.switchstatement.test005.jack.Switch;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Assert.assertEquals(1, Switch.switch001(1));
+ Assert.assertEquals(2, Switch.switch001(2));
+ Assert.assertEquals(3, Switch.switch001(3));
+ }
+
+ @Test
+ public void test2() {
+ Assert.assertEquals(1, Switch.switch002(1));
+ Assert.assertEquals(2, Switch.switch002(2));
+ Assert.assertEquals(3, Switch.switch002(3));
+ }
+
+ @Test
+ public void test3() {
+ Assert.assertEquals(1, Switch.switch003(1));
+ Assert.assertEquals(2, Switch.switch003(2));
+ Assert.assertEquals(3, Switch.switch003(3));
+ }
+
+ @Test
+ public void test4() {
+ Assert.assertEquals(1, Switch.switch004(1));
+ Assert.assertEquals(2, Switch.switch004(2));
+ Assert.assertEquals(3, Switch.switch004(3));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test005/jack/Switch.java b/jack-tests/tests/com/android/jack/switchstatement/test005/jack/Switch.java
new file mode 100644
index 0000000..3fd90b2
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test005/jack/Switch.java
@@ -0,0 +1,77 @@
+/*
+ * 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.switchstatement.test005.jack;
+
+public class Switch {
+ public static int switch001(int a) {
+ switch (a) {
+ case 1:
+ return 1;
+ case 2:
+ return 2;
+ default:
+ return 3;
+ }
+ }
+
+ public static int switch002(int a) {
+ switch (a) {
+ case 1:
+ return 1;
+ case 2: {
+ switch (a) {
+ case 1:
+ return 11;
+ default:
+ break;
+ }
+ return 2;
+ }
+ }
+ return 3;
+ }
+
+ public static int switch003(int a) {
+ switch (a) {
+ case (byte) 1:
+ return 1;
+ case (short) 3:
+ return 3;
+ case (char) 2:
+ return 2;
+ default:
+ return 3;
+ }
+ }
+
+ public static int switch004(int a) {
+ switch (a) {
+ case 1:
+ return 1;
+ case 3:
+ return 3;
+ case (char) 2:
+ return 2;
+ case (char) -1:
+ return -1;
+ case -2:
+ return -2;
+ default:
+ return 3;
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test006/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test006/dx/Tests.java
new file mode 100644
index 0000000..60e0aee
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test006/dx/Tests.java
@@ -0,0 +1,64 @@
+/*
+ * 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.switchstatement.test006.dx;
+
+import com.android.jack.switchstatement.test006.jack.Switch;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Assert.assertEquals(3, Switch.switch001(new Switch.A()));
+ try {
+ Switch.switch001(null);
+ Assert.fail();
+ } catch (NullPointerException npe) {
+ // It is ok
+ }
+ }
+
+ @Test
+ public void test2() {
+ try {
+ Switch.switch002();
+ Assert.fail();
+ } catch (ExceptionInInitializerError npe) {
+ // It is ok
+ }
+ }
+
+ public void test3() {
+ try {
+ Switch.switch003(new Switch.A());
+ Assert.fail();
+ } catch (ExceptionInInitializerError npe) {
+ // It is ok
+ }
+ }
+
+ public void test4() {
+ Assert.assertEquals(1, Switch.switch004(0)) ;
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test006/jack/Switch.java b/jack-tests/tests/com/android/jack/switchstatement/test006/jack/Switch.java
new file mode 100644
index 0000000..83251db
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test006/jack/Switch.java
@@ -0,0 +1,65 @@
+/*
+ * 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.switchstatement.test006.jack;
+
+public class Switch {
+
+ public static class A {
+ public int value;
+ }
+
+ public static class B {
+ public static int value;
+ static {
+ int i = 0;
+ if (i != 1) {
+ throw new NullPointerException();
+ }
+ }
+ }
+
+ public static int switch001(A a) {
+ switch (a.value) {
+ default:
+ return 3;
+ }
+ }
+
+ public static int switch002() {
+ switch (B.value) {
+ default:
+ return 3;
+ }
+ }
+
+ @SuppressWarnings({"boxing", "cast"})
+ public static int switch003(A a) {
+ switch ((Integer) a.value) {
+ default:
+ return 3;
+ }
+ }
+
+ public static int switch004(int i) {
+ int [] array = {1, 2};
+ switch (array[i++]) {
+ default:
+ return i;
+ }
+ }
+
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test007/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test007/dx/Tests.java
new file mode 100644
index 0000000..a976bd0
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test007/dx/Tests.java
@@ -0,0 +1,33 @@
+/*
+ * 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.switchstatement.test007.dx;
+
+import com.android.jack.switchstatement.test007.jack.Switch;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Assert.assertEquals(1, Switch.switch001());
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test007/jack/Switch.java b/jack-tests/tests/com/android/jack/switchstatement/test007/jack/Switch.java
new file mode 100644
index 0000000..4a22a26
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test007/jack/Switch.java
@@ -0,0 +1,33 @@
+/*
+ * 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.switchstatement.test007.jack;
+
+public class Switch {
+
+ public static int switch001() {
+ switch (1) {
+ default:
+ return 3;
+ case 1: {
+ return 1;
+ }
+ case 2: {
+ return 2;
+ }
+ }
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test008/dx/Tests.java b/jack-tests/tests/com/android/jack/switchstatement/test008/dx/Tests.java
new file mode 100644
index 0000000..550b588
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test008/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.switchstatement.test008.dx;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.android.jack.switchstatement.test008.jack.Switch;
+
+/**
+ * Tests about switches.
+ */
+public class Tests {
+
+ @Test
+ public void test1() {
+ Assert.assertEquals(1, Switch.switch001(1));
+ Assert.assertEquals(-1, Switch.switch001(2));
+ Assert.assertEquals(-1, Switch.switch001(255));
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test008/jack/Switch.java b/jack-tests/tests/com/android/jack/switchstatement/test008/jack/Switch.java
new file mode 100644
index 0000000..d9ac67d
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test008/jack/Switch.java
@@ -0,0 +1,48 @@
+/*
+ * 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.switchstatement.test008.jack;
+
+public class Switch {
+
+ public final class SwitchValues {
+ public static final int ZERO = 0;
+ public static final int ONE = 1;
+ public static final int UNSUPPORTED = 255;
+ }
+
+ /**
+ * Check that the control flow graph does not contains useless edge/block when a case fall-through
+ * to the default case. The case SwitchValues.UNSUPPORTED and SwitchValues.ZERO are uselesses and
+ * must be remove to generate packed switch instead of sparsed switch.
+ */
+ public static int switch001(int switchValue) {
+ int retValue;
+ switch (switchValue) {
+ case SwitchValues.ONE: {
+ retValue = 1;
+ break;
+ }
+ case SwitchValues.ZERO:
+ case SwitchValues.UNSUPPORTED: {
+ }
+ default:
+ retValue = -1;
+ }
+
+ return retValue;
+ }
+}
diff --git a/jack-tests/tests/com/android/jack/switchstatement/test009/jack/Switch.java b/jack-tests/tests/com/android/jack/switchstatement/test009/jack/Switch.java
new file mode 100644
index 0000000..f1a12bf
--- /dev/null
+++ b/jack-tests/tests/com/android/jack/switchstatement/test009/jack/Switch.java
@@ -0,0 +1,50 @@
+/*
+ * 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.switchstatement.test009.jack;
+
+/**
+ * Test allowing to check that 'packed-switch-payload' into generated dex is as small as possible.
+ */
+public class Switch {
+
+ public static enum Num {
+ ZERO,
+ ONE,
+ TWO,
+ THREE,
+ FOUR,
+ FIVE,
+ SIX,
+ SEVEN,
+ EIGHT,
+ NINE,
+ TEN
+ }
+
+ public static boolean switch1(Num num) {
+ switch (num) {
+ case ZERO:
+ case ONE:
+ case TWO:
+ case THREE:
+ case TEN:
+ return true;
+ default:
+ return false;
+ }
+ }
+}