1 /* 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 17 import java.lang.reflect.Method; 18 19 public class Main { 20 expectEquals(int expected, int result)21 public static void expectEquals(int expected, int result) { 22 if (expected != result) { 23 throw new Error("Expected: " + expected + ", found: " + result); 24 } 25 } 26 expectEquals(long expected, long result)27 public static void expectEquals(long expected, long result) { 28 if (expected != result) { 29 throw new Error("Expected: " + expected + ", found: " + result); 30 } 31 } 32 main(String[] args)33 public static void main(String[] args) throws Exception { 34 notInt(); 35 notLong(); 36 } 37 notInt()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) 44 expectEquals(2147483646, smaliNotInt(-2147483647)); // -(2^31 - 1) 45 expectEquals(-2147483647, smaliNotInt(2147483646)); // 2^31 - 2 46 expectEquals(-2147483648, smaliNotInt(2147483647)); // 2^31 - 1 47 } 48 notLong()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) 55 expectEquals(2147483646L, smaliNotLong(-2147483647L)); // -(2^31 - 1) 56 expectEquals(-2147483647L, smaliNotLong(2147483646L)); // 2^31 - 2 57 expectEquals(-2147483648L, smaliNotLong(2147483647L)); // 2^31 - 1 58 expectEquals(9223372036854775807L, smaliNotLong(-9223372036854775808L)); // -(2^63) 59 expectEquals(9223372036854775806L, smaliNotLong(-9223372036854775807L)); // -(2^63 - 1) 60 expectEquals(-9223372036854775807L, smaliNotLong(9223372036854775806L)); // 2^63 - 2 61 expectEquals(-9223372036854775808L, smaliNotLong(9223372036854775807L)); // 2^63 - 1 62 } 63 64 // Wrappers around methods located in file not.smali. 65 smaliNotInt(int a)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 smaliNotLong(long a)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 } 80