1 /* 2 * Copyright (C) 2013 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 class JniTest { main(String[] args)20 public static void main(String[] args) { 21 System.loadLibrary("arttest"); 22 testFindClassOnAttachedNativeThread(); 23 testFindFieldOnAttachedNativeThread(); 24 testCallStaticVoidMethodOnSubClass(); 25 testGetMirandaMethod(); 26 } 27 testFindClassOnAttachedNativeThread()28 private static native void testFindClassOnAttachedNativeThread(); 29 30 private static boolean testFindFieldOnAttachedNativeThreadField; 31 testFindFieldOnAttachedNativeThread()32 private static void testFindFieldOnAttachedNativeThread() { 33 testFindFieldOnAttachedNativeThreadNative(); 34 if (!testFindFieldOnAttachedNativeThreadField) { 35 throw new AssertionError(); 36 } 37 } 38 testFindFieldOnAttachedNativeThreadNative()39 private static native void testFindFieldOnAttachedNativeThreadNative(); 40 testCallStaticVoidMethodOnSubClass()41 private static void testCallStaticVoidMethodOnSubClass() { 42 testCallStaticVoidMethodOnSubClassNative(); 43 if (!testCallStaticVoidMethodOnSubClass_SuperClass.executed) { 44 throw new AssertionError(); 45 } 46 } 47 testCallStaticVoidMethodOnSubClassNative()48 private static native void testCallStaticVoidMethodOnSubClassNative(); 49 50 private static class testCallStaticVoidMethodOnSubClass_SuperClass { 51 private static boolean executed = false; execute()52 private static void execute() { 53 executed = true; 54 } 55 } 56 57 private static class testCallStaticVoidMethodOnSubClass_SubClass 58 extends testCallStaticVoidMethodOnSubClass_SuperClass { 59 } 60 testGetMirandaMethodNative()61 private static native Method testGetMirandaMethodNative(); 62 testGetMirandaMethod()63 private static void testGetMirandaMethod() { 64 Method m = testGetMirandaMethodNative(); 65 if (m.getDeclaringClass() != testGetMirandaMethod_MirandaInterface.class) { 66 throw new AssertionError(); 67 } 68 } 69 70 private static abstract class testGetMirandaMethod_MirandaAbstract implements testGetMirandaMethod_MirandaInterface { inAbstract()71 public boolean inAbstract() { 72 return true; 73 } 74 } 75 76 private static interface testGetMirandaMethod_MirandaInterface { inInterface()77 public boolean inInterface(); 78 } 79 } 80