18fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe/*
28fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * Copyright (C) 2014 The Android Open Source Project
38fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe *
48fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * Licensed under the Apache License, Version 2.0 (the "License");
58fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * you may not use this file except in compliance with the License.
68fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * You may obtain a copy of the License at
78fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe *
88fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe *      http://www.apache.org/licenses/LICENSE-2.0
98fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe *
108fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * Unless required by applicable law or agreed to in writing, software
118fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * distributed under the License is distributed on an "AS IS" BASIS,
128fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * See the License for the specific language governing permissions and
148fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * limitations under the License.
158fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe */
168fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
17920506d4509fef2486a099c005ec134a5d22ec11Vladimir Markoimport java.lang.reflect.InvocationTargetException;
188fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampeimport java.lang.reflect.Method;
198e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogersimport java.lang.reflect.Modifier;
208fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampeimport java.util.LinkedList;
218fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampeimport java.util.List;
228fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
238fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe/**
248fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe * Smali excercise.
258fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe */
268fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampepublic class Main {
278fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
288fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    private static class TestCase {
298fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        public TestCase(String testName, String testClass, String testMethodName, Object[] values,
308fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                        Throwable expectedException, Object expectedReturn) {
318fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.testName = testName;
328fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.testClass = testClass;
338fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.testMethodName = testMethodName;
348fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.values = values;
358fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.expectedException = expectedException;
368fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            this.expectedReturn = expectedReturn;
378fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        }
388fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
398fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        String testName;
408fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        String testClass;
418fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        String testMethodName;
428fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        Object[] values;
438fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        Throwable expectedException;
448fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        Object expectedReturn;
458fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    }
468fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
478fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    private List<TestCase> testCases;
488fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
498fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    public Main() {
508fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        // Create the test cases.
518fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        testCases = new LinkedList<TestCase>();
526489d22a44ea7d135c142ee94925570d0333d5e7buzbee        testCases.add(new TestCase("PackedSwitch", "PackedSwitch", "packedSwitch",
53270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                new Object[]{123}, null, 123));
545469d3444614be1d29302aef75210119df453721David Brazdil        testCases.add(new TestCase("PackedSwitch key INT_MAX", "PackedSwitch",
555469d3444614be1d29302aef75210119df453721David Brazdil                "packedSwitch_INT_MAX", new Object[]{123}, null, 123));
565469d3444614be1d29302aef75210119df453721David Brazdil        testCases.add(new TestCase("PackedSwitch key overflow", "b_24399945",
575469d3444614be1d29302aef75210119df453721David Brazdil                "packedSwitch_overflow", new Object[]{123}, new VerifyError(), null));
588fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
598fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        testCases.add(new TestCase("b/17790197", "B17790197", "getInt", null, null, 100));
608fe0e35c546921a3576411948efffb3c813ef686Stephen Kyle        testCases.add(new TestCase("FloatBadArgReg", "FloatBadArgReg", "getInt",
61270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                new Object[]{100}, null, 100));
62d24c9346138b7b8723461d94d9866762a59929d9nikolay serdjuk        testCases.add(new TestCase("negLong", "negLong", "negLong", null, null, 122142L));
637a7c1db21782fb922d3ffc5c576117812624ea58Vladimir Marko        testCases.add(new TestCase("sameFieldNames", "sameFieldNames", "getInt", null, null, 7));
64920506d4509fef2486a099c005ec134a5d22ec11Vladimir Marko        testCases.add(new TestCase("b/18380491", "B18380491ConcreteClass", "foo",
65270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                new Object[]{42}, null, 42));
66920506d4509fef2486a099c005ec134a5d22ec11Vladimir Marko        testCases.add(new TestCase("invoke-super abstract", "B18380491ConcreteClass", "foo",
67270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                new Object[]{0}, new AbstractMethodError(), null));
68270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("BadCaseInOpRegRegReg", "BadCaseInOpRegRegReg", "getInt", null,
69270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                null, 2));
7032b2a52aa3d6dc25c18422514c7f88757f87d33cNicolas Geoffray        testCases.add(new TestCase("CmpLong", "CmpLong", "run", null, null, 0));
71270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("FloatIntConstPassing", "FloatIntConstPassing", "run", null,
72270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                null, 2));
73341e425599ba32f0776bcd294882e1e30cafa10fVladimir Marko        testCases.add(new TestCase("b/18718277", "B18718277", "getInt", null, null, 0));
74270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("b/18800943 (1)", "B18800943_1", "n_a", null, new VerifyError(),
75270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                0));
76270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("b/18800943 (2)", "B18800943_2", "n_a", null, new VerifyError(),
77270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                0));
78270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("MoveExc", "MoveExc", "run", null, new ArithmeticException(),
79270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz                null));
80270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz        testCases.add(new TestCase("MoveExceptionOnEntry", "MoveExceptionOnEntry",
81270a0e16c3b8e5b95cbfdbd8996ac137c7c6322bSebastien Hertz            "moveExceptionOnEntry", new Object[]{0}, new VerifyError(), null));
829ccd151d0d27a729f88af9d00285afe4d147981aJeff Hao        testCases.add(new TestCase("EmptySparseSwitch", "EmptySparseSwitch", "run", null, null,
839ccd151d0d27a729f88af9d00285afe4d147981aJeff Hao                null));
84b588f4c037d27dedeef358b478c281ebb3fbb900Andreas Gampe        testCases.add(new TestCase("b/20224106", "B20224106", "run", null, new VerifyError(),
85b588f4c037d27dedeef358b478c281ebb3fbb900Andreas Gampe                0));
86da9badb9edea5e0d18cd9f97eff0d0937ad48310Andreas Gampe        testCases.add(new TestCase("b/17410612", "B17410612", "run", null, new VerifyError(),
87da9badb9edea5e0d18cd9f97eff0d0937ad48310Andreas Gampe                0));
88ea9ef4dccf8af7ef9865b373ea6da00f007cf641Nicolas Geoffray        testCases.add(new TestCase("b/21863767", "B21863767", "run", null, null,
8969505f86a1a653bf86c1f2b423b3e0605137d5d1Nicolas Geoffray                null));
902d1a0a408fd148f7b2a2d670e6942ec3d920f875Vladimir Marko        testCases.add(new TestCase("b/21873167", "B21873167", "test", null, null, null));
91f11c420c448baffac6a70ac0884d481ab347e257Vladimir Marko        testCases.add(new TestCase("b/21614284", "B21614284", "test", new Object[] { null },
92d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe                new NullPointerException(), null));
93dde9827f75d1e1e9cd4b7e6b54086aec54f29b5fJeff Hao        testCases.add(new TestCase("b/21902684", "B21902684", "test", null, null, null));
94a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe        testCases.add(new TestCase("b/22045582", "B22045582", "run", null, new VerifyError(),
95a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe                0));
96a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe        testCases.add(new TestCase("b/22045582 (int)", "B22045582Int", "run", null,
97a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe                new VerifyError(), 0));
98a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe        testCases.add(new TestCase("b/22045582 (wide)", "B22045582Wide", "run", null,
99a32210c53d23b73ba769053b8c1b214a7468fe6eAndreas Gampe                new VerifyError(), 0));
100414000ec4d728b5c85f8c6dee4f867fecde59b01Vladimir Marko        testCases.add(new TestCase("b/21886894", "B21886894", "test", null, new VerifyError(),
101d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe                null));
102d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe        testCases.add(new TestCase("b/22080519", "B22080519", "run", null,
103d12e782bcee03ecb6dec41aa9673ef53b638dceaAndreas Gampe                new NullPointerException(), null));
104d5ad72fb8ca28ee4fa4109fa7154e08d0c4ac4d3Andreas Gampe        testCases.add(new TestCase("b/21645819", "B21645819", "run", new Object[] { null },
105d5ad72fb8ca28ee4fa4109fa7154e08d0c4ac4d3Andreas Gampe                null, null));
106185a5586c8b796e770e9b4b7ac2befa8ccdaca7eAndreas Gampe        testCases.add(new TestCase("b/22244733", "B22244733", "run", new Object[] { "abc" },
107185a5586c8b796e770e9b4b7ac2befa8ccdaca7eAndreas Gampe                null, "abc"));
10838536287f61c9c0fc3bab8c1950cf8c74881482aAndreas Gampe        testCases.add(new TestCase("b/22331663", "B22331663", "run", new Object[] { false },
10938536287f61c9c0fc3bab8c1950cf8c74881482aAndreas Gampe                null, null));
11097a1ff353f254b6e46c7501fe3f0e3254c2517b4Andreas Gampe        testCases.add(new TestCase("b/22331663 (pass)", "B22331663Pass", "run",
11197a1ff353f254b6e46c7501fe3f0e3254c2517b4Andreas Gampe                new Object[] { false }, null, null));
11297a1ff353f254b6e46c7501fe3f0e3254c2517b4Andreas Gampe        testCases.add(new TestCase("b/22331663 (fail)", "B22331663Fail", "run",
11397a1ff353f254b6e46c7501fe3f0e3254c2517b4Andreas Gampe                new Object[] { false }, new VerifyError(), null));
114891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe        testCases.add(new TestCase("b/22411633 (1)", "B22411633_1", "run", new Object[] { false },
115891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe                null, null));
116891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe        testCases.add(new TestCase("b/22411633 (2)", "B22411633_2", "run", new Object[] { false },
117891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe                new VerifyError(), null));
118891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe        testCases.add(new TestCase("b/22411633 (3)", "B22411633_3", "run", new Object[] { false },
119891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe                null, null));
120891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe        testCases.add(new TestCase("b/22411633 (4)", "B22411633_4", "run", new Object[] { false },
121891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe                new VerifyError(), null));
122891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe        testCases.add(new TestCase("b/22411633 (5)", "B22411633_5", "run", new Object[] { false },
123891dfaa94eda54ab620d203200191c4be46afb70Andreas Gampe                null, null));
124be2aa44277e5be04d6e3a9b80af9df01e26b73c0Andreas Gampe        testCases.add(new TestCase("b/22777307", "B22777307", "run", null, new InstantiationError(),
125be2aa44277e5be04d6e3a9b80af9df01e26b73c0Andreas Gampe                null));
1262ea7b70b2347969f3735bd0ec1b462bd6d2ff1bdAndreas Gampe        testCases.add(new TestCase("b/22881413", "B22881413", "run", null, null, null));
127f10b6e109bfb595b6752d1b59db680694ac1684dAndreas Gampe        testCases.add(new TestCase("b/20843113", "B20843113", "run", null, null, null));
1284bf4c78a6e8b7da7cf306e1dd17ff5a55d0c6c98Andreas Gampe        testCases.add(new TestCase("b/23201502 (float)", "B23201502", "runFloat", null,
1294bf4c78a6e8b7da7cf306e1dd17ff5a55d0c6c98Andreas Gampe                new NullPointerException(), null));
1304bf4c78a6e8b7da7cf306e1dd17ff5a55d0c6c98Andreas Gampe        testCases.add(new TestCase("b/23201502 (double)", "B23201502", "runDouble", null,
1314bf4c78a6e8b7da7cf306e1dd17ff5a55d0c6c98Andreas Gampe                new NullPointerException(), null));
132f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe        testCases.add(new TestCase("b/23300986", "B23300986", "runAliasAfterEnter",
133f5cdc417be5958eaed2172667178ae87ccc51c56Andreas Gampe                new Object[] { new Object() }, null, null));
134c147410b4459aeda08fc0cd8b6df089d75f4e573Andreas Gampe        testCases.add(new TestCase("b/23300986 (2)", "B23300986", "runAliasBeforeEnter",
135c147410b4459aeda08fc0cd8b6df089d75f4e573Andreas Gampe                new Object[] { new Object() }, null, null));
136ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe        testCases.add(new TestCase("b/23502994 (if-eqz)", "B23502994", "runIF_EQZ",
137ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe                new Object[] { new Object() }, null, null));
138ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe        testCases.add(new TestCase("b/23502994 (check-cast)", "B23502994", "runCHECKCAST",
139ad238ce884468234509a9367c0ce1055bd1394bfAndreas Gampe                new Object[] { "abc" }, null, null));
140a4c98f292f6471f88816ce74046ecc85bc57e6b3Andreas Gampe        testCases.add(new TestCase("b/25494456", "B25494456", "run", null, new VerifyError(),
141a4c98f292f6471f88816ce74046ecc85bc57e6b3Andreas Gampe                null));
14242ef8ab151a3d0cbb42cb43f6841c3708d65fca3Andreas Gampe        testCases.add(new TestCase("b/21869691", "B21869691A", "run", null,
14342ef8ab151a3d0cbb42cb43f6841c3708d65fca3Andreas Gampe                new IncompatibleClassChangeError(), null));
14497b113596576ee026c9d3e100e472e343bfda7faAndreas Gampe        testCases.add(new TestCase("b/26143249", "B26143249", "run", null,
14597b113596576ee026c9d3e100e472e343bfda7faAndreas Gampe                new AbstractMethodError(), null));
14687a5575ada60051a3d45630da9ae3d634b993b60David Brazdil        testCases.add(new TestCase("b/26579108", "B26579108", "run", null, new VerifyError(),
14787a5575ada60051a3d45630da9ae3d634b993b60David Brazdil                null));
14868b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (1)", "B26594149_1", "run", null, new VerifyError(),
14968b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
15068b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (2)", "B26594149_2", "run", null, new VerifyError(),
15168b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
15268b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (3)", "B26594149_3", "run", null, new VerifyError(),
15368b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
15468b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (4)", "B26594149_4", "run", null, new VerifyError(),
15568b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
15668b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (5)", "B26594149_5", "run", null, null, null));
15768b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (6)", "B26594149_6", "run", null, new VerifyError(),
15868b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
15968b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (7)", "B26594149_7", "run", null, new VerifyError(),
16068b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
16168b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil        testCases.add(new TestCase("b/26594149 (8)", "B26594149_8", "run", null, new VerifyError(),
16268b5c0b677bae53b3bae5d1890e21fae527f3df3David Brazdil                null));
163980027c7f22f332ad224f662add0df197e71f137Pavel Vyssotski        testCases.add(new TestCase("b/27148248", "B27148248", "run", null, new VerifyError(),
164980027c7f22f332ad224f662add0df197e71f137Pavel Vyssotski                null));
1654a2c8fc0fc47631550bc5ff8edd8221a3aea1b23Alex Light        testCases.add(new TestCase("b/26965384", "B26965384", "run", null, new VerifyError(),
1664a2c8fc0fc47631550bc5ff8edd8221a3aea1b23Alex Light                null));
167bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe        testCases.add(new TestCase("b/27799205 (1)", "B27799205Helper", "run1", null, null, null));
168bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe        testCases.add(new TestCase("b/27799205 (2)", "B27799205Helper", "run2", null,
169bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe                new VerifyError(), null));
170bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe        testCases.add(new TestCase("b/27799205 (3)", "B27799205Helper", "run3", null,
171bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe                new VerifyError(), null));
172bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe        testCases.add(new TestCase("b/27799205 (4)", "B27799205Helper", "run4", null,
173bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe                new VerifyError(), null));
174bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe        testCases.add(new TestCase("b/27799205 (5)", "B27799205Helper", "run5", null,
175bb18a03c44d99b3cae232d445d56e80d8388cca9Andreas Gampe                new VerifyError(), null));
1768d8fc48664205e433cfa5540753b38043d918873Andreas Gampe        testCases.add(new TestCase("b/27799205 (6)", "B27799205Helper", "run6", null, null, null));
177c69c0acadd5b83b467de24d1b5872daf0ac9cf8aAndreas Gampe        testCases.add(new TestCase("b/28187158", "B28187158", "run", new Object[] { null} ,
178c69c0acadd5b83b467de24d1b5872daf0ac9cf8aAndreas Gampe                new VerifyError(), null));
179df2d4f22d5e89692c90b443da82fe2930518418bArtem Udovichenko        testCases.add(new TestCase("b/29778499 (1)", "B29778499_1", "run", null,
180df2d4f22d5e89692c90b443da82fe2930518418bArtem Udovichenko                new IncompatibleClassChangeError(), null));
181df2d4f22d5e89692c90b443da82fe2930518418bArtem Udovichenko        testCases.add(new TestCase("b/29778499 (2)", "B29778499_2", "run", null,
182df2d4f22d5e89692c90b443da82fe2930518418bArtem Udovichenko                new IncompatibleClassChangeError(), null));
1838fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    }
1848fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
1858fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    public void runTests() {
1868fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        for (TestCase tc : testCases) {
1878fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            System.out.println(tc.testName);
1888fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            try {
1898fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                runTest(tc);
1908fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            } catch (Exception exc) {
1918fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                exc.printStackTrace(System.out);
1928fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            }
1938fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        }
1948fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    }
1958fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
1968fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    private void runTest(TestCase tc) throws Exception {
1978fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        Exception errorReturn = null;
1988fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        try {
1998e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            Class<?> c = Class.forName(tc.testClass);
2008e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
2018e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            Method[] methods = c.getDeclaredMethods();
2028e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
2038e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            // For simplicity we assume that test methods are not overloaded. So searching by name
2048e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            // will give us the method we need to run.
2058e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            Method method = null;
2068e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            for (Method m : methods) {
2078e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                if (m.getName().equals(tc.testMethodName)) {
2088e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    method = m;
2098e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    break;
2108e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                }
2118fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            }
2128e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers
2138e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            if (method == null) {
2148e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                errorReturn = new IllegalArgumentException("Could not find test method " +
2158e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                           tc.testMethodName + " in class " +
2168e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                           tc.testClass + " for test " +
2178e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                           tc.testName);
2188e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            } else {
2198e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                Object retValue;
2208e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                if (Modifier.isStatic(method.getModifiers())) {
2218e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    retValue = method.invoke(null, tc.values);
2228e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                } else {
2238e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    retValue = method.invoke(method.getDeclaringClass().newInstance(), tc.values);
2248e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                }
2258e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                if (tc.expectedException != null) {
2268e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    errorReturn = new IllegalStateException("Expected an exception in test " +
2278e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                            tc.testName);
22887a5575ada60051a3d45630da9ae3d634b993b60David Brazdil                } else if (tc.expectedReturn == null && retValue != null) {
2298e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    errorReturn = new IllegalStateException("Expected a null result in test " +
2308e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                            tc.testName);
2318e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                } else if (tc.expectedReturn != null &&
2328e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                           (retValue == null || !tc.expectedReturn.equals(retValue))) {
2338e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    errorReturn = new IllegalStateException("Expected return " +
2348e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                            tc.expectedReturn +
2358e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                            ", but got " + retValue);
2368e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                } else {
2378e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                    // Expected result, do nothing.
2388e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                }
2398fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            }
2408e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers        } catch (Throwable exc) {
2418fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            if (tc.expectedException == null) {
2428fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                errorReturn = new IllegalStateException("Did not expect exception", exc);
243920506d4509fef2486a099c005ec134a5d22ec11Vladimir Marko            } else if (exc instanceof InvocationTargetException && exc.getCause() != null &&
244920506d4509fef2486a099c005ec134a5d22ec11Vladimir Marko                       exc.getCause().getClass().equals(tc.expectedException.getClass())) {
245920506d4509fef2486a099c005ec134a5d22ec11Vladimir Marko                // Expected exception is wrapped in InvocationTargetException.
2468fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            } else if (!tc.expectedException.getClass().equals(exc.getClass())) {
2478fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                errorReturn = new IllegalStateException("Expected " +
2488e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                        tc.expectedException.getClass().getName() +
2498e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers                                                        ", but got " + exc.getClass(), exc);
2508e1f4f8f848f2dbb36265a019310498a61cd674dIan Rogers            } else {
25142ef8ab151a3d0cbb42cb43f6841c3708d65fca3Andreas Gampe                // Expected exception, do nothing.
2528fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            }
2538fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        } finally {
2548fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            if (errorReturn != null) {
2558fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe                throw errorReturn;
2568fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe            }
2578fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        }
2588fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    }
2598fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
2608fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    public static void main(String[] args) throws Exception {
2618fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        Main main = new Main();
2628fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
2638fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        main.runTests();
2648fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe
2658fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe        System.out.println("Done!");
2668fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe    }
2678fda9f2aec6820ebf1bd550412ec99d9eb3ffa9eAndreas Gampe}
268