pull/696/head
Mattia Iavarone 6 years ago
parent 0a2f554fbf
commit e3a7f89216
  1. 14
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/BaseTest.java
  2. 32
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java
  3. 3
      cameraview/src/main/java/com/otaliastudios/cameraview/video/FullVideoRecorder.java

@ -10,6 +10,7 @@ import android.os.PowerManager;
import androidx.annotation.NonNull;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.GrantPermissionRule;
import com.otaliastudios.cameraview.tools.Op;
@ -89,19 +90,6 @@ public class BaseTest {
InstrumentationRegistry.getInstrumentation().waitForIdleSync();
}
protected static void grantAllPermissions() {
grantPermission("android.permission.CAMERA");
grantPermission("android.permission.RECORD_AUDIO");
grantPermission("android.permission.WRITE_EXTERNAL_STORAGE");
}
@SuppressWarnings("WeakerAccess")
protected static void grantPermission(@NonNull String permission) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return;
String command = "pm grant " + getContext().getPackageName() + " " + permission;
InstrumentationRegistry.getInstrumentation().getUiAutomation().executeShellCommand(command);
}
@NonNull
protected static Stubber doCountDown(@NonNull final CountDownLatch latch) {
return doAnswer(new Answer<Object>() {

@ -39,6 +39,7 @@ import com.otaliastudios.cameraview.tools.RetryRule;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.rule.ActivityTestRule;
import androidx.test.rule.GrantPermissionRule;
import org.junit.After;
import org.junit.Before;
@ -78,16 +79,18 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Rule
public RetryRule retryRule = new RetryRule(3);
@Rule
public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
"android.permission.CAMERA",
"android.permission.RECORD_AUDIO",
"android.permission.WRITE_EXTERNAL_STORAGE"
);
protected CameraView camera;
protected E controller;
private CameraListener listener;
private Op<Throwable> error;
@BeforeClass
public static void grant() {
grantAllPermissions();
}
@NonNull
protected abstract Engine getEngine();
@ -559,11 +562,14 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test
@Retry(emulatorOnly = true)
public void testSetPreviewFrameRate() {
openSync(true);
CameraOptions options = openSync(true);
camera.setPreviewFrameRate(30);
Op<Void> op = new Op<>(controller.mPreviewFrameRateTask);
op.await(300);
assertEquals(camera.getPreviewFrameRate(), 30, 0);
assertEquals(camera.getPreviewFrameRate(),
Math.min(options.getPreviewFrameRateMaxValue(),
Math.max(options.getPreviewFrameRateMinValue(), 30)),
0);
}
@Test
@ -809,8 +815,10 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
Integer.MAX_VALUE, Integer.MAX_VALUE);
if (bitmap != null) {
assertNotNull(bitmap);
assertEquals(bitmap.getWidth(), size.getWidth());
assertEquals(bitmap.getHeight(), size.getHeight());
String message = LOG.i("[PICTURE SIZE]", "Desired:", size, "Bitmap:",
new Size(bitmap.getWidth(), bitmap.getHeight()));
assertEquals(message, bitmap.getWidth(), size.getWidth());
assertEquals(message, bitmap.getHeight(), size.getHeight());
}
}
@ -883,9 +891,11 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
Bitmap bitmap = CameraUtils.decodeBitmap(result.getData(),
Integer.MAX_VALUE, Integer.MAX_VALUE);
if (bitmap != null) {
String message = LOG.i("[PICTURE SIZE]", "Desired:", size, "Bitmap:",
new Size(bitmap.getWidth(), bitmap.getHeight()));
assertNotNull(bitmap);
assertEquals(bitmap.getWidth(), size.getWidth());
assertEquals(bitmap.getHeight(), size.getHeight());
assertEquals(message, bitmap.getWidth(), size.getWidth());
assertEquals(message, bitmap.getHeight(), size.getHeight());
}
}

@ -237,6 +237,9 @@ public abstract class FullVideoRecorder extends VideoRecorder {
shouldStop = true;
break;
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING:
case MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:
// On rare occasions APPROACHING is not called. Make sure we listen to
// REACHED as well.
mResult.endReason = VideoResult.REASON_MAX_SIZE_REACHED;
shouldStop = true;
break;

Loading…
Cancel
Save