diff options
author | Etan Cohen <etancohen@google.com> | 2016-09-28 05:04:06 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-09-28 05:04:06 +0000 |
commit | d5a1b60f238596381bc69a2f0987aee59bdd6078 (patch) | |
tree | 5ad2cf5168dda41a1c19fa08c05fed619c5447d6 | |
parent | 81cc7a93e0f248f69e1d14487c0ea52aef789c15 (diff) | |
parent | 0c9a3591240a5d9f7ee74437bee7b0a16c8d49ff (diff) |
Merge "[NAN] Use a hidden class for peer ID opaque handle: updated unit tests"
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java | 27 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/nan/WifiNanManagerTest.java | 57 |
2 files changed, 52 insertions, 32 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java index b2a85d2a4..13e3dd41c 100644 --- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanDataPathStateManagerTest.java @@ -401,7 +401,8 @@ public class WifiNanDataPathStateManagerTest { boolean provideToken, boolean getConfirmation) throws Exception { final int clientId = 123; final int pubSubId = 11234; - final Object peerHandle = Integer.valueOf(1341234); + final WifiNanManager.OpaquePeerHandle peerHandle = new WifiNanManager.OpaquePeerHandle( + 1341234); final int ndpId = 2; final String token = "some token"; final String peerToken = "let's go!"; @@ -413,8 +414,8 @@ public class WifiNanDataPathStateManagerTest { InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback); // (0) initialize - Pair<Integer, Messenger> res = initDataPathEndPoint(clientId, pubSubId, - (Integer) peerHandle, peerDiscoveryMac, inOrder); + Pair<Integer, Messenger> res = initDataPathEndPoint(clientId, pubSubId, peerHandle, + peerDiscoveryMac, inOrder); // (1) request network NetworkRequest nr; @@ -433,7 +434,7 @@ public class WifiNanDataPathStateManagerTest { res.second.send(reqNetworkMsg); mMockLooper.dispatchAll(); inOrder.verify(mMockNative).initiateDataPath(transactionId.capture(), - eq(useDirect ? 0 : (Integer) peerHandle), + eq(useDirect ? 0 : peerHandle.peerId), eq(WifiNanNative.CHANNEL_REQUEST_TYPE_REQUESTED), eq(2437), eq(peerDiscoveryMac), eq("nan0"), eq(token.getBytes())); mDut.onInitiateDataPathResponseSuccess(transactionId.getValue(), ndpId); @@ -481,7 +482,8 @@ public class WifiNanDataPathStateManagerTest { boolean provideToken, boolean getConfirmation) throws Exception { final int clientId = 123; final int pubSubId = 11234; - final Object peerHandle = Integer.valueOf(1341234); + final WifiNanManager.OpaquePeerHandle peerHandle = new WifiNanManager.OpaquePeerHandle( + 1341234); final int ndpId = 2; final String token = "some token"; final String peerToken = "let's go!"; @@ -493,8 +495,8 @@ public class WifiNanDataPathStateManagerTest { InOrder inOrder = inOrder(mMockNative, mMockCm, mMockCallback, mMockSessionCallback); // (0) initialize - Pair<Integer, Messenger> res = initDataPathEndPoint(clientId, pubSubId, - (Integer) peerHandle, peerDiscoveryMac, inOrder); + Pair<Integer, Messenger> res = initDataPathEndPoint(clientId, pubSubId, peerHandle, + peerDiscoveryMac, inOrder); // (1) request network NetworkRequest nr; @@ -675,8 +677,9 @@ public class WifiNanDataPathStateManagerTest { return new NetworkRequest(nc, 0, 0); } - private Pair<Integer, Messenger> initDataPathEndPoint(int clientId, int pubSubId, int peerId, - byte[] peerDiscoveryMac, InOrder inOrder) throws Exception { + private Pair<Integer, Messenger> initDataPathEndPoint(int clientId, int pubSubId, + WifiNanManager.OpaquePeerHandle peerHandle, byte[] peerDiscoveryMac, InOrder inOrder) + throws Exception { final int uid = 1000; final int pid = 2000; final String callingPackage = "com.android.somePackage"; @@ -729,9 +732,11 @@ public class WifiNanDataPathStateManagerTest { mDut.onSessionConfigSuccessResponse(transactionId.getValue(), true, pubSubId); mMockLooper.dispatchAll(); inOrder.verify(mMockSessionCallback).onSessionStarted(sessionId.capture()); - mDut.onMessageReceivedNotification(pubSubId, peerId, peerDiscoveryMac, someMsg.getBytes()); + mDut.onMessageReceivedNotification(pubSubId, peerHandle.peerId, peerDiscoveryMac, + someMsg.getBytes()); mMockLooper.dispatchAll(); - inOrder.verify(mMockSessionCallback).onMessageReceived(peerId, someMsg.getBytes()); + inOrder.verify(mMockSessionCallback).onMessageReceived(peerHandle.peerId, + someMsg.getBytes()); return new Pair<>(sessionId.getValue(), messengerCaptor.getValue()); } diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanManagerTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanManagerTest.java index 628c9a5d1..0d68bd9c2 100644 --- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanManagerTest.java @@ -274,7 +274,7 @@ public class WifiNanManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final PublishConfig publishConfig = new PublishConfig.Builder().build(); - final int peerId = 873; + final WifiNanManager.OpaquePeerHandle peerHandle = new WifiNanManager.OpaquePeerHandle(873); final String string1 = "hey from here..."; final String string2 = "some other arbitrary string..."; final int messageId = 2123; @@ -290,6 +290,7 @@ public class WifiNanManagerTest { .forClass(IWifiNanDiscoverySessionCallback.class); ArgumentCaptor<WifiNanPublishDiscoverySession> publishSession = ArgumentCaptor .forClass(WifiNanPublishDiscoverySession.class); + ArgumentCaptor<Object> peerIdCaptor = ArgumentCaptor.forClass(Object.class); // (0) connect + success mDut.attach(mMockLooperHandler, configRequest, mockCallback, null); @@ -311,18 +312,24 @@ public class WifiNanManagerTest { inOrder.verify(mockSessionCallback).onPublishStarted(publishSession.capture()); // (3) ... - publishSession.getValue().sendMessage(peerId, messageId, string1.getBytes()); - sessionProxyCallback.getValue().onMatch(peerId, string1.getBytes(), string2.getBytes()); - sessionProxyCallback.getValue().onMessageReceived(peerId, string1.getBytes()); + publishSession.getValue().sendMessage(peerHandle, messageId, string1.getBytes()); + sessionProxyCallback.getValue().onMatch(peerHandle.peerId, string1.getBytes(), + string2.getBytes()); + sessionProxyCallback.getValue().onMessageReceived(peerHandle.peerId, string1.getBytes()); sessionProxyCallback.getValue().onMessageSendFail(messageId, reason); sessionProxyCallback.getValue().onMessageSendSuccess(messageId); mMockLooper.dispatchAll(); - inOrder.verify(mockNanService).sendMessage(eq(clientId), eq(sessionId), eq(peerId), - eq(string1.getBytes()), eq(messageId), eq(0)); - inOrder.verify(mockSessionCallback).onServiceDiscovered(eq(peerId), eq(string1.getBytes()), - eq(string2.getBytes())); - inOrder.verify(mockSessionCallback).onMessageReceived(eq(peerId), eq(string1.getBytes())); + inOrder.verify(mockNanService).sendMessage(eq(clientId), eq(sessionId), + eq(peerHandle.peerId), eq(string1.getBytes()), eq(messageId), eq(0)); + inOrder.verify(mockSessionCallback).onServiceDiscovered(peerIdCaptor.capture(), + eq(string1.getBytes()), eq(string2.getBytes())); + assertEquals(((WifiNanManager.OpaquePeerHandle) peerIdCaptor.getValue()).peerId, + peerHandle.peerId); + inOrder.verify(mockSessionCallback).onMessageReceived(peerIdCaptor.capture(), + eq(string1.getBytes())); + assertEquals(((WifiNanManager.OpaquePeerHandle) peerIdCaptor.getValue()).peerId, + peerHandle.peerId); inOrder.verify(mockSessionCallback).onMessageSendFailed(eq(messageId)); inOrder.verify(mockSessionCallback).onMessageSent(eq(messageId)); @@ -408,7 +415,7 @@ public class WifiNanManagerTest { final int sessionId = 123; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); final SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build(); - final int peerId = 873; + final WifiNanManager.OpaquePeerHandle peerHandle = new WifiNanManager.OpaquePeerHandle(873); final String string1 = "hey from here..."; final String string2 = "some other arbitrary string..."; final int messageId = 2123; @@ -424,6 +431,7 @@ public class WifiNanManagerTest { .forClass(IWifiNanDiscoverySessionCallback.class); ArgumentCaptor<WifiNanSubscribeDiscoverySession> subscribeSession = ArgumentCaptor .forClass(WifiNanSubscribeDiscoverySession.class); + ArgumentCaptor<Object> peerIdCaptor = ArgumentCaptor.forClass(Object.class); // (0) connect + success mDut.attach(mMockLooperHandler, configRequest, mockCallback, null); @@ -445,18 +453,24 @@ public class WifiNanManagerTest { inOrder.verify(mockSessionCallback).onSubscribeStarted(subscribeSession.capture()); // (3) ... - subscribeSession.getValue().sendMessage(peerId, messageId, string1.getBytes()); - sessionProxyCallback.getValue().onMatch(peerId, string1.getBytes(), string2.getBytes()); - sessionProxyCallback.getValue().onMessageReceived(peerId, string1.getBytes()); + subscribeSession.getValue().sendMessage(peerHandle, messageId, string1.getBytes()); + sessionProxyCallback.getValue().onMatch(peerHandle.peerId, string1.getBytes(), + string2.getBytes()); + sessionProxyCallback.getValue().onMessageReceived(peerHandle.peerId, string1.getBytes()); sessionProxyCallback.getValue().onMessageSendFail(messageId, reason); sessionProxyCallback.getValue().onMessageSendSuccess(messageId); mMockLooper.dispatchAll(); - inOrder.verify(mockNanService).sendMessage(eq(clientId), eq(sessionId), eq(peerId), - eq(string1.getBytes()), eq(messageId), eq(0)); - inOrder.verify(mockSessionCallback).onServiceDiscovered(eq(peerId), eq(string1.getBytes()), - eq(string2.getBytes())); - inOrder.verify(mockSessionCallback).onMessageReceived(eq(peerId), eq(string1.getBytes())); + inOrder.verify(mockNanService).sendMessage(eq(clientId), eq(sessionId), + eq(peerHandle.peerId), eq(string1.getBytes()), eq(messageId), eq(0)); + inOrder.verify(mockSessionCallback).onServiceDiscovered(peerIdCaptor.capture(), + eq(string1.getBytes()), eq(string2.getBytes())); + assertEquals(((WifiNanManager.OpaquePeerHandle) peerIdCaptor.getValue()).peerId, + peerHandle.peerId); + inOrder.verify(mockSessionCallback).onMessageReceived(peerIdCaptor.capture(), + eq(string1.getBytes())); + assertEquals(((WifiNanManager.OpaquePeerHandle) peerIdCaptor.getValue()).peerId, + peerHandle.peerId); inOrder.verify(mockSessionCallback).onMessageSendFailed(eq(messageId)); inOrder.verify(mockSessionCallback).onMessageSent(eq(messageId)); @@ -928,7 +942,8 @@ public class WifiNanManagerTest { public void testNetworkSpecifierWithClient() throws Exception { final int clientId = 4565; final int sessionId = 123; - final int peerId = 123412; + final WifiNanManager.OpaquePeerHandle peerHandle = new WifiNanManager.OpaquePeerHandle( + 123412); final int role = WifiNanManager.WIFI_NAN_DATA_PATH_ROLE_INITIATOR; final String token = "Some arbitrary token string - can really be anything"; final ConfigRequest configRequest = new ConfigRequest.Builder().build(); @@ -966,7 +981,7 @@ public class WifiNanManagerTest { inOrder.verify(mockSessionCallback).onPublishStarted(publishSession.capture()); // (3) request a network specifier from the session - String networkSpecifier = publishSession.getValue().createNetworkSpecifier(role, peerId, + String networkSpecifier = publishSession.getValue().createNetworkSpecifier(role, peerHandle, token.getBytes()); // validate format @@ -977,7 +992,7 @@ public class WifiNanManagerTest { equalTo(jsonObject.getInt(WifiNanManager.NETWORK_SPECIFIER_KEY_CLIENT_ID))); collector.checkThat("session_id", sessionId, equalTo(jsonObject.getInt(WifiNanManager.NETWORK_SPECIFIER_KEY_SESSION_ID))); - collector.checkThat("peer_id", peerId, + collector.checkThat("peer_id", peerHandle.peerId, equalTo(jsonObject.getInt(WifiNanManager.NETWORK_SPECIFIER_KEY_PEER_ID))); collector.checkThat("token", tokenB64, equalTo(jsonObject.getString(WifiNanManager.NETWORK_SPECIFIER_KEY_TOKEN))); |