Fix integration tests

pull/697/head
Mattia Iavarone 6 years ago
parent 7502939561
commit aa0cb04f32
  1. 1
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/Camera1IntegrationTest.java
  2. 13
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java
  3. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/action/BaseAction.java
  4. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/orchestrator/CameraOrchestrator.java
  5. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/engine/orchestrator/CameraStateOrchestrator.java

@ -2,6 +2,7 @@ package com.otaliastudios.cameraview.engine;
import com.otaliastudios.cameraview.controls.Engine;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.annotation.NonNull;

@ -810,18 +810,19 @@ public abstract class CameraIntegrationTest extends BaseTest {
public void testPictureFormat_DNG() {
openSync(true);
if (camera.getCameraOptions().supports(PictureFormat.DNG)) {
Op<Boolean> op = new Op<>();
doEndOp(op, true).when(listener).onCameraOpened(any(CameraOptions.class));
camera.setPictureFormat(PictureFormat.DNG);
assertNotNull(op.await(2000));
camera.takePicture();
PictureResult result = waitForPictureResult(true);
// assert that result.getData() is a DNG file:
// We can use the first 4 bytes assuming they are the same as a TIFF file
// https://en.wikipedia.org/wiki/List_of_file_signatures
// https://en.wikipedia.org/wiki/List_of_file_signatures 73, 73, 42, 0
byte[] b = result.getData();
boolean isII = b[0] == 'I' && b[1] == 'I' && b[2] == '*' && b[3] == '.';
boolean isMM = b[0] == 'M' && b[1] == 'M' && b[2] == '.' && b[3] == '*';
if (!isII && !isMM) {
throw new RuntimeException("Not a DNG file.");
}
boolean isII = b[0] == 'I' && b[1] == 'I' && b[2] == '*' && b[3] == 0;
boolean isMM = b[0] == 'M' && b[1] == 'M' && b[2] == 0 && b[3] == '*';
assertTrue(isII || isMM);
}
}

@ -39,6 +39,7 @@ public abstract class BaseAction implements Action {
@Override
public final void start(@NonNull ActionHolder holder) {
this.holder = holder;
holder.addAction(this);
if (holder.getLastResult(this) != null) {
onStart(holder);
@ -64,6 +65,8 @@ public abstract class BaseAction implements Action {
*/
@CallSuper
protected void onStart(@NonNull ActionHolder holder) {
// Repeating holder assignment here (already in start()) because we NEED it in start()
// but some special actions will not call start() at all for their children.
this.holder = holder;
// Overrideable
}

@ -14,6 +14,7 @@ import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
/**
* Schedules {@link com.otaliastudios.cameraview.engine.CameraEngine} actions,
@ -104,6 +105,8 @@ public class CameraOrchestrator {
mCallback.handleJobException(name, e);
}
source.trySetException(e);
} else if (task.isCanceled()) {
source.trySetException(new CancellationException());
} else {
source.trySetResult(null);
}

@ -61,7 +61,7 @@ public class CameraStateOrchestrator extends CameraOrchestrator {
if (getCurrentState() != fromState) {
LOG.w(changeName.toUpperCase(), "- State mismatch, aborting. current:",
getCurrentState(), "from:", fromState, "to:", toState);
return Tasks.forResult(null);
return Tasks.forCanceled();
} else {
Executor executor = mCallback.getJobWorker(changeName).getExecutor();
return stateChange.call().continueWithTask(executor,

Loading…
Cancel
Save