pull/696/head
Mattia Iavarone 6 years ago
parent bdb2f0ebe3
commit 41e2ef389e
  1. 24
      .github/workflows/build.yml
  2. 4
      cameraview/build.gradle
  3. 6
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/engine/CameraIntegrationTest.java
  4. 2
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/tools/SdkExclude.java
  5. 9
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/tools/SdkExcludeFilter.java
  6. 20
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/tools/SdkInclude.java
  7. 47
      cameraview/src/androidTest/java/com/otaliastudios/cameraview/tools/SdkIncludeFilter.java

@ -38,19 +38,33 @@ jobs:
name: Emulator Tests name: Emulator Tests
runs-on: macOS-latest runs-on: macOS-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
# TODO 29 fails due to Mockito issues, probably reproducible locally. # TODO 29 fails due to Mockito issues, probably reproducible locally.
# 22, 23, 24, 25, 26, 27, 28 work - some of them, with SdkExclude restrictions. # 22-28 work (some of them, with SdkExclude restrictions)
# EMULATOR_API: [22, 23, 24, 25, 26, 27, 28] EMULATOR_API: [22, 23, 24, 25, 26, 27, 28]
EMULATOR_API: [25] include:
EMULATOR_ARCH: [x86_64] - EMULATOR_API: 28
EMULATOR_ARCH: x86_64
- EMULATOR_API: 27
EMULATOR_ARCH: x86_64
- EMULATOR_API: 26
EMULATOR_ARCH: x86_64
- EMULATOR_API: 25
EMULATOR_ARCH: x86
- EMULATOR_API: 24
EMULATOR_ARCH: x86
- EMULATOR_API: 23
EMULATOR_ARCH: x86
- EMULATOR_API: 22
EMULATOR_ARCH: x86
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions/setup-java@v1 - uses: actions/setup-java@v1
with: with:
java-version: 1.8 java-version: 1.8
- name: Execute emulator tests - name: Execute emulator tests
uses: reactivecircus/android-emulator-runner@v2 uses: reactivecircus/android-emulator-runner@v2.0.0
with: with:
api-level: ${{ matrix.EMULATOR_API }} api-level: ${{ matrix.EMULATOR_API }}
arch: ${{ matrix.EMULATOR_ARCH }} arch: ${{ matrix.EMULATOR_ARCH }}

