pull/580/head
Mattia Iavarone 6 years ago
parent a1974ef9e3
commit ab9a114826
  1. 5
      cameraview/build.gradle
  2. 27
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegration2Test.java
  3. 16
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java

@ -240,9 +240,12 @@ task mergedCoverageReport(type: JacocoReport) {
classFilter.add('**/com/otaliastudios/cameraview/engine/CameraEngine**.*') classFilter.add('**/com/otaliastudios/cameraview/engine/CameraEngine**.*')
classFilter.add('**/com/otaliastudios/cameraview/engine/Camera1Engine**.*') classFilter.add('**/com/otaliastudios/cameraview/engine/Camera1Engine**.*')
classFilter.add('**/com/otaliastudios/cameraview/engine/Camera2Engine**.*') classFilter.add('**/com/otaliastudios/cameraview/engine/Camera2Engine**.*')
classFilter.add('**/com/otaliastudios/cameraview/engine/action/**.*')
classFilter.add('**/com/otaliastudios/cameraview/engine/lock/**.*')
classFilter.add('**/com/otaliastudios/cameraview/engine/meter/**.*')
classFilter.add('**/com/otaliastudios/cameraview/picture/**.*') classFilter.add('**/com/otaliastudios/cameraview/picture/**.*')
classFilter.add('**/com/otaliastudios/cameraview/video/**.*') classFilter.add('**/com/otaliastudios/cameraview/video/**.*')
// TODO these below could be testable ALSO outside of the integration tests // TODO these below could be easily testable ALSO outside of the integration tests
classFilter.add('**/com/otaliastudios/cameraview/video/encoding/**.*') classFilter.add('**/com/otaliastudios/cameraview/video/encoding/**.*')
} }
// We don't test OpenGL filters. // We don't test OpenGL filters.

@ -1,7 +1,12 @@
package com.otaliastudios.cameraview.engine; package com.otaliastudios.cameraview.engine;
import android.hardware.camera2.CaptureRequest;
import android.hardware.camera2.TotalCaptureResult;
import com.otaliastudios.cameraview.DoNotRunOnTravis; import com.otaliastudios.cameraview.DoNotRunOnTravis;
import com.otaliastudios.cameraview.controls.Engine; import com.otaliastudios.cameraview.controls.Engine;
import com.otaliastudios.cameraview.engine.action.ActionHolder;
import com.otaliastudios.cameraview.engine.action.BaseAction;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -11,6 +16,8 @@ import androidx.annotation.NonNull;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest; import androidx.test.filters.LargeTest;
import java.util.concurrent.CountDownLatch;
/** /**
* These tests work great on real devices, and are the only way to test actual CameraEngine * These tests work great on real devices, and are the only way to test actual CameraEngine
* implementation - we really need to open the camera device. * implementation - we really need to open the camera device.
@ -29,7 +36,23 @@ public class CameraIntegration2Test extends CameraIntegrationTest {
} }
@Override @Override
public void testFrameProcessing_afterVideo() throws Exception { protected void onOpenSync() {
super.testFrameProcessing_afterVideo(); super.onOpenSync();
// Extra wait for the first frame to be dispatched.
// This is because various classes require getLastResult to be non-null
// and that's typically the case in a real app.
Camera2Engine engine = (Camera2Engine) controller;
final CountDownLatch latch = new CountDownLatch(1);
new BaseAction() {
@Override
public void onCaptureCompleted(@NonNull ActionHolder holder,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
super.onCaptureCompleted(holder, request, result);
latch.countDown();
setState(STATE_COMPLETED);
}
}.start(engine);
try { latch.await(); } catch (InterruptedException ignore) {}
} }
} }

@ -71,7 +71,7 @@ public abstract class CameraIntegrationTest extends BaseTest {
public ActivityTestRule<TestActivity> rule = new ActivityTestRule<>(TestActivity.class); public ActivityTestRule<TestActivity> rule = new ActivityTestRule<>(TestActivity.class);
private CameraView camera; private CameraView camera;
private CameraEngine controller; protected CameraEngine controller;
private CameraListener listener; private CameraListener listener;
private Op<Throwable> uiExceptionOp; private Op<Throwable> uiExceptionOp;
@ -136,7 +136,6 @@ public abstract class CameraIntegrationTest extends BaseTest {
} }
} }
@SuppressWarnings("StatementWithEmptyBody")
private CameraOptions openSync(boolean expectSuccess) { private CameraOptions openSync(boolean expectSuccess) {
camera.open(); camera.open();
final Op<CameraOptions> open = new Op<>(true); final Op<CameraOptions> open = new Op<>(true);
@ -144,15 +143,20 @@ public abstract class CameraIntegrationTest extends BaseTest {
CameraOptions result = open.await(DELAY); CameraOptions result = open.await(DELAY);
if (expectSuccess) { if (expectSuccess) {
assertNotNull("Can open", result); assertNotNull("Can open", result);
onOpenSync();
} else {
assertNull("Should not open", result);
}
return result;
}
@SuppressWarnings("StatementWithEmptyBody")
protected void onOpenSync() {
// Extra wait for the bind and preview state, so we run tests in a fully operational // Extra wait for the bind and preview state, so we run tests in a fully operational
// state. If we didn't do so, we could have null values, for example, in getPictureSize // state. If we didn't do so, we could have null values, for example, in getPictureSize
// or in getSnapshotSize. // or in getSnapshotSize.
while (controller.getBindState() != CameraEngine.STATE_STARTED) {} while (controller.getBindState() != CameraEngine.STATE_STARTED) {}
while (controller.getPreviewState() != CameraEngine.STATE_STARTED) {} while (controller.getPreviewState() != CameraEngine.STATE_STARTED) {}
} else {
assertNull("Should not open", result);
}
return result;
} }
private void closeSync(boolean expectSuccess) { private void closeSync(boolean expectSuccess) {

Loading…
Cancel
Save