diff options
author | Etan Cohen <etancohen@google.com> | 2016-12-22 00:57:47 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-12-22 00:57:48 +0000 |
commit | 3121bb5254ff46122939a52e9e0d54ac39199eff (patch) | |
tree | e0f12dfb6d8eff2051a6496080b2ff7681adf9f0 /tests | |
parent | e8d771c2638ee06a3c06b676daf6a87fa85cdcd9 (diff) | |
parent | d45abba86c33bd93863fc9d8f7c84ca28deb17b2 (diff) |
Merge "[AWARE] Use WifiInjector in WifiAware library"
Diffstat (limited to 'tests')
4 files changed, 14 insertions, 86 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java index 110c42b16..675b61cb9 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareDataPathStateManagerTest.java @@ -76,7 +76,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.Arrays; @@ -122,7 +121,8 @@ public class WifiAwareDataPathStateManagerTest { mMockLooper = new TestLooper(); mMockLooperHandler = new Handler(mMockLooper.getLooper()); - mDut = installNewAwareStateManager(); + mDut = new WifiAwareStateManager(); + mDut.setNative(mMockNative); mDut.start(mMockContext, mMockLooper.getLooper()); mDut.startLate(); @@ -150,7 +150,6 @@ public class WifiAwareDataPathStateManagerTest { anyString(), anyInt(), any(NetworkInfo.class), any(NetworkCapabilities.class), any(LinkProperties.class))).thenReturn(true); - installMockWifiAwareNative(mMockNative); installDataPathStateManagerMocks(); } @@ -624,27 +623,6 @@ public class WifiAwareDataPathStateManagerTest { verifyNoMoreInteractions(mMockNative, mMockCm); } - - private static WifiAwareStateManager installNewAwareStateManager() - throws Exception { - Constructor<WifiAwareStateManager> ctr = - WifiAwareStateManager.class.getDeclaredConstructor(); - ctr.setAccessible(true); - WifiAwareStateManager awareStateManager = ctr.newInstance(); - - Field field = WifiAwareStateManager.class.getDeclaredField("sAwareStateManagerSingleton"); - field.setAccessible(true); - field.set(null, awareStateManager); - - return WifiAwareStateManager.getInstance(); - } - - private static void installMockWifiAwareNative(WifiAwareNative obj) throws Exception { - Field field = WifiAwareNative.class.getDeclaredField("sWifiAwareNativeSingleton"); - field.setAccessible(true); - field.set(null, obj); - } - private void installDataPathStateManagerMocks() throws Exception { Field field = WifiAwareStateManager.class.getDeclaredField("mDataPathMgr"); field.setAccessible(true); diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareHalTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareHalTest.java index 61aa27441..d54229c35 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareHalTest.java @@ -44,18 +44,15 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.lang.reflect.Field; - /** * Unit test harness for WifiAwareNative + JNI code interfacing to the HAL. */ @SmallTest public class WifiAwareHalTest { - private WifiAwareNative mDut = WifiAwareNative.getInstance(); + private WifiAwareNative mDut; private ArgumentCaptor<String> mArgs = ArgumentCaptor.forClass(String.class); - @Mock - private WifiAwareHalMock mAwareHalMock; + @Mock private WifiAwareHalMock mAwareHalMock; @Mock private WifiAwareStateManager mAwareStateManager; @Rule @@ -65,13 +62,13 @@ public class WifiAwareHalTest { public void setup() throws Exception { MockitoAnnotations.initMocks(this); - resetWifiAwareNative(); + mDut = new WifiAwareNative(false); + mDut.setStateManager(mAwareStateManager); HalMockUtils.initHalMockLibrary(); WifiAwareHalMock.initAwareHalMockLibrary(mDut); WifiAwareNative.initAwareHandlersNative(WifiNative.class, WifiNative.sWlan0Index); HalMockUtils.setHalMockObject(mAwareHalMock); - installMockAwareStateManager(mAwareStateManager); } @Test @@ -1218,17 +1215,4 @@ public class WifiAwareHalTest { equalTo(ndpIdBase + i)); } } - - private static void installMockAwareStateManager(WifiAwareStateManager awareStateManager) - throws Exception { - Field field = WifiAwareStateManager.class.getDeclaredField("sAwareStateManagerSingleton"); - field.setAccessible(true); - field.set(null, awareStateManager); - } - - private static void resetWifiAwareNative() throws Exception { - Field field = WifiAwareNative.class.getDeclaredField("sWifiAwareNativeSingleton"); - field.setAccessible(true); - field.set(null, null); - } } diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java index 1876cd2e3..a65c760a6 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareServiceImplTest.java @@ -37,6 +37,7 @@ import android.net.wifi.aware.IWifiAwareEventCallback; import android.net.wifi.aware.PublishConfig; import android.net.wifi.aware.SubscribeConfig; import android.net.wifi.aware.WifiAwareCharacteristics; +import android.os.HandlerThread; import android.os.IBinder; import android.os.Looper; import android.test.suitebuilder.annotation.SmallTest; @@ -65,6 +66,8 @@ public class WifiAwareServiceImplTest { @Mock private Context mContextMock; @Mock + private HandlerThread mHandlerThreadMock; + @Mock private PackageManager mPackageManagerMock; @Mock private WifiAwareStateManager mAwareStateManagerMock; @@ -75,6 +78,8 @@ public class WifiAwareServiceImplTest { @Mock private IWifiAwareDiscoverySessionCallback mSessionCallbackMock; + private HandlerThread mHandlerThread; + /** * Using instead of spy to avoid native crash failures - possibly due to * spy's copying of state. @@ -109,19 +114,9 @@ public class WifiAwareServiceImplTest { .thenReturn(true); when(mAwareStateManagerMock.getCharacteristics()).thenReturn(getCharacteristics()); - installMockAwareStateManager(); - mDut = new WifiAwareServiceImplSpy(mContextMock); mDut.fakeUid = mDefaultUid; - } - - /** - * Validate start() function: passes a valid looper. - */ - @Test - public void testStart() { - mDut.start(); - + mDut.start(mHandlerThreadMock, mAwareStateManagerMock); verify(mAwareStateManagerMock).start(eq(mContextMock), any(Looper.class)); } @@ -654,13 +649,6 @@ public class WifiAwareServiceImplTest { return clientId.getValue(); } - private void installMockAwareStateManager() - throws Exception { - Field field = WifiAwareStateManager.class.getDeclaredField("sAwareStateManagerSingleton"); - field.setAccessible(true); - field.set(null, mAwareStateManagerMock); - } - private static WifiAwareCharacteristics getCharacteristics() { WifiAwareNative.Capabilities cap = new WifiAwareNative.Capabilities(); cap.maxConcurrentAwareClusters = 1; diff --git a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java index e80784576..b4396002d 100644 --- a/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/aware/WifiAwareStateManagerTest.java @@ -69,7 +69,6 @@ import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Map; @@ -120,7 +119,8 @@ public class WifiAwareStateManagerTest { mMockLooper = new TestLooper(); - mDut = installNewAwareStateManager(); + mDut = new WifiAwareStateManager(); + mDut.setNative(mMockNative); mDut.start(mMockContext, mMockLooper.getLooper()); installMocksInStateManager(mDut, mMockAwareRttStateManager, mMockAwareDataPathStatemanager); @@ -135,8 +135,6 @@ public class WifiAwareStateManagerTest { when(mMockNative.stopPublish(anyShort(), anyInt())).thenReturn(true); when(mMockNative.stopSubscribe(anyShort(), anyInt())).thenReturn(true); when(mMockNative.getCapabilities(anyShort())).thenReturn(true); - - installMockWifiAwareNative(mMockNative); } /** @@ -2506,20 +2504,6 @@ public class WifiAwareStateManagerTest { * Utilities */ - private static WifiAwareStateManager installNewAwareStateManager() - throws Exception { - Constructor<WifiAwareStateManager> ctr = - WifiAwareStateManager.class.getDeclaredConstructor(); - ctr.setAccessible(true); - WifiAwareStateManager awareStateManager = ctr.newInstance(); - - Field field = WifiAwareStateManager.class.getDeclaredField("sAwareStateManagerSingleton"); - field.setAccessible(true); - field.set(null, awareStateManager); - - return WifiAwareStateManager.getInstance(); - } - private static void installMocksInStateManager(WifiAwareStateManager awareStateManager, WifiAwareRttStateManager mockRtt, WifiAwareDataPathStateManager mockDpMgr) throws Exception { @@ -2532,12 +2516,6 @@ public class WifiAwareStateManagerTest { field.set(awareStateManager, mockDpMgr); } - private static void installMockWifiAwareNative(WifiAwareNative obj) throws Exception { - Field field = WifiAwareNative.class.getDeclaredField("sWifiAwareNativeSingleton"); - field.setAccessible(true); - field.set(null, obj); - } - private static WifiAwareClientState getInternalClientState(WifiAwareStateManager dut, int clientId) throws Exception { Field field = WifiAwareStateManager.class.getDeclaredField("mClients"); |