@ -17,7 +17,9 @@ android {
versionCode 1 versionCode 1
versionName project.version versionName project.version
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArgument "filter", "com.otaliastudios.cameraview.tools.SdkExcludeFilter" testInstrumentationRunnerArgument "filter", "" +
"com.otaliastudios.cameraview.tools.SdkExcludeFilter," +
"com.otaliastudios.cameraview.tools.SdkIncludeFilter"
} }
buildTypes { buildTypes {

@ -36,6 +36,7 @@ import com.otaliastudios.cameraview.overlay.Overlay;
import com.otaliastudios.cameraview.size.Size; import com.otaliastudios.cameraview.size.Size;
import com.otaliastudios.cameraview.tools.Retry; import com.otaliastudios.cameraview.tools.Retry;
import com.otaliastudios.cameraview.tools.RetryRule; import com.otaliastudios.cameraview.tools.RetryRule;
import com.otaliastudios.cameraview.tools.SdkExclude;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -613,6 +614,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test @Test
@Retry(emulatorOnly = true) @Retry(emulatorOnly = true)
@SdkExclude(maxSdkVersion = 25, emulatorOnly = true)
public void testStartEndVideo() { public void testStartEndVideo() {
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
openSync(true); openSync(true);
@ -631,6 +633,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test @Test
@Retry(emulatorOnly = true) @Retry(emulatorOnly = true)
@SdkExclude(maxSdkVersion = 25, emulatorOnly = true)
public void testStartEndVideo_withManualStop() { public void testStartEndVideo_withManualStop() {
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
openSync(true); openSync(true);
@ -679,6 +682,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test @Test
@Retry(emulatorOnly = true) @Retry(emulatorOnly = true)
@SdkExclude(maxSdkVersion = 25, emulatorOnly = true)
public void testEndVideo_withMaxSize() { public void testEndVideo_withMaxSize() {
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
camera.setVideoSize(SizeSelectors.maxArea(480 * 360)); camera.setVideoSize(SizeSelectors.maxArea(480 * 360));
@ -710,6 +714,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test @Test
@Retry(emulatorOnly = true) @Retry(emulatorOnly = true)
@SdkExclude(maxSdkVersion = 25, emulatorOnly = true)
public void testEndVideo_withMaxDuration() { public void testEndVideo_withMaxDuration() {
camera.setMode(Mode.VIDEO); camera.setMode(Mode.VIDEO);
camera.setVideoMaxDuration(4000); camera.setVideoMaxDuration(4000);
@ -1006,6 +1011,7 @@ public abstract class CameraIntegrationTest<E extends CameraEngine> extends Base
@Test @Test
@Retry(emulatorOnly = true) @Retry(emulatorOnly = true)
@SdkExclude(maxSdkVersion = 25, emulatorOnly = true)
public void testFrameProcessing_afterVideo() throws Exception { public void testFrameProcessing_afterVideo() throws Exception {
FrameProcessor processor = mock(FrameProcessor.class); FrameProcessor processor = mock(FrameProcessor.class);
camera.addFrameProcessor(processor); camera.addFrameProcessor(processor);

@ -15,4 +15,6 @@ public @interface SdkExclude {
int minSdkVersion() default 1; int minSdkVersion() default 1;
/** The maximum API level to drop (inclusive) */ /** The maximum API level to drop (inclusive) */
int maxSdkVersion() default Integer.MAX_VALUE; int maxSdkVersion() default Integer.MAX_VALUE;
/** Whether this filter only applies to emulators */
boolean emulatorOnly() default false;
} }

@ -15,10 +15,11 @@ import org.junit.runner.Description;
public class SdkExcludeFilter extends ParentFilter { public class SdkExcludeFilter extends ParentFilter {
protected boolean evaluateTest(Description description) { protected boolean evaluateTest(Description description) {
final SdkExclude sdkSuppress = getAnnotationForTest(description); SdkExclude annotation = getAnnotationForTest(description);
if (sdkSuppress != null) { if (annotation != null) {
if (Build.VERSION.SDK_INT >= sdkSuppress.minSdkVersion() if ((!annotation.emulatorOnly() || Emulator.isEmulator())
&& Build.VERSION.SDK_INT <= sdkSuppress.maxSdkVersion()) { && Build.VERSION.SDK_INT >= annotation.minSdkVersion()
&& Build.VERSION.SDK_INT <= annotation.maxSdkVersion()) {
return false; // exclude the test return false; // exclude the test
} }
return true; // run the test return true; // run the test

@ -0,0 +1,20 @@
package com.otaliastudios.cameraview.tools;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Like {@link androidx.test.filters.SdkSuppress}, but with emulatorOnly().
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SdkInclude {
/** The minimum API level to run (inclusive) */
int minSdkVersion() default 1;
/** The maximum API level to run (inclusive) */
int maxSdkVersion() default Integer.MAX_VALUE;
/** Whether this filter only applies to emulators */
boolean emulatorOnly() default false;
}

@ -0,0 +1,47 @@
package com.otaliastudios.cameraview.tools;
import android.os.Build;
import androidx.annotation.Nullable;
import androidx.test.internal.runner.filters.ParentFilter;
import org.junit.runner.Description;
/**
* Filter for {@link SdkInclude}, based on
* {@link androidx.test.internal.runner.TestRequestBuilder}'s SdkSuppressFilter.
*/
public class SdkIncludeFilter extends ParentFilter {
protected boolean evaluateTest(Description description) {
SdkInclude annotation = getAnnotationForTest(description);
if (annotation != null) {
if ((!annotation.emulatorOnly() || Emulator.isEmulator())
&& Build.VERSION.SDK_INT >= annotation.minSdkVersion()
&& Build.VERSION.SDK_INT <= annotation.maxSdkVersion()) {
return true; // run the test
}
return false; // drop the test
}
return true; // no annotation, run the test
}
@Nullable
private SdkInclude getAnnotationForTest(Description description) {
final SdkInclude s = description.getAnnotation(SdkInclude.class);
if (s != null) {
return s;
}
final Class<?> testClass = description.getTestClass();
if (testClass != null) {
return testClass.getAnnotation(SdkInclude.class);
}
return null;
}
@Override
public String describe() {
return "Skip tests annotated with SdkInclude";
}
}
Loading…
Cancel
Save