1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ex.camera2.utils;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertNotSame;
22 import static org.junit.Assert.assertTrue;
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
25 
26 import android.graphics.Rect;
27 import android.hardware.camera2.CameraCaptureSession.CaptureCallback;
28 import android.hardware.camera2.CameraDevice;
29 import android.hardware.camera2.CaptureRequest;
30 import android.hardware.camera2.CaptureRequest.Key;
31 import android.view.Surface;
32 
33 import org.junit.Test;
34 
35 public class Camera2UtilsTest extends Camera2DeviceTester {
captureListenerSplitterAllCallbacksReceived(CaptureCallback splitter, CaptureCallback... terminals)36     private void captureListenerSplitterAllCallbacksReceived(CaptureCallback splitter,
37                                                              CaptureCallback... terminals) {
38         splitter.onCaptureCompleted(null, null, null);
39         for (CaptureCallback each : terminals) {
40             verify(each).onCaptureCompleted(null, null, null);
41         }
42         splitter.onCaptureFailed(null, null, null);
43         for (CaptureCallback each : terminals) {
44             verify(each).onCaptureFailed(null, null, null);
45         }
46         splitter.onCaptureProgressed(null, null, null);
47         for (CaptureCallback each : terminals) {
48             verify(each).onCaptureProgressed(null, null, null);
49         }
50         splitter.onCaptureSequenceAborted(null, 0);
51         for (CaptureCallback each : terminals) {
52             verify(each).onCaptureSequenceAborted(null, 0);
53         }
54         splitter.onCaptureSequenceCompleted(null, 0, 0L);
55         for (CaptureCallback each : terminals) {
56             verify(each).onCaptureSequenceCompleted(null, 0, 0L);
57         }
58         splitter.onCaptureStarted(null, null, 0L, 1L);
59         for (CaptureCallback each : terminals) {
60             verify(each).onCaptureStarted(null, null, 0L, 1L);
61         }
62     }
63 
64     @Test
captureListenerSplitter()65     public void captureListenerSplitter() {
66         CaptureCallback firstBackingListener = mock(CaptureCallback.class);
67         CaptureCallback secondBackingListener = mock(CaptureCallback.class);
68         captureListenerSplitterAllCallbacksReceived(
69                 new Camera2CaptureCallbackSplitter(firstBackingListener, secondBackingListener),
70                 firstBackingListener, secondBackingListener);
71     }
72 
73     @Test
captureListenerSplitterEmpty()74     public void captureListenerSplitterEmpty() {
75         captureListenerSplitterAllCallbacksReceived(new Camera2CaptureCallbackSplitter());
76     }
77 
78     @Test
captureListenerSplitterNoNpe()79     public void captureListenerSplitterNoNpe() {
80         captureListenerSplitterAllCallbacksReceived(
81                 new Camera2CaptureCallbackSplitter((CaptureCallback) null));
82     }
83 
84     @Test
captureListenerSplitterMultipleNulls()85     public void captureListenerSplitterMultipleNulls() {
86         captureListenerSplitterAllCallbacksReceived(
87                 new Camera2CaptureCallbackSplitter(null, null, null));
88     }
89 
90     @Test
captureListenerSplitterValidAndNull()91     public void captureListenerSplitterValidAndNull() {
92         CaptureCallback onlyRealBackingListener = mock(CaptureCallback.class);
93         captureListenerSplitterAllCallbacksReceived(
94                 new Camera2CaptureCallbackSplitter(null, onlyRealBackingListener),
95                 onlyRealBackingListener);
96     }
97 
requestSettingsSetAndForget(Camera2RequestSettingsSet s, Key<T> k, T v)98     private <T> void requestSettingsSetAndForget(Camera2RequestSettingsSet s, Key<T> k, T v) {
99         s.set(k, v);
100         assertEquals(v, s.get(k));
101     }
102 
103     @Test
requestSettingsSet()104     public void requestSettingsSet() {
105         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
106         // Try a boolean
107         requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_LOCK, false);
108         requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
109         // Try an int
110         requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, 1);
111         requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, -1);
112         requestSettingsSetAndForget(setUp, CaptureRequest.CONTROL_AE_MODE, 0);
113         // Try an int[]
114         requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, new int[] {1});
115         requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA,
116                 new int[] {2, 2});
117     }
118 
119     @Test
requestSettingsSetNullValue()120     public void requestSettingsSetNullValue() {
121         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
122         requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, new int[] {1});
123         requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null);
124         requestSettingsSetAndForget(setUp, CaptureRequest.SENSOR_TEST_PATTERN_DATA,
125                 new int[] {2, 2});
126     }
127 
128     @Test
requestSettingsSetUnsetAndContains()129     public void requestSettingsSetUnsetAndContains() {
130         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
131         assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
132         setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
133         assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
134         setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
135         assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
136         setUp.unset(CaptureRequest.CONTROL_AE_LOCK);
137         assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
138 
139         setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
140         assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
141         setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
142         assertTrue(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
143         setUp.unset(CaptureRequest.CONTROL_AE_LOCK);
144         assertFalse(setUp.contains(CaptureRequest.CONTROL_AE_LOCK));
145     }
146 
147     @Test
requestSettingsSetStartsWithoutChanges()148     public void requestSettingsSetStartsWithoutChanges() {
149         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
150         assertEquals(0, setUp.getRevision());
151     }
152 
requestSettingsSetAndAssertChanged(Camera2RequestSettingsSet settings, Key<T> key, T value, boolean shouldHaveChanged)153     private <T> void requestSettingsSetAndAssertChanged(Camera2RequestSettingsSet settings,
154                                                         Key<T> key, T value,
155                                                         boolean shouldHaveChanged) {
156         long revision = settings.getRevision();
157         assertEquals(shouldHaveChanged, settings.set(key, value));
158         assertEquals(shouldHaveChanged ? revision + 1 : revision, settings.getRevision());
159     }
160 
161     @Test
requestSettingsSetChangesReportedCorrectly()162     public void requestSettingsSetChangesReportedCorrectly() {
163         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
164         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
165         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, false);
166         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true, true);
167     }
168 
169     @Test
requestSettingsSetDetectsNoopChanges()170     public void requestSettingsSetDetectsNoopChanges() {
171         Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
172         int[] one = {1}, two = {2};
173 
174         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, one, true);
175         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, one, false);
176 
177         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null, true);
178         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, null, false);
179 
180         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, two, true);
181         requestSettingsSetAndAssertChanged(s, CaptureRequest.SENSOR_TEST_PATTERN_DATA, two, false);
182     }
183 
requestSettingsUnsetAndAssertChanged(Camera2RequestSettingsSet settings, Key<T> key, boolean shouldHaveChanged)184     private <T> void requestSettingsUnsetAndAssertChanged(Camera2RequestSettingsSet settings,
185                                                           Key<T> key, boolean shouldHaveChanged) {
186         long revision = settings.getRevision();
187         assertEquals(shouldHaveChanged, settings.unset(key));
188         assertEquals(shouldHaveChanged ? revision + 1 : revision, settings.getRevision());
189     }
190 
191     @Test
requestSettingsSetUnsetMakesChangesAndDetectsNoops()192     public void requestSettingsSetUnsetMakesChangesAndDetectsNoops() {
193         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
194         requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false);
195 
196         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
197         requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
198 
199         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
200         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, false);
201         requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
202         requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false);
203 
204         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, false, true);
205         requestSettingsSetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true, true);
206         requestSettingsUnsetAndAssertChanged(setUp, CaptureRequest.CONTROL_AE_LOCK, true);
207     }
208 
209     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToCopyConstructor()210     public void requestSettingsSetNullArgToCopyConstructor() {
211         Camera2RequestSettingsSet flop = new Camera2RequestSettingsSet(null);
212     }
213 
214     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToSetKey()215     public void requestSettingsSetNullArgToSetKey() {
216         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
217         setUp.set(null, null);
218     }
219 
220     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToUnset()221     public void requestSettingsSetNullArgToUnset() {
222         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
223         setUp.unset(null);
224     }
225 
226     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToContains()227     public void requestSettingsSetNullArgToContains() {
228         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
229         setUp.contains(null);
230     }
231 
232     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToGet()233     public void requestSettingsSetNullArgToGet() {
234         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
235         setUp.get(null);
236     }
237 
238     @Test
requestSettingsSetMatchesPrimitives()239     public void requestSettingsSetMatchesPrimitives() {
240         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
241         assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
242         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
243         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));
244 
245         setUp.set(CaptureRequest.CONTROL_AE_LOCK, null);
246         assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
247         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
248         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));
249 
250         setUp.set(CaptureRequest.CONTROL_AE_LOCK, false);
251         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
252         assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
253         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));
254 
255         setUp.set(CaptureRequest.CONTROL_AE_LOCK, true);
256         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, null));
257         assertFalse(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, false));
258         assertTrue(setUp.matches(CaptureRequest.CONTROL_AE_LOCK, true));
259     }
260 
261     @Test
requestSettingsSetMatchesReferences()262     public void requestSettingsSetMatchesReferences() {
263         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
264         assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
265         assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));
266 
267         setUp.set(CaptureRequest.SCALER_CROP_REGION, null);
268         assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
269         assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));
270 
271         setUp.set(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0));
272         assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, null));
273         assertTrue(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 0, 0)));
274         assertFalse(setUp.matches(CaptureRequest.SCALER_CROP_REGION, new Rect(0, 0, 1, 1)));
275     }
276 
277     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToCreateRequest0()278     public void requestSettingsSetNullArgToCreateRequest0() throws Exception {
279         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
280         setUp.createRequest(null, CameraDevice.TEMPLATE_PREVIEW);
281     }
282 
283     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToCreateRequest2()284     public void requestSettingsSetNullArgToCreateRequest2() throws Exception {
285         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
286         setUp.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW, (Surface) null);
287     }
288 
289     @Test(expected=NullPointerException.class)
requestSettingsSetNullArgToCreateRequest02()290     public void requestSettingsSetNullArgToCreateRequest02() throws Exception {
291         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
292         setUp.createRequest(null, CameraDevice.TEMPLATE_PREVIEW, (Surface) null);
293     }
294 
295     @Test
requestSettingsSetNullArgToUnion()296     public void requestSettingsSetNullArgToUnion() {
297         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
298         assertFalse(setUp.union(null));
299         assertEquals(0, setUp.getRevision());
300     }
301 
302     @Test
requestSettingsSetSelfArgToUnion()303     public void requestSettingsSetSelfArgToUnion() {
304         Camera2RequestSettingsSet setUp = new Camera2RequestSettingsSet();
305         assertFalse(setUp.union(setUp));
306         assertEquals(0, setUp.getRevision());
307     }
308 
309     @Test
requestSettingsSetCopyConstructor()310     public void requestSettingsSetCopyConstructor() {
311         Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
312         Camera2RequestSettingsSet unchanged = new Camera2RequestSettingsSet(original);
313 
314         requestSettingsSetAndForget(original, CaptureRequest.CONTROL_AE_LOCK, true);
315         Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
316         assertEquals(true, changed.get(CaptureRequest.CONTROL_AE_LOCK));
317     }
318 
319     @Test
requestSettingsSetCopyConstructorPreservesChangedStatus()320     public void requestSettingsSetCopyConstructorPreservesChangedStatus() {
321         Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
322         Camera2RequestSettingsSet unchanged = new Camera2RequestSettingsSet(original);
323         assertEquals(original.getRevision(), unchanged.getRevision());
324 
325         requestSettingsSetAndAssertChanged(original, CaptureRequest.CONTROL_AE_LOCK, true, true);
326         Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
327         assertEquals(original.getRevision(), changed.getRevision());
328         assertNotSame(original.getRevision(), unchanged.getRevision());
329     }
330 
331     @Test
requestSettingsSetCopyConstructorPerformsDeepCopy()332     public void requestSettingsSetCopyConstructorPerformsDeepCopy() {
333         Camera2RequestSettingsSet original = new Camera2RequestSettingsSet();
334         requestSettingsSetAndForget(original, CaptureRequest.CONTROL_AE_LOCK, true);
335 
336         Camera2RequestSettingsSet changed = new Camera2RequestSettingsSet(original);
337         requestSettingsSetAndForget(changed, CaptureRequest.CONTROL_AE_LOCK, false);
338         assertEquals(true, original.get(CaptureRequest.CONTROL_AE_LOCK));
339     }
340 
341     @Test
requestSettingsSetNullMeansDefault()342     public void requestSettingsSetNullMeansDefault() throws Exception {
343         Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
344         CaptureRequest r1 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
345         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
346                 r1.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
347 
348         requestSettingsSetAndForget(s, CaptureRequest.CONTROL_CAPTURE_INTENT,
349                 CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
350         CaptureRequest r2 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
351         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
352                 r2.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
353 
354         requestSettingsSetAndForget(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null);
355         CaptureRequest r3 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
356         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
357                 r3.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
358 
359         s.unset(CaptureRequest.CONTROL_CAPTURE_INTENT);
360         CaptureRequest r4 = s.createRequest(mCamera, CameraDevice.TEMPLATE_PREVIEW);
361         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
362                 r4.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
363     }
364 
365     @Test
requestSettingsSetNullPreservedByUnions()366     public void requestSettingsSetNullPreservedByUnions() {
367         Camera2RequestSettingsSet master = new Camera2RequestSettingsSet();
368         requestSettingsSetAndForget(master, CaptureRequest.CONTROL_CAPTURE_INTENT,
369                 CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW);
370 
371         Camera2RequestSettingsSet slave = new Camera2RequestSettingsSet();
372         master.union(slave);
373         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW,
374                 master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
375 
376         requestSettingsSetAndForget(slave, CaptureRequest.CONTROL_CAPTURE_INTENT, null);
377         master.union(slave);
378         assertEquals(null, master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
379 
380         requestSettingsSetAndForget(slave, CaptureRequest.CONTROL_CAPTURE_INTENT,
381                 CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE);
382         master.union(slave);
383         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
384                 master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
385 
386         slave.unset(CaptureRequest.CONTROL_CAPTURE_INTENT);
387         master.union(slave);
388         assertEquals((Object) CaptureRequest.CONTROL_CAPTURE_INTENT_STILL_CAPTURE,
389                 master.get(CaptureRequest.CONTROL_CAPTURE_INTENT));
390     }
391 
392     @Test
requestSettingsSetNullChangesRecorded()393     public void requestSettingsSetNullChangesRecorded() throws Exception {
394         Camera2RequestSettingsSet s = new Camera2RequestSettingsSet();
395         requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, true);
396         requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT,
397                 CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW, true);
398         requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, true);
399         requestSettingsSetAndAssertChanged(s, CaptureRequest.CONTROL_CAPTURE_INTENT, null, false);
400     }
401 
402     @Test
requestSettingsSetUnionChangesRecorded()403     public void requestSettingsSetUnionChangesRecorded() {
404         Camera2RequestSettingsSet[] sets = { new Camera2RequestSettingsSet(),
405                                              new Camera2RequestSettingsSet() };
406         sets[0].union(sets[1]);
407         assertEquals(1, sets[0].getRevision());
408         assertEquals(0, sets[1].getRevision());
409     }
410 
requestSettingsSetsCheckPairOfProperties(Camera2RequestSettingsSet firstSet, Camera2RequestSettingsSet secondSet, Key<T> firstKey, Key<T> secondKey, T expectedFirstSetFirstValue, T expectedFirstSetSecondValue, T expectedSecondSetFirstValue, T expectedSecondSetSecondValue)411     private <T> void requestSettingsSetsCheckPairOfProperties(Camera2RequestSettingsSet firstSet,
412                                                               Camera2RequestSettingsSet secondSet,
413                                                               Key<T> firstKey,
414                                                               Key<T> secondKey,
415                                                               T expectedFirstSetFirstValue,
416                                                               T expectedFirstSetSecondValue,
417                                                               T expectedSecondSetFirstValue,
418                                                               T expectedSecondSetSecondValue) {
419         assertEquals(expectedFirstSetFirstValue, firstSet.get(firstKey));
420         assertEquals(expectedFirstSetSecondValue, firstSet.get(secondKey));
421         assertEquals(expectedSecondSetFirstValue, secondSet.get(firstKey));
422         assertEquals(expectedSecondSetSecondValue, secondSet.get(secondKey));
423     }
424 
425     @Test
requestSettingsSetUnionChangesReflected()426     public void requestSettingsSetUnionChangesReflected() {
427         Camera2RequestSettingsSet[] sets = { new Camera2RequestSettingsSet(),
428                                              new Camera2RequestSettingsSet() };
429 
430         sets[0].set(CaptureRequest.CONTROL_AE_LOCK, true);
431         sets[1].set(CaptureRequest.CONTROL_AWB_LOCK, true);
432         sets[0].union(sets[1]);
433         sets[1].set(CaptureRequest.CONTROL_AE_LOCK, false);
434         requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
435                 CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
436                 true, true, false, true);
437 
438         sets[0].union(sets[1]);
439         requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
440                 CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
441                 false, true, false, true);
442 
443         sets[1].set(CaptureRequest.CONTROL_AE_LOCK, false);
444         sets[1].set(CaptureRequest.CONTROL_AWB_LOCK, false);
445         sets[0].union(sets[1]);
446         requestSettingsSetsCheckPairOfProperties(sets[0], sets[1],
447                 CaptureRequest.CONTROL_AE_LOCK, CaptureRequest.CONTROL_AWB_LOCK,
448                 false, false, false, false);
449     }
450 }
451