From 3401582e1b1defc1877c7c47c6a839611fa211c3 Mon Sep 17 00:00:00 2001 From: Michael Plass Date: Wed, 15 Feb 2017 15:40:56 -0800 Subject: [WifiVendorHal] RSSI Monitoring Test: New unit test Bug: 34903056 Change-Id: I0246a6bb21d3d4d49854ed1c8f64f0cdf48cb839 --- .../com/android/server/wifi/WifiVendorHalTest.java | 54 ++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java index 19374ca8c..ec477b263 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java @@ -54,6 +54,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.stubbing.Answer; import java.net.InetAddress; import java.util.ArrayList; @@ -82,8 +83,14 @@ public class WifiVendorHalTest { private IWifiStaIface mIWifiStaIface; @Mock private IWifiRttController mIWifiRttController; - @Mock - private IWifiStaIfaceEventCallback mIWifistaIfaceEventCallback; + private IWifiStaIfaceEventCallback mIWifiStaIfaceEventCallback; + + /** + * Identity function to supply a type to its argument, which is a lambda + */ + static Answer answerWifiStatus(Answer statusLambda) { + return (statusLambda); + } /** * Sets up for unit test @@ -127,8 +134,13 @@ public class WifiVendorHalTest { .thenReturn(mIWifiRttController); when(mIWifiChip.registerEventCallback(any(IWifiChipEventCallback.class))) .thenReturn(mWifiStatusSuccess); + mIWifiStaIfaceEventCallback = null; when(mIWifiStaIface.registerEventCallback(any(IWifiStaIfaceEventCallback.class))) - .thenReturn(mWifiStatusSuccess); + .thenAnswer(answerWifiStatus((invocation) -> { + Object[] args = invocation.getArguments(); + mIWifiStaIfaceEventCallback = (IWifiStaIfaceEventCallback) args[0]; + return (mWifiStatusSuccess); + })); // Create the vendor HAL object under test. mWifiVendorHal = new WifiVendorHal(mHalDeviceManager, mWifiStateMachineHandlerThread); @@ -525,6 +537,42 @@ public class WifiVendorHalTest { verify(mIWifiStaIface).stopSendingKeepAlivePackets(eq(slot)); } + /** + * Test the setup, invocation, and removal of a RSSI event handler + * + */ + @Test + public void testRssiMonitoring() throws Exception { + when(mIWifiStaIface.startRssiMonitoring(anyInt(), anyInt(), anyInt())) + .thenReturn(mWifiStatusSuccess); + when(mIWifiStaIface.stopRssiMonitoring(anyInt())) + .thenReturn(mWifiStatusSuccess); + + ArrayList breach = new ArrayList<>(10); + byte hi = -21; + byte med = -42; + byte lo = -84; + Byte lower = -88; + WifiNative.WifiRssiEventHandler handler; + handler = ((cur) -> { + breach.add(cur); + }); + assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); // not started + assertEquals(-1, mWifiVendorHal.stopRssiMonitoring()); // not started + assertTrue(mWifiVendorHal.startVendorHalSta()); + assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); + int theCmdId = mWifiVendorHal.sRssiMonCmdId; + breach.clear(); + mIWifiStaIfaceEventCallback.onRssiThresholdBreached(theCmdId, new byte[6], lower); + assertEquals(breach.get(0), lower); + assertEquals(0, mWifiVendorHal.stopRssiMonitoring()); + assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); + assertEquals(0, mWifiVendorHal.startRssiMonitoring(med, lo, handler)); // replacing works + assertEquals(-1, mWifiVendorHal.startRssiMonitoring(hi, lo, null)); // null handler fails + assertEquals(0, mWifiVendorHal.startRssiMonitoring(hi, lo, handler)); + assertEquals(-1, mWifiVendorHal.startRssiMonitoring(lo, hi, handler)); // empty range + } + /** * Test that getApfCapabilities is hooked up to the HAL correctly * -- cgit v1.2.3