|
|
@ -8,10 +8,12 @@ import android.os.Build; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.BaseTest; |
|
|
|
import com.otaliastudios.cameraview.BaseTest; |
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.CameraException; |
|
|
|
import com.otaliastudios.cameraview.CameraListener; |
|
|
|
import com.otaliastudios.cameraview.CameraListener; |
|
|
|
import com.otaliastudios.cameraview.CameraOptions; |
|
|
|
import com.otaliastudios.cameraview.CameraOptions; |
|
|
|
import com.otaliastudios.cameraview.CameraUtils; |
|
|
|
import com.otaliastudios.cameraview.CameraUtils; |
|
|
|
import com.otaliastudios.cameraview.CameraView; |
|
|
|
import com.otaliastudios.cameraview.CameraView; |
|
|
|
|
|
|
|
import com.otaliastudios.cameraview.DoNotRunOnTravis; |
|
|
|
import com.otaliastudios.cameraview.PictureResult; |
|
|
|
import com.otaliastudios.cameraview.PictureResult; |
|
|
|
import com.otaliastudios.cameraview.TestActivity; |
|
|
|
import com.otaliastudios.cameraview.TestActivity; |
|
|
|
import com.otaliastudios.cameraview.VideoResult; |
|
|
|
import com.otaliastudios.cameraview.VideoResult; |
|
|
@ -41,6 +43,7 @@ import org.junit.Ignore; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
import org.junit.runner.RunWith; |
|
|
|
|
|
|
|
import org.mockito.ArgumentMatcher; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
|
import java.util.concurrent.CountDownLatch; |
|
|
@ -51,14 +54,16 @@ import static org.junit.Assert.assertFalse; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertNotNull; |
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
import static org.junit.Assert.assertNull; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
|
|
|
import static org.mockito.ArgumentMatchers.argThat; |
|
|
|
import static org.mockito.Matchers.anyBoolean; |
|
|
|
import static org.mockito.Matchers.anyBoolean; |
|
|
|
import static org.mockito.Mockito.any; |
|
|
|
import static org.mockito.Mockito.any; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
import static org.mockito.Mockito.spy; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static long DELAY = 9000; |
|
|
|
|
|
|
|
|
|
|
|
@Rule |
|
|
|
@Rule |
|
|
|
public ActivityTestRule<TestActivity> rule = new ActivityTestRule<>(TestActivity.class); |
|
|
|
public ActivityTestRule<TestActivity> rule = new ActivityTestRule<>(TestActivity.class); |
|
|
|
|
|
|
|
|
|
|
@ -119,7 +124,7 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void waitForUiException() throws Throwable { |
|
|
|
private void waitForUiException() throws Throwable { |
|
|
|
Throwable throwable = uiExceptionOp.await(5000); |
|
|
|
Throwable throwable = uiExceptionOp.await(DELAY); |
|
|
|
if (throwable != null) { |
|
|
|
if (throwable != null) { |
|
|
|
throw throwable; |
|
|
|
throw throwable; |
|
|
|
} |
|
|
|
} |
|
|
@ -129,7 +134,7 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
camera.open(); |
|
|
|
camera.open(); |
|
|
|
final Op<CameraOptions> open = new Op<>(true); |
|
|
|
final Op<CameraOptions> open = new Op<>(true); |
|
|
|
doEndTask(open, 0).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
doEndTask(open, 0).when(listener).onCameraOpened(any(CameraOptions.class)); |
|
|
|
CameraOptions result = open.await(4000); |
|
|
|
CameraOptions result = open.await(DELAY); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Can open", result); |
|
|
|
assertNotNull("Can open", result); |
|
|
|
// Extra wait for the bind state.
|
|
|
|
// Extra wait for the bind state.
|
|
|
@ -144,7 +149,7 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
camera.close(); |
|
|
|
camera.close(); |
|
|
|
final Op<Boolean> close = new Op<>(true); |
|
|
|
final Op<Boolean> close = new Op<>(true); |
|
|
|
doEndTask(close, true).when(listener).onCameraClosed(); |
|
|
|
doEndTask(close, true).when(listener).onCameraClosed(); |
|
|
|
Boolean result = close.await(4000); |
|
|
|
Boolean result = close.await(DELAY); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Can close", result); |
|
|
|
assertNotNull("Can close", result); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -155,9 +160,16 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
private void waitForVideoEnd(boolean expectSuccess) { |
|
|
|
private void waitForVideoEnd(boolean expectSuccess) { |
|
|
|
final Op<Boolean> video = new Op<>(true); |
|
|
|
final Op<Boolean> video = new Op<>(true); |
|
|
|
doEndTask(video, true).when(listener).onVideoTaken(any(VideoResult.class)); |
|
|
|
doEndTask(video, true).when(listener).onVideoTaken(any(VideoResult.class)); |
|
|
|
Boolean result = video.await(12000); |
|
|
|
doEndTask(video, false).when(listener).onCameraError(argThat(new ArgumentMatcher<CameraException>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean matches(CameraException argument) { |
|
|
|
|
|
|
|
return argument.getReason() == CameraException.REASON_VIDEO_FAILED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
Boolean result = video.await(DELAY); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Should end video", result); |
|
|
|
assertNotNull("Should end video", result); |
|
|
|
|
|
|
|
assertTrue("Should end video without errors", result); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
assertNull("Should not end video", result); |
|
|
|
assertNull("Should not end video", result); |
|
|
|
} |
|
|
|
} |
|
|
@ -166,7 +178,13 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
private PictureResult waitForPicture(boolean expectSuccess) { |
|
|
|
private PictureResult waitForPicture(boolean expectSuccess) { |
|
|
|
final Op<PictureResult> pic = new Op<>(true); |
|
|
|
final Op<PictureResult> pic = new Op<>(true); |
|
|
|
doEndTask(pic, 0).when(listener).onPictureTaken(any(PictureResult.class)); |
|
|
|
doEndTask(pic, 0).when(listener).onPictureTaken(any(PictureResult.class)); |
|
|
|
PictureResult result = pic.await(5000); |
|
|
|
doEndTask(pic, null).when(listener).onCameraError(argThat(new ArgumentMatcher<CameraException>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean matches(CameraException argument) { |
|
|
|
|
|
|
|
return argument.getReason() == CameraException.REASON_PICTURE_FAILED; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
})); |
|
|
|
|
|
|
|
PictureResult result = pic.await(DELAY); |
|
|
|
if (expectSuccess) { |
|
|
|
if (expectSuccess) { |
|
|
|
assertNotNull("Can take picture", result); |
|
|
|
assertNotNull("Can take picture", result); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -179,7 +197,8 @@ public abstract class CameraIntegrationTest extends BaseTest { |
|
|
|
controller.mStartVideoOp.listen(); |
|
|
|
controller.mStartVideoOp.listen(); |
|
|
|
File file = new File(context().getFilesDir(), "video.mp4"); |
|
|
|
File file = new File(context().getFilesDir(), "video.mp4"); |
|
|
|
camera.takeVideo(file); |
|
|
|
camera.takeVideo(file); |
|
|
|
controller.mStartVideoOp.await(1000); |
|
|
|
controller.mStartVideoOp.await(DELAY); |
|
|
|
|
|
|
|
// TODO assert!
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//region test open/close
|
|
|
|
//region test open/close
|
|
|
|