Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 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 | |
Jeff Hao | 201803f | 2013-11-20 18:11:39 -0800 | [diff] [blame] | 17 | import java.lang.reflect.Method; |
| 18 | |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 19 | class JniTest { |
| 20 | public static void main(String[] args) { |
| 21 | System.loadLibrary("arttest"); |
| 22 | testFindClassOnAttachedNativeThread(); |
Jeff Hao | 62509b6 | 2013-12-10 17:44:56 -0800 | [diff] [blame] | 23 | testFindFieldOnAttachedNativeThread(); |
Brian Carlstrom | 67fe2b4 | 2013-10-15 18:51:42 -0700 | [diff] [blame] | 24 | testCallStaticVoidMethodOnSubClass(); |
Jeff Hao | 201803f | 2013-11-20 18:11:39 -0800 | [diff] [blame] | 25 | testGetMirandaMethod(); |
Narayan Kamath | ef809d0 | 2013-12-19 17:52:47 +0000 | [diff] [blame^] | 26 | testZeroLengthByteBuffers(); |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | private static native void testFindClassOnAttachedNativeThread(); |
Brian Carlstrom | 67fe2b4 | 2013-10-15 18:51:42 -0700 | [diff] [blame] | 30 | |
Jeff Hao | 62509b6 | 2013-12-10 17:44:56 -0800 | [diff] [blame] | 31 | private static boolean testFindFieldOnAttachedNativeThreadField; |
| 32 | |
| 33 | private static void testFindFieldOnAttachedNativeThread() { |
| 34 | testFindFieldOnAttachedNativeThreadNative(); |
| 35 | if (!testFindFieldOnAttachedNativeThreadField) { |
| 36 | throw new AssertionError(); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | private static native void testFindFieldOnAttachedNativeThreadNative(); |
| 41 | |
Brian Carlstrom | 67fe2b4 | 2013-10-15 18:51:42 -0700 | [diff] [blame] | 42 | private static void testCallStaticVoidMethodOnSubClass() { |
| 43 | testCallStaticVoidMethodOnSubClassNative(); |
| 44 | if (!testCallStaticVoidMethodOnSubClass_SuperClass.executed) { |
| 45 | throw new AssertionError(); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | private static native void testCallStaticVoidMethodOnSubClassNative(); |
| 50 | |
| 51 | private static class testCallStaticVoidMethodOnSubClass_SuperClass { |
| 52 | private static boolean executed = false; |
| 53 | private static void execute() { |
| 54 | executed = true; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | private static class testCallStaticVoidMethodOnSubClass_SubClass |
| 59 | extends testCallStaticVoidMethodOnSubClass_SuperClass { |
| 60 | } |
Jeff Hao | 201803f | 2013-11-20 18:11:39 -0800 | [diff] [blame] | 61 | |
| 62 | private static native Method testGetMirandaMethodNative(); |
| 63 | |
| 64 | private static void testGetMirandaMethod() { |
| 65 | Method m = testGetMirandaMethodNative(); |
| 66 | if (m.getDeclaringClass() != testGetMirandaMethod_MirandaInterface.class) { |
| 67 | throw new AssertionError(); |
| 68 | } |
| 69 | } |
| 70 | |
Narayan Kamath | ef809d0 | 2013-12-19 17:52:47 +0000 | [diff] [blame^] | 71 | private static native void testZeroLengthByteBuffers(); |
| 72 | |
Jeff Hao | 201803f | 2013-11-20 18:11:39 -0800 | [diff] [blame] | 73 | private static abstract class testGetMirandaMethod_MirandaAbstract implements testGetMirandaMethod_MirandaInterface { |
| 74 | public boolean inAbstract() { |
| 75 | return true; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | private static interface testGetMirandaMethod_MirandaInterface { |
| 80 | public boolean inInterface(); |
| 81 | } |
Brian Carlstrom | ce88853 | 2013-10-10 00:32:58 -0700 | [diff] [blame] | 82 | } |