diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2017-02-09 00:03:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-02-09 00:03:03 +0000 |
commit | 15413f890a31b7ba8ac9e1410a7fc44f8f695c32 (patch) | |
tree | 1888bfe0d4ab509bba2526fce9fbf4fbc3b312b9 /tests | |
parent | 4498a1ad78d325a8a42358c875197cc1b7e4c517 (diff) | |
parent | 70603901b67c48202ecbb1818e59d487bbcceeda (diff) |
Merge "Create new class WificondControl"
Diffstat (limited to 'tests')
3 files changed, 361 insertions, 10 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java index ddf8da884..d3fa4800b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java @@ -22,10 +22,15 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.anyInt; import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.net.wifi.IApInterface; +import android.net.wifi.IClientInterface; +import android.net.wifi.IWificond; import android.test.suitebuilder.annotation.SmallTest; import org.junit.Before; @@ -439,4 +444,116 @@ public class WifiNativeTest { } // TODO(b/28005116): Add test for the success case of getDriverStateDump(). + + /** + * Verifies that setupDriverForClientMode() calls underlying WificondControl. + */ + @Test + public void testSetupDriverForClientMode() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(wificondControl.setupDriverForClientMode()).thenReturn(clientInterface); + mWifiNative.setWificondControl(wificondControl); + + IClientInterface returnedClientInterface = mWifiNative.setupDriverForClientMode(); + assertEquals(clientInterface, returnedClientInterface); + verify(wificondControl).setupDriverForClientMode(); + verify(mWifiNative).startHal(eq(true)); + } + + /** + * Verifies that setupDriverForClientMode() returns null when underlying WificondControl + * call fails. + */ + @Test + public void testSetupDriverForClientModeError() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + + when(wificondControl.setupDriverForClientMode()).thenReturn(null); + mWifiNative.setWificondControl(wificondControl); + + IClientInterface returnedClientInterface = mWifiNative.setupDriverForClientMode(); + assertEquals(null, returnedClientInterface); + verify(wificondControl).setupDriverForClientMode(); + } + + /** + * Verifies that setupDriverForSoftApMode() calls underlying WificondControl. + */ + @Test + public void testSetupDriverForSoftApMode() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + IApInterface apInterface = mock(IApInterface.class); + + when(wificondControl.setupDriverForSoftApMode()).thenReturn(apInterface); + mWifiNative.setWificondControl(wificondControl); + + IApInterface returnedApInterface = mWifiNative.setupDriverForSoftApMode(); + assertEquals(apInterface, returnedApInterface); + verify(wificondControl).setupDriverForSoftApMode(); + verify(mWifiNative).startHal(eq(false)); + } + + /** + * Verifies that setupDriverForSoftApMode() returns null when underlying WificondControl + * call fails. + */ + @Test + public void testSetupDriverForSoftApModeError() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + + when(wificondControl.setupDriverForSoftApMode()).thenReturn(null); + mWifiNative.setWificondControl(wificondControl); + + IApInterface returnedApInterface = mWifiNative.setupDriverForSoftApMode(); + assertEquals(null, returnedApInterface); + verify(wificondControl).setupDriverForSoftApMode(); + } + + /** + * Verifies that enableSupplicant() calls underlying WificondControl. + */ + @Test + public void testEnableSupplicant() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + + mWifiNative.setWificondControl(wificondControl); + + mWifiNative.enableSupplicant(); + verify(wificondControl).enableSupplicant(); + } + + /** + * Verifies that disableSupplicant() calls underlying WificondControl. + */ + @Test + public void testDisableSupplicant() { + WificondControl wificondControl = mock(WificondControl.class); + IWificond wificond = mock(IWificond.class); + + mWifiNative.setWificondControl(wificondControl); + + mWifiNative.disableSupplicant(); + verify(wificondControl).disableSupplicant(); + } + + /** + * Verifies that tearDownInterfaces() calls underlying WificondControl. + */ + @Test + public void testTearDownInterfaces() { + WificondControl wificondControl = mock(WificondControl.class); + + when(wificondControl.tearDownInterfaces()).thenReturn(true); + mWifiNative.setWificondControl(wificondControl); + + assertTrue(mWifiNative.tearDownInterfaces()); + verify(wificondControl).tearDownInterfaces(); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 9d300acbf..78ff58ffe 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -362,7 +362,11 @@ public class WifiStateMachineTest { any(WifiConfiguration.class))) .thenReturn(mSoftApManager); + when(mWifiNative.setupDriverForClientMode()).thenReturn(mClientInterface); + when(mWifiNative.setupDriverForSoftApMode()).thenReturn(mApInterface); when(mWifiNative.getInterfaceName()).thenReturn("mockWlan"); + when(mWifiNative.enableSupplicant()).thenReturn(true); + when(mWifiNative.disableSupplicant()).thenReturn(true); when(mWifiSupplicantControl.getFrameworkNetworkId(anyInt())).thenReturn(0); @@ -390,12 +394,8 @@ public class WifiStateMachineTest { new UserInfo(UserHandle.USER_SYSTEM, "owner", 0), new UserInfo(11, "managed profile", 0))); - when(mWificond.createApInterface()).thenReturn(mApInterface); when(mApInterface.asBinder()).thenReturn(mApInterfaceBinder); - when(mWificond.createClientInterface()).thenReturn(mClientInterface); when(mClientInterface.asBinder()).thenReturn(mClientInterfaceBinder); - when(mClientInterface.enableSupplicant()).thenReturn(true); - when(mClientInterface.disableSupplicant()).thenReturn(true); mWsm = new WifiStateMachine(context, factory, mLooper.getLooper(), mUserManager, mWifiInjector, mBackupManagerProxy, mCountryCode, mWifiNative); @@ -453,12 +453,10 @@ public class WifiStateMachineTest { @Test public void loadComponentsInStaMode() throws Exception { - when(mWifiNative.startHal(anyBoolean())).thenReturn(true); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); assertEquals("SupplicantStartingState", getCurrentState().getName()); - verify(mWifiNative).startHal(eq(true)); when(mWifiNative.setDeviceName(anyString())).thenReturn(true); when(mWifiNative.setManufacturer(anyString())).thenReturn(true); @@ -478,19 +476,17 @@ public class WifiStateMachineTest { @Test public void loadComponentsInApMode() throws Exception { - when(mWifiNative.startHal(anyBoolean())).thenReturn(true); mWsm.setHostApRunning(new WifiConfiguration(), true); mLooper.dispatchAll(); assertEquals("SoftApState", getCurrentState().getName()); - verify(mWifiNative).startHal(eq(false)); verify(mSoftApManager).start(); } @Test public void shouldRequireSupplicantStartupToLeaveInitialState() throws Exception { - when(mClientInterface.enableSupplicant()).thenReturn(false); + when(mWifiNative.enableSupplicant()).thenReturn(false); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); assertEquals("InitialState", getCurrentState().getName()); @@ -523,7 +519,7 @@ public class WifiStateMachineTest { @Test public void loadComponentsFailure() throws Exception { when(mWifiNative.startHal(anyBoolean())).thenReturn(false); - when(mClientInterface.enableSupplicant()).thenReturn(false); + when(mWifiNative.enableSupplicant()).thenReturn(false); mWsm.setSupplicantRunning(true); mLooper.dispatchAll(); diff --git a/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java new file mode 100644 index 000000000..4fa006f4d --- /dev/null +++ b/tests/wifitests/src/com/android/server/wifi/WificondControlTest.java @@ -0,0 +1,238 @@ +/* + * Copyright (C) 2017 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 com.android.server.wifi; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import android.net.wifi.IApInterface; +import android.net.wifi.IClientInterface; +import android.net.wifi.IWificond; +import android.test.suitebuilder.annotation.SmallTest; + +import org.junit.Before; +import org.junit.Test; + +/** + * Unit tests for {@link com.android.server.wifi.WificondControl}. + */ +@SmallTest +public class WificondControlTest { + private WifiInjector mWifiInjector; + private WificondControl mWificondControl; + + @Before + public void setUp() throws Exception { + mWifiInjector = mock(WifiInjector.class); + mWificondControl = new WificondControl(mWifiInjector); + } + + /** + * Verifies that setupDriverForClientMode() calls Wificond. + */ + @Test + public void testSetupDriverForClientMode() throws Exception { + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(clientInterface); + + IClientInterface returnedClientInterface = mWificondControl.setupDriverForClientMode(); + assertEquals(clientInterface, returnedClientInterface); + verify(wificond).createClientInterface(); + } + + /** + * Verifies that setupDriverForClientMode() returns null when wificond is not started. + */ + @Test + public void testSetupDriverForClientModeErrorWhenWificondIsNotStarted() throws Exception { + when(mWifiInjector.makeWificond()).thenReturn(null); + + IClientInterface returnedClientInterface = mWificondControl.setupDriverForClientMode(); + assertEquals(null, returnedClientInterface); + } + + /** + * Verifies that setupDriverForClientMode() returns null when wificond failed to setup client + * interface. + */ + @Test + public void testSetupDriverForClientModeErrorWhenWificondFailedToSetupInterface() + throws Exception { + IWificond wificond = mock(IWificond.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(null); + + IClientInterface returnedClientInterface = mWificondControl.setupDriverForClientMode(); + assertEquals(null, returnedClientInterface); + } + + /** + * Verifies that setupDriverForSoftApMode() calls wificond. + */ + @Test + public void testSetupDriverForSoftApMode() throws Exception { + IWificond wificond = mock(IWificond.class); + IApInterface apInterface = mock(IApInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createApInterface()).thenReturn(apInterface); + + IApInterface returnedApInterface = mWificondControl.setupDriverForSoftApMode(); + assertEquals(apInterface, returnedApInterface); + verify(wificond).createApInterface(); + } + + /** + * Verifies that setupDriverForSoftAp() returns null when wificond is not started. + */ + @Test + public void testSetupDriverForSoftApModeErrorWhenWificondIsNotStarted() throws Exception { + when(mWifiInjector.makeWificond()).thenReturn(null); + + IApInterface returnedApInterface = mWificondControl.setupDriverForSoftApMode(); + + assertEquals(null, returnedApInterface); + } + + /** + * Verifies that setupDriverForSoftApMode() returns null when wificond failed to setup + * AP interface. + */ + @Test + public void testSetupDriverForSoftApModeErrorWhenWificondFailedToSetupInterface() + throws Exception { + IWificond wificond = mock(IWificond.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createApInterface()).thenReturn(null); + + IApInterface returnedApInterface = mWificondControl.setupDriverForSoftApMode(); + assertEquals(null, returnedApInterface); + } + + /** + * Verifies that enableSupplicant() calls wificond. + */ + @Test + public void testEnableSupplicant() throws Exception { + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(clientInterface); + when(clientInterface.enableSupplicant()).thenReturn(true); + + mWificondControl.setupDriverForClientMode(); + assertTrue(mWificondControl.enableSupplicant()); + verify(clientInterface).enableSupplicant(); + } + + /** + * Verifies that enableSupplicant() returns false when there is no configured + * client interface. + */ + @Test + public void testEnableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception { + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(clientInterface); + + // Configure client interface. + IClientInterface returnedClientInterface = mWificondControl.setupDriverForClientMode(); + assertEquals(clientInterface, returnedClientInterface); + + // Tear down interfaces. + assertTrue(mWificondControl.tearDownInterfaces()); + + // Enabling supplicant should fail. + assertFalse(mWificondControl.enableSupplicant()); + } + + /** + * Verifies that disableSupplicant() calls wificond. + */ + @Test + public void testDisableSupplicant() throws Exception { + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(clientInterface); + when(clientInterface.disableSupplicant()).thenReturn(true); + + mWificondControl.setupDriverForClientMode(); + assertTrue(mWificondControl.disableSupplicant()); + verify(clientInterface).disableSupplicant(); + } + + /** + * Verifies that disableSupplicant() returns false when there is no configured + * client interface. + */ + @Test + public void testDisableSupplicantErrorWhenNoClientInterfaceConfigured() throws Exception { + IWificond wificond = mock(IWificond.class); + IClientInterface clientInterface = mock(IClientInterface.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + when(wificond.createClientInterface()).thenReturn(clientInterface); + + // Configure client interface. + IClientInterface returnedClientInterface = mWificondControl.setupDriverForClientMode(); + assertEquals(clientInterface, returnedClientInterface); + + // Tear down interfaces. + assertTrue(mWificondControl.tearDownInterfaces()); + + // Disabling supplicant should fail. + assertFalse(mWificondControl.disableSupplicant()); + } + + /** + * Verifies that tearDownInterfaces() calls wificond. + */ + @Test + public void testTearDownInterfaces() throws Exception { + IWificond wificond = mock(IWificond.class); + + when(mWifiInjector.makeWificond()).thenReturn(wificond); + + assertTrue(mWificondControl.tearDownInterfaces()); + verify(wificond).tearDownInterfaces(); + } + + /** + * Verifies that tearDownInterfaces() returns false when wificond is not started. + */ + @Test + public void testTearDownInterfacesErrorWhenWificondIsNotStarterd() throws Exception { + when(mWifiInjector.makeWificond()).thenReturn(null); + + assertFalse(mWificondControl.tearDownInterfaces()); + } + +} |