1*795d594fSAndroid Build Coastguard Worker /* 2*795d594fSAndroid Build Coastguard Worker * Copyright (C) 2015 The Android Open Source Project 3*795d594fSAndroid Build Coastguard Worker * 4*795d594fSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*795d594fSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*795d594fSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*795d594fSAndroid Build Coastguard Worker * 8*795d594fSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*795d594fSAndroid Build Coastguard Worker * 10*795d594fSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*795d594fSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*795d594fSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*795d594fSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*795d594fSAndroid Build Coastguard Worker * limitations under the License. 15*795d594fSAndroid Build Coastguard Worker */ 16*795d594fSAndroid Build Coastguard Worker class Main extends Impl implements Iface { main(String[] args)17*795d594fSAndroid Build Coastguard Worker public static void main(String[] args) { 18*795d594fSAndroid Build Coastguard Worker System.loadLibrary(args[0]); 19*795d594fSAndroid Build Coastguard Worker System.out.println("Create Main instance"); 20*795d594fSAndroid Build Coastguard Worker Main m = new Main(); 21*795d594fSAndroid Build Coastguard Worker callMain(m); 22*795d594fSAndroid Build Coastguard Worker } 23*795d594fSAndroid Build Coastguard Worker callMain(Main m)24*795d594fSAndroid Build Coastguard Worker public static void callMain(Main m) { 25*795d594fSAndroid Build Coastguard Worker System.out.println("Test method with concrete implementation"); 26*795d594fSAndroid Build Coastguard Worker m.test_correct(); 27*795d594fSAndroid Build Coastguard Worker System.out.println("Test method with concrete implementation via JNI call"); 28*795d594fSAndroid Build Coastguard Worker long iface_id = GetMethodId(false, Iface.class, "test_correct", "()V"); 29*795d594fSAndroid Build Coastguard Worker long main_id = GetMethodId(false, Main.class, "test_correct", "()V"); 30*795d594fSAndroid Build Coastguard Worker long impl_id = GetMethodId(false, Impl.class, "test_correct", "()V"); 31*795d594fSAndroid Build Coastguard Worker if (iface_id != main_id) { 32*795d594fSAndroid Build Coastguard Worker System.out.println("Abstract interface and Main have different method ids"); 33*795d594fSAndroid Build Coastguard Worker } else { 34*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected: Abstract interface and Main have same method ids"); 35*795d594fSAndroid Build Coastguard Worker } 36*795d594fSAndroid Build Coastguard Worker CallNonvirtual(m, Main.class, main_id); 37*795d594fSAndroid Build Coastguard Worker 38*795d594fSAndroid Build Coastguard Worker System.out.println("Test method with no concrete implementation"); 39*795d594fSAndroid Build Coastguard Worker try { 40*795d594fSAndroid Build Coastguard Worker m.test_throws(); 41*795d594fSAndroid Build Coastguard Worker } catch (AbstractMethodError e) { 42*795d594fSAndroid Build Coastguard Worker System.out.println("Expected AME Thrown on Main"); 43*795d594fSAndroid Build Coastguard Worker } 44*795d594fSAndroid Build Coastguard Worker long iface_throws_id = GetMethodId(false, Iface.class, "test_throws", "()V"); 45*795d594fSAndroid Build Coastguard Worker long main_throws_id = GetMethodId(false, Main.class, "test_throws", "()V"); 46*795d594fSAndroid Build Coastguard Worker try { 47*795d594fSAndroid Build Coastguard Worker long id = GetMethodId(false, Impl.class, "test_throws", "()V"); 48*795d594fSAndroid Build Coastguard Worker } catch (NoSuchMethodError e) { 49*795d594fSAndroid Build Coastguard Worker System.out.println("Expected NoSuchMethodError on Main"); 50*795d594fSAndroid Build Coastguard Worker } 51*795d594fSAndroid Build Coastguard Worker if (iface_throws_id == main_throws_id) { 52*795d594fSAndroid Build Coastguard Worker System.out.println("Abstract interface and Main have same method ids"); 53*795d594fSAndroid Build Coastguard Worker } else { 54*795d594fSAndroid Build Coastguard Worker System.out.println("Unexpected: Abstract interface and Main have different method ids"); 55*795d594fSAndroid Build Coastguard Worker } 56*795d594fSAndroid Build Coastguard Worker 57*795d594fSAndroid Build Coastguard Worker try { 58*795d594fSAndroid Build Coastguard Worker CallNonvirtual(m, Main.class, main_throws_id); 59*795d594fSAndroid Build Coastguard Worker } catch (AbstractMethodError e) { 60*795d594fSAndroid Build Coastguard Worker System.out.println("Expected AME Thrown on Main via JNI call"); 61*795d594fSAndroid Build Coastguard Worker } 62*795d594fSAndroid Build Coastguard Worker return; 63*795d594fSAndroid Build Coastguard Worker } 64*795d594fSAndroid Build Coastguard Worker GetMethodId(boolean is_static, Class k, String name, String sig)65*795d594fSAndroid Build Coastguard Worker private static native long GetMethodId(boolean is_static, Class k, String name, String sig); CallNonvirtual(Object obj, Class k, long methodid)66*795d594fSAndroid Build Coastguard Worker private static native long CallNonvirtual(Object obj, Class k, long methodid); 67*795d594fSAndroid Build Coastguard Worker } 68