• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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 android.hardware.camera2.cts;
18 
19 import android.hardware.camera2.CameraCharacteristics;
20 import android.hardware.camera2.CaptureRequest;
21 import android.hardware.camera2.CaptureResult;
22 
23 import androidx.test.runner.AndroidJUnit4;
24 
25 import org.junit.Assert;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 
29 /**
30  * Test CaptureRequest/Result/CameraCharacteristics.Key objects.
31  */
32 @RunWith(AndroidJUnit4.class)
33 @SuppressWarnings("EqualsIncompatibleType")
34 public class SimpleObjectsTest {
35 
36     @Test
CameraKeysTest()37     public void CameraKeysTest() throws Exception {
38         String keyName = "android.testing.Key";
39         String keyName2 = "android.testing.Key2";
40 
41         CaptureRequest.Key<Integer> testRequestKey =
42                 new CaptureRequest.Key<>(keyName, Integer.class);
43         Assert.assertEquals("Request key name not correct",
44                 testRequestKey.getName(), keyName);
45 
46         CaptureResult.Key<Integer> testResultKey =
47                 new CaptureResult.Key<>(keyName, Integer.class);
48         Assert.assertEquals("Result key name not correct",
49                 testResultKey.getName(), keyName);
50 
51         CameraCharacteristics.Key<Integer> testCharacteristicsKey =
52                 new CameraCharacteristics.Key<>(keyName, Integer.class);
53         Assert.assertEquals("Characteristics key name not correct",
54                 testCharacteristicsKey.getName(), keyName);
55 
56         CaptureRequest.Key<Integer> testRequestKey2 =
57                 new CaptureRequest.Key<>(keyName, Integer.class);
58         Assert.assertEquals("Two request keys with same name/type should be equal",
59                 testRequestKey, testRequestKey2);
60         CaptureRequest.Key<Byte> testRequestKey3 =
61                 new CaptureRequest.Key<>(keyName, Byte.class);
62         Assert.assertTrue("Two request keys with different types should not be equal",
63                 !testRequestKey.equals(testRequestKey3));
64         CaptureRequest.Key<Integer> testRequestKey4 =
65                 new CaptureRequest.Key<>(keyName2, Integer.class);
66         Assert.assertTrue("Two request keys with different names should not be equal",
67                 !testRequestKey.equals(testRequestKey4));
68         CaptureRequest.Key<Byte> testRequestKey5 =
69                 new CaptureRequest.Key<>(keyName2, Byte.class);
70         Assert.assertTrue("Two request keys with different types and names should not be equal",
71                 !testRequestKey.equals(testRequestKey5));
72 
73         CaptureResult.Key<Integer> testResultKey2 =
74                 new CaptureResult.Key<>(keyName, Integer.class);
75         Assert.assertEquals("Two result keys with same name/type should be equal",
76                 testResultKey, testResultKey2);
77         CaptureResult.Key<Byte> testResultKey3 =
78                 new CaptureResult.Key<>(keyName, Byte.class);
79         Assert.assertTrue("Two result keys with different types should not be equal",
80                 !testResultKey.equals(testResultKey3));
81         CaptureResult.Key<Integer> testResultKey4 =
82                 new CaptureResult.Key<>(keyName2, Integer.class);
83         Assert.assertTrue("Two result keys with different names should not be equal",
84                 !testResultKey.equals(testResultKey4));
85         CaptureResult.Key<Byte> testResultKey5 =
86                 new CaptureResult.Key<>(keyName2, Byte.class);
87         Assert.assertTrue("Two result keys with different types and names should not be equal",
88                 !testResultKey.equals(testResultKey5));
89 
90         CameraCharacteristics.Key<Integer> testCharacteristicsKey2 =
91                 new CameraCharacteristics.Key<>(keyName, Integer.class);
92         Assert.assertEquals("Two characteristics keys with same name/type should be equal",
93                 testCharacteristicsKey, testCharacteristicsKey2);
94         CameraCharacteristics.Key<Byte> testCharacteristicsKey3 =
95                 new CameraCharacteristics.Key<>(keyName, Byte.class);
96         Assert.assertTrue("Two characteristics keys with different types should not be equal",
97                 !testCharacteristicsKey.equals(testCharacteristicsKey3));
98         CameraCharacteristics.Key<Integer> testCharacteristicsKey4 =
99                 new CameraCharacteristics.Key<>(keyName2, Integer.class);
100         Assert.assertTrue("Two characteristics keys with different names should not be equal",
101                 !testCharacteristicsKey.equals(testCharacteristicsKey4));
102         CameraCharacteristics.Key<Byte> testCharacteristicsKey5 =
103                 new CameraCharacteristics.Key<>(keyName2, Byte.class);
104         Assert.assertTrue(
105                 "Two characteristics keys with different types and names should not be equal",
106                 !testCharacteristicsKey.equals(testCharacteristicsKey5));
107 
108     }
109 
110 }
111