pull/696/head
Mattia Iavarone 6 years ago
parent d1ef3d1ac2
commit 1cc56bfad9
  1. 22
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java

@ -92,7 +92,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
protected CameraView camera; protected CameraView camera;
protected E controller; protected E controller;
private CameraListener listener; private CameraListener listener;
private Op<Throwable> uiExceptionOp; private Op<Throwable> errorOp;
@BeforeClass @BeforeClass
public static void grant() { public static void grant() {
@ -114,7 +114,9 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@NonNull @NonNull
@Override @Override
protected CameraEngine instantiateCameraEngine(@NonNull Engine engine, @NonNull CameraEngine.Callback callback) { protected CameraEngine instantiateCameraEngine(
@NonNull Engine engine,
@NonNull CameraEngine.Callback callback) {
//noinspection unchecked //noinspection unchecked
controller = (E) super.instantiateCameraEngine(getEngine(), callback); controller = (E) super.instantiateCameraEngine(getEngine(), callback);
return controller; return controller;
@ -127,15 +129,14 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
activityRule.getActivity().inflate(camera); activityRule.getActivity().inflate(camera);
// Ensure that controller exceptions are thrown on this thread (not on the UI thread). // Ensure that controller exceptions are thrown on this thread (not on the UI thread).
// TODO this makes debugging for wrong tests very hard, as we don't get the exception errorOp = new Op<>();
// unless waitForUiException() is called.
uiExceptionOp = new Op<>();
WorkerHandler crashThread = WorkerHandler.get("CrashThread"); WorkerHandler crashThread = WorkerHandler.get("CrashThread");
crashThread.getThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { crashThread.getThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) { public void uncaughtException(@NonNull Thread t, @NonNull Throwable e) {
LOG.e("[UNCAUGHT EXCEPTION]", "Exception in exception handler:", e); LOG.e("[UNCAUGHT EXCEPTION]", "Exception in exception handler:", e);
uiExceptionOp.controller().end(e); errorOp.controller().end(e);
throw new RuntimeException(e);
} }
}); });
controller.mCrashHandler = crashThread.getHandler(); controller.mCrashHandler = crashThread.getHandler();
@ -147,6 +148,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
public void onCameraError(@NonNull CameraException exception) { public void onCameraError(@NonNull CameraException exception) {
super.onCameraError(exception); super.onCameraError(exception);
if (exception.isUnrecoverable()) { if (exception.isUnrecoverable()) {
LOG.e("[UNRECOVERABLE CAMERA EXCEPTION]", exception);
throw exception; throw exception;
} }
} }
@ -163,8 +165,8 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
LOG.w("[TEST ENDED]", "Torn down camera."); LOG.w("[TEST ENDED]", "Torn down camera.");
} }
private void waitForUiException() throws Throwable { private void waitForError() throws Throwable {
Throwable throwable = uiExceptionOp.await(DELAY); Throwable throwable = errorOp.await(DELAY);
if (throwable != null) { if (throwable != null) {
throw throwable; throw throwable;
} }
@ -584,7 +586,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
camera.setMode(Mode.PICTURE); camera.setMode(Mode.PICTURE);
openSync(true); openSync(true);
takeVideoSync(false); takeVideoSync(false);
waitForUiException(); waitForError();
} }
@Test @Test
@ -776,7 +778,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
openSync(true); openSync(true);
camera.takePicture(); camera.takePicture();
waitForUiException(); waitForError();
camera.takePicture(); camera.takePicture();
} }

Loading…
Cancel
Save