1705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain/* 2705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * Copyright (C) 2014 The Android Open Source Project 3705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * 4705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * Licensed under the Apache License, Version 2.0 (the "License"); 5705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * you may not use this file except in compliance with the License. 6705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * You may obtain a copy of the License at 7705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * 8705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * http://www.apache.org/licenses/LICENSE-2.0 9705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * 10705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * Unless required by applicable law or agreed to in writing, software 11705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * distributed under the License is distributed on an "AS IS" BASIS, 12705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * See the License for the specific language governing permissions and 14705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain * limitations under the License. 15705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain */ 16705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 17705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillainimport java.lang.reflect.Method; 18705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 19705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillainpublic class Main { 20705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 21705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain public static void expectEquals(int expected, int result) { 22705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain if (expected != result) { 23705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain throw new Error("Expected: " + expected + ", found: " + result); 24705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 25705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 26705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 27705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain public static void expectEquals(long expected, long result) { 28705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain if (expected != result) { 29705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain throw new Error("Expected: " + expected + ", found: " + result); 30705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 31705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 32705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 33705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain public static void main(String[] args) throws Exception { 34705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain notInt(); 35705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain notLong(); 36705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 37705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 38705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain private static void notInt() throws Exception { 39705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(1, smaliNotInt(-2)); 40705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(0, smaliNotInt(-1)); 41705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(-1, smaliNotInt(0)); 42705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(-2, smaliNotInt(1)); 43946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(2147483647, smaliNotInt(-2147483648)); // -(2^31) 44946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(2147483646, smaliNotInt(-2147483647)); // -(2^31 - 1) 45946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-2147483647, smaliNotInt(2147483646)); // 2^31 - 2 46946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-2147483648, smaliNotInt(2147483647)); // 2^31 - 1 47705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 48705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 49705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain private static void notLong() throws Exception { 50705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(1L, smaliNotLong(-2L)); 51705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(0L, smaliNotLong(-1L)); 52705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(-1L, smaliNotLong(0L)); 53705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain expectEquals(-2L, smaliNotLong(1L)); 54946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(2147483647L, smaliNotLong(-2147483648L)); // -(2^31) 55946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(2147483646L, smaliNotLong(-2147483647L)); // -(2^31 - 1) 56946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-2147483647L, smaliNotLong(2147483646L)); // 2^31 - 2 57946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-2147483648L, smaliNotLong(2147483647L)); // 2^31 - 1 58946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(9223372036854775807L, smaliNotLong(-9223372036854775808L)); // -(2^63) 59946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(9223372036854775806L, smaliNotLong(-9223372036854775807L)); // -(2^63 - 1) 60946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-9223372036854775807L, smaliNotLong(9223372036854775806L)); // 2^63 - 2 61946e143941d456a4ec666f7f54719c65c5aa3f5dRoland Levillain expectEquals(-9223372036854775808L, smaliNotLong(9223372036854775807L)); // 2^63 - 1 62705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 63705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 64705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain // Wrappers around methods located in file not.smali. 65705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 66705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain private static int smaliNotInt(int a) throws Exception { 67705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain Class<?> c = Class.forName("TestNot"); 68705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain Method m = c.getMethod("$opt$NotInt", int.class); 69705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain int result = (Integer)m.invoke(null, a); 70705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain return result; 71705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 72705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain 73705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain private static long smaliNotLong(long a) throws Exception { 74705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain Class<?> c = Class.forName("TestNot"); 75705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain Method m = c.getMethod("$opt$NotLong", long.class); 76705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain long result = (Long)m.invoke(null, a); 77705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain return result; 78705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain } 79705664321a5cc1418255172f92d7d7195cf60a7bRoland Levillain} 80