FileDocCategorySizeDatePackage
Camera2UtilsTest.javaAPI DocAndroid 5.1 API21616Thu Mar 12 22:22:48 GMT 2015com.android.ex.camera2.utils

Camera2UtilsTest

public class Camera2UtilsTest extends Camera2DeviceTester

Fields Summary
Constructors Summary
Methods Summary
public voidcaptureListenerSplitter()

        CaptureCallback firstBackingListener = mock(CaptureCallback.class);
        CaptureCallback secondBackingListener = mock(CaptureCallback.class);
        captureListenerSplitterAllCallbacksReceived(
                new Camera2CaptureCallbackSplitter(firstBackingListener, secondBackingListener),
                firstBackingListener, secondBackingListener);
    
private voidcaptureListenerSplitterAllCallbacksReceived(android.hardware.camera2.CameraCaptureSession.CaptureCallback splitter, android.hardware.camera2.CameraCaptureSession.CaptureCallback terminals)

        splitter.onCaptureCompleted(null, null, null);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureCompleted(null, null, null);
        }
        splitter.onCaptureFailed(null, null, null);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureFailed(null, null, null);
        }
        splitter.onCaptureProgressed(null, null, null);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureProgressed(null, null, null);
        }
        splitter.onCaptureSequenceAborted(null, 0);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureSequenceAborted(null, 0);
        }
        splitter.onCaptureSequenceCompleted(null, 0, 0L);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureSequenceCompleted(null, 0, 0L);
        }
        splitter.onCaptureStarted(null, null, 0L, 1L);
        for (CaptureCallback each : terminals) {
            verify(each).onCaptureStarted(null, null, 0L, 1L);
        }
    
public voidcaptureListenerSplitterEmpty()

        captureListenerSplitterAllCallbacksReceived(new Camera2CaptureCallbackSplitter());
    
public voidcaptureListenerSplitterMultipleNulls()

        captureListenerSplitterAllCallbacksReceived(
                new Camera2CaptureCallbackSplitter(null, null, null));
    
public voidcaptureListenerSplitterNoNpe()

        captureListenerSplitterAllCallbacksReceived(
                new Camera2CaptureCallbackSplitter((CaptureCallback) null));
    
public voidcaptureListenerSplitterValidAndNull()

        CaptureCallback onlyRealBackingListener = mock(CaptureCallback.class);
        captureListenerSplitterAllCallbacksReceived(
                new Camera2CaptureCallbackSplitter(null, onlyRealBackingListener),
                onlyRealBackingListener);
    
public voidrequestSettingsSet()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        // Try a boolean
        requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_LOCK, false);
        requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
        // Try an int
        requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, 1);
        requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, -1);
        requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, 0);
        // Try an int[]
        requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, new int[] {1});
        requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA,
                new int[] {2, 2});
    
private voidrequestSettingsSetAndAssertChanged(Camera2RequestSettingsSet settings, android.hardware.camera2.CaptureRequest.Key key, T value, boolean shouldHaveChanged)

        long revision = settings.getRevision();
        assertEquals(shouldHaveChanged, settings.set(key, value));
        assertEquals(shouldHaveChanged ? revision + 1 : revision, settings.getRevision());
    
private voidrequestSettingsSetAndForget(Camera2RequestSettingsSet s, android.hardware.camera2.CaptureRequest.Key k, T v)

        s.set(k, v);
        assertEquals(v, s.get(k));
    
public voidrequestSettingsSetChangesReportedCorrectly()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, false);
        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true, true);
    
public voidrequestSettingsSetCopyConstructor()

        Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
        Camera2RequestSettingsSet unchanged = new Camera2RequestSettingsSet(original);

        requestSettingsSetAndForget(original, CaptureRequest.CONTROL_AE_LOCK, true);
        Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
        assertEquals(true, changed.get(CaptureRequest.CONTROL_AE_LOCK));
    
public voidrequestSettingsSetCopyConstructorPerformsDeepCopy()

        Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
        requestSettingsSetAndForget(original, CaptureRequest.CONTROL_AE_LOCK, true);

        Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
        requestSettingsSetAndForget(changed, CaptureRequest.CONTROL_AE_LOCK, false);
        assertEquals(true, original.get(CaptureRequest.CONTROL_AE_LOCK));
    
public voidrequestSettingsSetCopyConstructorPreservesChangedStatus()

        Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
        Camera2RequestSettingsSet unchanged = new Camera2RequestSettingsSet(original);
        assertEquals(original.getRevision(), unchanged.getRevision());

        requestSettingsSetAndAssertChanged(original, CaptureRequest.CONTROL_AE_LOCK, true, true);
        Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
        assertEquals(original.getRevision(), changed.getRevision());
        assertNotSame(original.getRevision(), unchanged.getRevision());
    
public voidrequestSettingsSetDetectsNoopChanges()

        Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
        int[] one = {1}, two = {2};

        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, one, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, one, false);

        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null, false);

        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, two, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, two, false);
    
public voidrequestSettingsSetMatchesPrimitives()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));

        setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
        assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));

        setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
        assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));

        setUp.set(CaptureRequest.CONTROL_AE_LOCK, true);
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
        assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
        assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));
    
public voidrequestSettingsSetMatchesReferences()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
        assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));

        setUp.set(CaptureRequest.SCALER_CROP_REGION, null);
        assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
        assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));

        setUp.set(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0));
        assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
        assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));
        assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 1, 1)));
    
public voidrequestSettingsSetNullArgToContains()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.contains(null);
    
public voidrequestSettingsSetNullArgToCopyConstructor()

        Camera2RequestSettingsSet flop = new Camera2RequestSettingsSet(null);
    
