Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | public class Main { |
| 18 | public Main() { |
| 19 | } |
| 20 | |
| 21 | int testThisWithInstanceCall() { |
| 22 | return doNativeCallRef(); |
| 23 | } |
| 24 | |
| 25 | int testThisWithStaticCall() { |
| 26 | return doStaticNativeCallRef(); |
| 27 | } |
| 28 | |
| 29 | static int testParameter(Object a) { |
| 30 | return doStaticNativeCallRef(); |
| 31 | } |
| 32 | |
| 33 | static int testObjectInScope() { |
| 34 | Object a = array[0]; |
| 35 | return doStaticNativeCallRef(); |
| 36 | } |
| 37 | |
| 38 | native int doNativeCallRef(); |
| 39 | static native int doStaticNativeCallRef(); |
| 40 | |
| 41 | static { |
| 42 | System.loadLibrary("arttest"); |
| 43 | } |
| 44 | |
| 45 | public static void main(String[] args) { |
| 46 | Main rm = new Main(); |
| 47 | if (rm.testThisWithInstanceCall() != 1) { |
| 48 | throw new Error("Expected 1"); |
| 49 | } |
| 50 | |
| 51 | if (rm.testThisWithStaticCall() != 2) { |
| 52 | throw new Error("Expected 2"); |
| 53 | } |
| 54 | |
| 55 | if (testParameter(new Object()) != 3) { |
| 56 | throw new Error("Expected 3"); |
| 57 | } |
| 58 | |
| 59 | if (testObjectInScope() != 4) { |
| 60 | throw new Error("Expected 4"); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static Object[] array = new Object[] { new Object() }; |
| 65 | } |