Dave Allison | f4b80bc | 2014-05-14 15:41:25 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | class SignalTest { |
| 18 | private static native void initSignalTest(); |
| 19 | private static native void terminateSignalTest(); |
| 20 | private static native int testSignal(); |
| 21 | |
| 22 | private static void stackOverflow() { |
| 23 | stackOverflow(); |
| 24 | } |
| 25 | |
| 26 | public static void main(String[] args) { |
| 27 | System.loadLibrary("arttest"); |
| 28 | |
| 29 | System.out.println("init signal test"); |
| 30 | initSignalTest(); |
| 31 | try { |
| 32 | Object o = null; |
| 33 | int hash = o.hashCode(); |
| 34 | |
| 35 | // Should never get here. |
| 36 | System.out.println("hash: " + hash); |
| 37 | throw new AssertionError(); |
| 38 | } catch (NullPointerException e) { |
| 39 | System.out.println("Caught NullPointerException"); |
| 40 | } |
| 41 | try { |
| 42 | stackOverflow(); |
| 43 | |
| 44 | // Should never get here. |
| 45 | throw new AssertionError(); |
| 46 | } catch (StackOverflowError e) { |
| 47 | System.out.println("Caught StackOverflowError"); |
| 48 | } |
| 49 | |
| 50 | // Test that a signal in native code works. This will return |
| 51 | // the value 1234 if the signal is caught. |
| 52 | int x = testSignal(); |
| 53 | if (x != 1234) { |
| 54 | throw new AssertionError(); |
| 55 | } |
| 56 | |
| 57 | terminateSignalTest(); |
| 58 | System.out.println("Signal test OK"); |
| 59 | } |
| 60 | } |