blob: 26e206c94dc473238a216a7a4141d980d48500f6 [file] [log] [blame]
Roland Levillain70566432014-10-24 16:20:17 +01001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import java.lang.reflect.Method;
18
19public class Main {
20
21 public static void expectEquals(int expected, int result) {
22 if (expected != result) {
23 throw new Error("Expected: " + expected + ", found: " + result);
24 }
25 }
26
27 public static void expectEquals(long expected, long result) {
28 if (expected != result) {
29 throw new Error("Expected: " + expected + ", found: " + result);
30 }
31 }
32
33 public static void main(String[] args) throws Exception {
34 notInt();
35 notLong();
36 }
37
38 private static void notInt() throws Exception {
39 expectEquals(1, smaliNotInt(-2));
40 expectEquals(0, smaliNotInt(-1));
41 expectEquals(-1, smaliNotInt(0));
42 expectEquals(-2, smaliNotInt(1));
43 expectEquals(2147483647, smaliNotInt(-2147483648)); // (2^31) - 1
44 expectEquals(2147483646, smaliNotInt(-2147483647)); // (2^31) - 2
45 expectEquals(-2147483647, smaliNotInt(2147483646)); // -(2^31) - 1
46 expectEquals(-2147483648, smaliNotInt(2147483647)); // -(2^31)
47 }
48
49 private static void notLong() throws Exception {
50 expectEquals(1L, smaliNotLong(-2L));
51 expectEquals(0L, smaliNotLong(-1L));
52 expectEquals(-1L, smaliNotLong(0L));
53 expectEquals(-2L, smaliNotLong(1L));
54 expectEquals(2147483647L, smaliNotLong(-2147483648L)); // (2^31) - 1
55 expectEquals(2147483646L, smaliNotLong(-2147483647L)); // (2^31) - 2
56 expectEquals(-2147483647L, smaliNotLong(2147483646L)); // -(2^31) - 1
57 expectEquals(-2147483648L, smaliNotLong(2147483647L)); // -(2^31)
58 expectEquals(9223372036854775807L, smaliNotLong(-9223372036854775808L)); // (2^63) - 1
59 expectEquals(9223372036854775806L, smaliNotLong(-9223372036854775807L)); // (2^63) - 2
60 expectEquals(-9223372036854775807L, smaliNotLong(9223372036854775806L)); // -(2^63) - 1
61 expectEquals(-9223372036854775808L, smaliNotLong(9223372036854775807L)); // -(2^63)
62 }
63
64 // Wrappers around methods located in file not.smali.
65
66 private static int smaliNotInt(int a) throws Exception {
67 Class<?> c = Class.forName("TestNot");
68 Method m = c.getMethod("$opt$NotInt", int.class);
69 int result = (Integer)m.invoke(null, a);
70 return result;
71 }
72
73 private static long smaliNotLong(long a) throws Exception {
74 Class<?> c = Class.forName("TestNot");
75 Method m = c.getMethod("$opt$NotLong", long.class);
76 long result = (Long)m.invoke(null, a);
77 return result;
78 }
79}