• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
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 package com.badlogic.gdx.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.tests.utils.GdxTest;
21 
22 /** Test that unchecked exceptions thrown from a runnable get posted and terminate the app. */
23 public class RunnablePostTest extends GdxTest {
24 
25 	private static final String TAG = "RunnablePostTest";
26 	static boolean expectIt = false;
27 
28 	static private Thread.UncaughtExceptionHandler exHandler = new Thread.UncaughtExceptionHandler() {
29 		@Override
30 		public void uncaughtException (Thread t, Throwable e) {
31 			if (expectIt) {
32 				Gdx.app.log(TAG, "PASSED: " + e.getMessage());
33 			} else {
34 				Gdx.app.log(TAG, "FAILED!  Unexpected exception received.");
35 				e.printStackTrace(System.err);
36 			}
37 		}
38 	};
39 
create()40 	public void create () {
41 		Thread.setDefaultUncaughtExceptionHandler(exHandler);
42 	}
43 
44 	@Override
render()45 	public void render () {
46 		if (Gdx.input.justTouched()) {
47 			expectIt = true;
48 			Gdx.app.postRunnable(new Runnable() {
49 				@Override
50 				public void run () {
51 					throw new RuntimeException("This is a test of the uncaught exception handler.");
52 				}
53 			});
54 		}
55 	}
56 }
57