public voidrequestSettingsSetNullArgToCreateRequest0()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.createRequest(null, CameraDevice.TEMPLATE_PREVIEW);
    
public voidrequestSettingsSetNullArgToCreateRequest02()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.createRequest(null, CameraDevice.TEMPLATE_PREVIEW, (Surface) null);
    
public voidrequestSettingsSetNullArgToCreateRequest2()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW, (Surface) null);
    
public voidrequestSettingsSetNullArgToGet()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.get(null);
    
public voidrequestSettingsSetNullArgToSetKey()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.set(null, null);
    
public voidrequestSettingsSetNullArgToUnion()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertFalse(setUp.union(null));
        assertEquals(0, setUp.getRevision());
    
public voidrequestSettingsSetNullArgToUnset()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        setUp.unset(null);
    
public voidrequestSettingsSetNullChangesRecorded()

        Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
        requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT,
                CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, true);
        requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, false);
    
public voidrequestSettingsSetNullMeansDefault()

        Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
        CaptureRequest r1 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
                r1.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        requestSettingsSetAndForget(s, CaptureRequest.CONTROL_CAPTURE_INTENT,
                CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
        CaptureRequest r2 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
                r2.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        requestSettingsSetAndForget(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null);
        CaptureRequest r3 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
                r3.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        s.unset(CaptureRequest.CONTROL_CAPTURE_INTENT);
        CaptureRequest r4 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
                r4.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
    
public voidrequestSettingsSetNullPreservedByUnions()

        Camera2RequestSettingsSet master = new Camera2RequestSettingsSet();
        requestSettingsSetAndForget(master, CaptureRequest.CONTROL_CAPTURE_INTENT,
                CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);

        Camera2RequestSettingsSet slave = new Camera2RequestSettingsSet();
        master.union(slave);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
                master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        requestSettingsSetAndForget(slave, CaptureRequest.CONTROL_CAPTURE_INTENT, null);
        master.union(slave);
        assertEquals(null, master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        requestSettingsSetAndForget(slave, CaptureRequest.CONTROL_CAPTURE_INTENT,
                CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
        master.union(slave);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
                master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));

        slave.unset(CaptureRequest.CONTROL_CAPTURE_INTENT);
        master.union(slave);
        assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
                master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
    
public voidrequestSettingsSetNullValue()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, new int[] {1});
        requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null);
        requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA,
                new int[] {2, 2});
    
public voidrequestSettingsSetSelfArgToUnion()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertFalse(setUp.union(setUp));
        assertEquals(0, setUp.getRevision());
    
public voidrequestSettingsSetStartsWithoutChanges()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertEquals(0, setUp.getRevision());
    
public voidrequestSettingsSetUnionChangesRecorded()

        Camera2RequestSettingsSet[] sets = { new Camera2RequestSettingsSet(),
                                             new Camera2RequestSettingsSet() };
        sets[0].union(sets[1]);
        assertEquals(1, sets[0].getRevision());
        assertEquals(0, sets[1].getRevision());
    
public voidrequestSettingsSetUnionChangesReflected()

        Camera2RequestSettingsSet[] sets = { new Camera2RequestSettingsSet(),
                                             new Camera2RequestSettingsSet() };

        sets[0].set(CaptureRequest.CONTROL_AE_LOCK, true);
        sets[1].set(CaptureRequest.CONTROL_AWB_LOCK, true);
        sets[0].union(sets[1]);
        sets[1].set(CaptureRequest.CONTROL_AE_LOCK, false);
        requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
                CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
                true, true, false, true);

        sets[0].union(sets[1]);
        requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
                CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
                false, true, false, true);

        sets[1].set(CaptureRequest.CONTROL_AE_LOCK, false);
        sets[1].set(CaptureRequest.CONTROL_AWB_LOCK, false);
        sets[0].union(sets[1]);
        requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
                CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
                false, false, false, false);
    
public voidrequestSettingsSetUnsetAndContains()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
        setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
        assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
        setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
        assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
        setUp.unset(CaptureRequest.CONTROL_AE_LOCK);
        assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));

        setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
        assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
        setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
        assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
        setUp.unset(CaptureRequest.CONTROL_AE_LOCK);
        assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
    
public voidrequestSettingsSetUnsetMakesChangesAndDetectsNoops()

        Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
        requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false);

        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
        requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);

        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, false);
        requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
        requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false);

        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
        requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true, true);
        requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
    
private voidrequestSettingsSetsCheckPairOfProperties(Camera2RequestSettingsSet firstSet, Camera2RequestSettingsSet secondSet, android.hardware.camera2.CaptureRequest.Key firstKey, android.hardware.camera2.CaptureRequest.Key secondKey, T expectedFirstSetFirstValue, T expectedFirstSetSecondValue, T expectedSecondSetFirstValue, T expectedSecondSetSecondValue)

        assertEquals(expectedFirstSetFirstValue, firstSet.get(firstKey));
        assertEquals(expectedFirstSetSecondValue, firstSet.get(secondKey));
        assertEquals(expectedSecondSetFirstValue, secondSet.get(firstKey));
        assertEquals(expectedSecondSetSecondValue, secondSet.get(secondKey));
    
private voidrequestSettingsUnsetAndAssertChanged(Camera2RequestSettingsSet settings, android.hardware.camera2.CaptureRequest.Key key, boolean shouldHaveChanged)

        long revision = settings.getRevision();
        assertEquals(shouldHaveChanged, settings.unset(key));
        assertEquals(shouldHaveChanged ? revision + 1 : revision, settings.getRevision());