|
|
@ -61,15 +61,23 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
@After |
|
|
|
@After |
|
|
|
public void tearDown() throws Exception { |
|
|
|
public void tearDown() throws Exception { |
|
|
|
camera.stopCapturingVideo(); |
|
|
|
camera.stopCapturingVideo(); |
|
|
|
camera.stop(); |
|
|
|
/* int state = controller.getState(); |
|
|
|
Thread.sleep(800); // Just to be sure it's released before next test.
|
|
|
|
if (state >= CameraController.STATE_STARTING) { |
|
|
|
|
|
|
|
// Enqueue a stop and wait.
|
|
|
|
|
|
|
|
camera.stop(); |
|
|
|
|
|
|
|
waitForClose(true); |
|
|
|
|
|
|
|
} else if (state == CameraController.STATE_STOPPING) { |
|
|
|
|
|
|
|
// Wait for incoming stop.
|
|
|
|
|
|
|
|
waitForClose(true); |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
camera.destroy(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CameraOptions waitForOpen(boolean expectSuccess) { |
|
|
|
private CameraOptions waitForOpen(boolean expectSuccess) { |
|
|
|
final Task<CameraOptions> open = new Task<>(); |
|
|
|
final Task<CameraOptions> open = new Task<>(); |
|
|
|
open.listen(); |
|
|
|
open.listen(); |
|
|
|
doEndTask(open, 0).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
doEndTask(open, 0).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
CameraOptions result = open.await(1000); |
|
|
|
CameraOptions result = open.await(2000); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Can open", result); |
|
|
|
assertNotNull("Can open", result); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -82,7 +90,7 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
final Task<Boolean> close = new Task<>(); |
|
|
|
final Task<Boolean> close = new Task<>(); |
|
|
|
close.listen(); |
|
|
|
close.listen(); |
|
|
|
doEndTask(close, true).when(listener).onCameraClosed(); |
|
|
|
doEndTask(close, true).when(listener).onCameraClosed(); |
|
|
|
Boolean result = close.await(1000); |
|
|
|
Boolean result = close.await(2000); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Can close", result); |
|
|
|
assertNotNull("Can close", result); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -95,21 +103,23 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testOpenClose() throws Exception { |
|
|
|
public void testOpenClose() throws Exception { |
|
|
|
assertFalse(controller.isCameraAvailable()); |
|
|
|
// Starting and stopping are hard to get since they happen on another thread.
|
|
|
|
|
|
|
|
assertEquals(controller.getState(), CameraController.STATE_STOPPED); |
|
|
|
|
|
|
|
|
|
|
|
camera.start(); |
|
|
|
camera.start(); |
|
|
|
waitForOpen(true); |
|
|
|
waitForOpen(true); |
|
|
|
assertTrue(controller.isCameraAvailable()); |
|
|
|
assertEquals(controller.getState(), CameraController.STATE_STARTED); |
|
|
|
|
|
|
|
|
|
|
|
camera.stop(); |
|
|
|
camera.stop(); |
|
|
|
waitForClose(true); |
|
|
|
waitForClose(true); |
|
|
|
assertFalse(controller.isCameraAvailable()); |
|
|
|
assertEquals(controller.getState(), CameraController.STATE_STOPPED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testOpenTwice() { |
|
|
|
public void testOpenTwice() { |
|
|
|
camera.start(); |
|
|
|
camera.start(); |
|
|
|
waitForOpen(true); |
|
|
|
waitForOpen(true); |
|
|
|
|
|
|
|
camera.start(); |
|
|
|
waitForOpen(false); |
|
|
|
waitForOpen(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -119,7 +129,10 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
waitForClose(false); |
|
|
|
waitForClose(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
// @Test
|
|
|
|
|
|
|
|
// This works great on the device but crashes on the emulator.
|
|
|
|
|
|
|
|
// There must be something wrong with the emulated camera...
|
|
|
|
|
|
|
|
// Like stopPreview() and release() are not really sync calls?
|
|
|
|
public void testConcurrentCalls() throws Exception { |
|
|
|
public void testConcurrentCalls() throws Exception { |
|
|
|
final CountDownLatch latch = new CountDownLatch(4); |
|
|
|
final CountDownLatch latch = new CountDownLatch(4); |
|
|
|
doCountDown(latch).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
doCountDown(latch).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
@ -130,8 +143,8 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
camera.start(); |
|
|
|
camera.start(); |
|
|
|
camera.stop(); |
|
|
|
camera.stop(); |
|
|
|
|
|
|
|
|
|
|
|
boolean did = latch.await(4, TimeUnit.SECONDS); |
|
|
|
boolean did = latch.await(10, TimeUnit.SECONDS); |
|
|
|
assertTrue("Handles concurrent calls to start & stop", did); |
|
|
|
assertTrue("Handles concurrent calls to start & stop, " + latch.getCount(), did); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -151,20 +164,20 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSetFacing() throws Exception { |
|
|
|
public void testSetFacing() throws Exception { |
|
|
|
camera.setFacing(Facing.BACK); |
|
|
|
|
|
|
|
camera.start(); |
|
|
|
camera.start(); |
|
|
|
waitForOpen(true); |
|
|
|
CameraOptions o = waitForOpen(true); |
|
|
|
|
|
|
|
int size = o.getSupportedFacing().size(); |
|
|
|
// set facing should call stop and start again.
|
|
|
|
if (size > 1) { |
|
|
|
final CountDownLatch latch = new CountDownLatch(2); |
|
|
|
// set facing should call stop and start again.
|
|
|
|
doCountDown(latch).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
final CountDownLatch latch = new CountDownLatch(2); |
|
|
|
doCountDown(latch).when(listener).onCameraClosed(); |
|
|
|
doCountDown(latch).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
|
|
|
|
doCountDown(latch).when(listener).onCameraClosed(); |
|
|
|
camera.setFacing(Facing.FRONT); |
|
|
|
|
|
|
|
|
|
|
|
camera.toggleFacing(); |
|
|
|
boolean did = latch.await(2, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
assertTrue("Handles setFacing while active", did); |
|
|
|
boolean did = latch.await(2, TimeUnit.SECONDS); |
|
|
|
assertEquals(camera.getFacing(), Facing.FRONT); |
|
|
|
assertTrue("Handles setFacing while active", did); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
@ -222,6 +235,7 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
camera.setFlash(value); |
|
|
|
camera.setFlash(value); |
|
|
|
if (options.supports(value)) { |
|
|
|
if (options.supports(value)) { |
|
|
|
assertEquals(camera.getFlash(), value); |
|
|
|
assertEquals(camera.getFlash(), value); |
|
|
|
|
|
|
|
oldValue = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
assertEquals(camera.getFlash(), oldValue); |
|
|
|
assertEquals(camera.getFlash(), oldValue); |
|
|
|
} |
|
|
|
} |
|
|
@ -238,6 +252,7 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
camera.setWhiteBalance(value); |
|
|
|
camera.setWhiteBalance(value); |
|
|
|
if (options.supports(value)) { |
|
|
|
if (options.supports(value)) { |
|
|
|
assertEquals(camera.getWhiteBalance(), value); |
|
|
|
assertEquals(camera.getWhiteBalance(), value); |
|
|
|
|
|
|
|
oldValue = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
assertEquals(camera.getWhiteBalance(), oldValue); |
|
|
|
assertEquals(camera.getWhiteBalance(), oldValue); |
|
|
|
} |
|
|
|
} |
|
|
@ -254,6 +269,7 @@ public class CameraControllerIntegrationTest extends BaseTest { |
|
|
|
camera.setHdr(value); |
|
|
|
camera.setHdr(value); |
|
|
|
if (options.supports(value)) { |
|
|
|
if (options.supports(value)) { |
|
|
|
assertEquals(camera.getHdr(), value); |
|
|
|
assertEquals(camera.getHdr(), value); |
|
|
|
|
|
|
|
oldValue = value; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
assertEquals(camera.getHdr(), oldValue); |
|
|
|
assertEquals(camera.getHdr(), oldValue); |
|
|
|
} |
|
|
|
} |
|
|
|