Video and focus tests

pull/37/head
Mattia Iavarone 8 years ago
parent 86aaf5e536
commit b18e8efd66
  1. 76
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/CameraControllerIntegrationTest.java
  2. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -2,6 +2,7 @@ package com.otaliastudios.cameraview;
import android.content.Context; import android.content.Context;
import android.graphics.PointF;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.rule.ActivityTestRule; import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4; import android.support.test.runner.AndroidJUnit4;
@ -16,6 +17,7 @@ import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -71,6 +73,7 @@ public class CameraControllerIntegrationTest extends BaseTest {
waitForClose(true); waitForClose(true);
} */ } */
camera.destroy(); camera.destroy();
WorkerHandler.clearCache();
} }
private CameraOptions waitForOpen(boolean expectSuccess) { private CameraOptions waitForOpen(boolean expectSuccess) {
@ -99,6 +102,32 @@ public class CameraControllerIntegrationTest extends BaseTest {
return result; return result;
} }
private Boolean waitForVideo(boolean expectSuccess) {
final Task<Boolean> video = new Task<>();
video.listen();
doEndTask(video, true).when(listener).onVideoTaken(any(File.class));
Boolean result = video.await(2000);
if (expectSuccess) {
assertNotNull("Can take video", result);
} else {
assertNull("Should not take video", result);
}
return result;
}
private PointF waitForFocusStart(boolean expectSuccess) {
final Task<PointF> focus = new Task<>();
focus.listen();
doEndTask(focus, 0).when(listener).onFocusStart(any(PointF.class));
PointF result = focus.await(5000);
if (expectSuccess) {
assertNotNull("Can do autofocus", result);
} else {
assertNull("Should not do autofocus", result);
}
return result;
}
//region test open/close //region test open/close
@Test @Test
@ -319,9 +348,52 @@ public class CameraControllerIntegrationTest extends BaseTest {
//endregion //endregion
// TODO: startVideo, endVideo //region test startVideo
// TODO: startAutoFocus @Test(expected = IllegalStateException.class)
public void testStartVideo_whileInPictureMode() {
camera.setSessionType(SessionType.PICTURE);
camera.start();
waitForOpen(true);
camera.startCapturingVideo(null);
}
@Test
public void testStartEndVideo() {
camera.setSessionType(SessionType.VIDEO);
camera.start();
waitForOpen(true);
camera.startCapturingVideo(null, 1000);
waitForVideo(true); // waits 2000
}
@Test
public void testEndVideo_withoutStarting() {
camera.setSessionType(SessionType.VIDEO);
camera.start();
waitForOpen(true);
camera.stopCapturingVideo();
waitForVideo(false);
}
//endregion
//region startAutoFocus
// TODO: won't test onStopAutoFocus because that is not guaranteed to be called
@Test
public void testStartAutoFocus() {
camera.start();
CameraOptions o = waitForOpen(true);
camera.startAutoFocus(1, 1);
if (o.isAutoFocusSupported()) {
verify(listener, times(1)).onFocusStart(new PointF(1, 1));
} else {
verify(listener, never()).onFocusStart(any(PointF.class));
}
}
//endregion
// TODO: capturePicture // TODO: capturePicture

@ -564,10 +564,10 @@ class Camera1 extends CameraController {
@Override @Override
boolean startVideo(@NonNull File videoFile) { boolean startVideo(@NonNull File videoFile) {
mVideoFile = videoFile;
if (mIsCapturingVideo) return false; if (mIsCapturingVideo) return false;
if (!isCameraAvailable()) return false; if (!isCameraAvailable()) return false;
if (mSessionType == SessionType.VIDEO) { if (mSessionType == SessionType.VIDEO) {
mVideoFile = videoFile;
mIsCapturingVideo = true; mIsCapturingVideo = true;
initMediaRecorder(); initMediaRecorder();
try { try {
@ -575,7 +575,6 @@ class Camera1 extends CameraController {
mMediaRecorder.start(); mMediaRecorder.start();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
Exception m = e; // FileNotFoundException: Read only file system.
LOG.e("Error while starting MediaRecorder.", e); LOG.e("Error while starting MediaRecorder.", e);
mVideoFile = null; mVideoFile = null;
mCamera.lock(); mCamera.lock();

@ -1129,7 +1129,7 @@ public class CameraView extends FrameLayout {
throw new IllegalArgumentException("Video duration can't be < 500 milliseconds"); throw new IllegalArgumentException("Video duration can't be < 500 milliseconds");
} }
startCapturingVideo(file); startCapturingVideo(file);
postDelayed(new Runnable() { mUiHandler.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
stopCapturingVideo(); stopCapturingVideo();

Loading…
Cancel
Save