diff options
| author | 2020-09-29 18:41:56 +0530 | |
|---|---|---|
| committer | 2020-11-23 09:49:52 +0530 | |
| commit | 61e6793d24d05186cfd1a87f05c44a0a3de894d1 (patch) | |
| tree | 470c5332849aac3075527e93577cecb1a99012e3 | |
| parent | 48695cb07352cb3033dc11bb828e1ca947dfc04d (diff) | |
HDMICEC: Override hashCode in HdmiDeviceInfo
Adds hashCode override and equals test for the class.
Bug: 168713324
Test: atest HdmiDeviceInfoTest
Change-Id: I77f7a4da113785573718a16895a988de7fff6b0b
| -rw-r--r-- | core/java/android/hardware/hdmi/HdmiDeviceInfo.java | 15 | ||||
| -rw-r--r-- | core/tests/hdmitests/Android.bp | 1 | ||||
| -rwxr-xr-x | core/tests/hdmitests/src/android/hardware/hdmi/HdmiDeviceInfoTest.java | 75 |
3 files changed, 91 insertions, 0 deletions
diff --git a/core/java/android/hardware/hdmi/HdmiDeviceInfo.java b/core/java/android/hardware/hdmi/HdmiDeviceInfo.java index 55b07268d201..6b2bab4f5a4f 100644 --- a/core/java/android/hardware/hdmi/HdmiDeviceInfo.java +++ b/core/java/android/hardware/hdmi/HdmiDeviceInfo.java @@ -513,4 +513,19 @@ public class HdmiDeviceInfo implements Parcelable { && mDeviceId == other.mDeviceId && mAdopterId == other.mAdopterId; } + + @Override + public int hashCode() { + return java.util.Objects.hash( + mHdmiDeviceType, + mPhysicalAddress, + mPortId, + mLogicalAddress, + mDeviceType, + mVendorId, + mDevicePowerStatus, + mDisplayName, + mDeviceId, + mAdopterId); + } } diff --git a/core/tests/hdmitests/Android.bp b/core/tests/hdmitests/Android.bp index 2194d4b030ce..4755e0ea5259 100644 --- a/core/tests/hdmitests/Android.bp +++ b/core/tests/hdmitests/Android.bp @@ -19,6 +19,7 @@ android_test { static_libs: [ "androidx.test.rules", "frameworks-base-testutils", + "guava-android-testlib", "truth-prebuilt", ], libs: ["android.test.runner"], diff --git a/core/tests/hdmitests/src/android/hardware/hdmi/HdmiDeviceInfoTest.java b/core/tests/hdmitests/src/android/hardware/hdmi/HdmiDeviceInfoTest.java new file mode 100755 index 000000000000..4c0de629c464 --- /dev/null +++ b/core/tests/hdmitests/src/android/hardware/hdmi/HdmiDeviceInfoTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.hdmi; + +import androidx.test.filters.SmallTest; + +import com.google.common.testing.EqualsTester; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link HdmiDeviceInfo} */ +@RunWith(JUnit4.class) +@SmallTest +public class HdmiDeviceInfoTest { + + @Test + public void testEquals() { + int logicalAddr = 0x00; + int phyAddr = 0x1000; + int portId = 1; + int deviceType = 0; + int vendorId = 0x123456; + String displayName = "test device"; + int powerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY; + int deviceId = 3; + int adopterId = 2; + + new EqualsTester() + .addEqualityGroup(new HdmiDeviceInfo()) + .addEqualityGroup( + new HdmiDeviceInfo(phyAddr, portId), new HdmiDeviceInfo(phyAddr, portId)) + .addEqualityGroup( + new HdmiDeviceInfo(phyAddr, portId, adopterId, deviceId), + new HdmiDeviceInfo(phyAddr, portId, adopterId, deviceId)) + .addEqualityGroup( + new HdmiDeviceInfo( + logicalAddr, phyAddr, portId, deviceType, vendorId, displayName), + new HdmiDeviceInfo( + logicalAddr, phyAddr, portId, deviceType, vendorId, displayName)) + .addEqualityGroup( + new HdmiDeviceInfo( + logicalAddr, + phyAddr, + portId, + deviceType, + vendorId, + displayName, + powerStatus), + new HdmiDeviceInfo( + logicalAddr, + phyAddr, + portId, + deviceType, + vendorId, + displayName, + powerStatus)) + .testEquals(); + } +} |