summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEtan Cohen <etancohen@google.com>2016-09-29 14:44:37 -0700
committerEtan Cohen <etancohen@google.com>2016-09-30 12:05:13 -0700
commit3796e636715ec00ac4548c4c09b0290ed09c8ba7 (patch)
tree59e4c9fec96213a671649fca147cec5d5ee2c9eb /tests
parente04f61522a496efcb6ab5b106253a0496fc1ef1f (diff)
[NAN] Add unit tests to validate that null or empty messages are supported
The code already supports null or empty array (byte[0]) messages. Add unit tests to validate framework support. (cherry-pick of commit 1a3d53d159020b248140dce100c241054c10c75f) Bug: 31676513 Test: unit-tests pass Change-Id: I23aa29861b1446176d13157ad682b3290ebaacb3
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/nan/WifiNanHalTest.java31
-rw-r--r--tests/wifitests/src/com/android/server/wifi/nan/WifiNanStateManagerTest.java51
2 files changed, 73 insertions, 9 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanHalTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanHalTest.java
index 8d881e47f..99b8596e5 100644
--- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanHalTest.java
@@ -245,6 +245,37 @@ public class WifiNanHalTest {
equalTo(msg.getBytes()));
}
+ /**
+ * Validate zero length message ("") is sent correctly through the HAL.
+ */
+ @Test
+ public void testSendMessageZeroLength() throws JSONException {
+ final short transactionId = 45;
+ final int pubSubId = 22;
+ final int reqInstanceId = 11;
+ final byte[] peer = HexEncoding.decode("000102030405".toCharArray(), false);
+ final String msg = "";
+ final int messageId = 10; /* garbage - not used by HAL */
+
+ mDut.sendMessage(transactionId, pubSubId, reqInstanceId, peer, msg.getBytes(), messageId);
+
+ verify(mNanHalMock).transmitFollowupHalMockNative(eq(transactionId), mArgs.capture());
+
+ Bundle argsData = HalMockUtils.convertJsonToBundle(mArgs.getValue());
+
+ collector.checkThat("publish_subscribe_id", argsData.getInt("publish_subscribe_id"),
+ equalTo(pubSubId));
+ collector.checkThat("requestor_instance_id", argsData.getInt("requestor_instance_id"),
+ equalTo(reqInstanceId));
+ collector.checkThat("addr", argsData.getByteArray("addr"), equalTo(peer));
+ collector.checkThat("priority", argsData.getInt("priority"), equalTo(0));
+ collector.checkThat("dw_or_faw", argsData.getInt("dw_or_faw"), equalTo(0));
+ collector.checkThat("service_specific_info_len",
+ argsData.getInt("service_specific_info_len"), equalTo(0));
+ collector.checkThat("service_specific_info", argsData.getByteArray("service_specific_info"),
+ equalTo(new byte[0]));
+ }
+
@Test
public void testSendMessageNull() throws JSONException {
diff --git a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanStateManagerTest.java b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanStateManagerTest.java
index 98abcfda9..b9fc83b18 100644
--- a/tests/wifitests/src/com/android/server/wifi/nan/WifiNanStateManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/nan/WifiNanStateManagerTest.java
@@ -26,6 +26,7 @@ import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyShort;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -1579,10 +1580,10 @@ public class WifiNanStateManagerTest {
}
/**
- * Validate that can send a NULL message successfully.
+ * Validate that can send empty message successfully: null, byte[0], ""
*/
@Test
- public void testSendMessageNull() throws Exception {
+ public void testSendEmptyMessages() throws Exception {
final int clientId = 1005;
final int uid = 1000;
final int pid = 2000;
@@ -1595,7 +1596,6 @@ public class WifiNanStateManagerTest {
final byte[] peerMac = HexEncoding.decode("060708090A0B".toCharArray(), false);
final String peerSsi = "some peer ssi data";
final String peerMatchFilter = "filter binary array represented as string";
- final byte[] msg = null;
final int messageId = 6948;
ConfigRequest configRequest = new ConfigRequest.Builder().build();
@@ -1609,6 +1609,7 @@ public class WifiNanStateManagerTest {
IWifiNanDiscoverySessionCallback.class);
ArgumentCaptor<Short> transactionId = ArgumentCaptor.forClass(Short.class);
ArgumentCaptor<Integer> sessionId = ArgumentCaptor.forClass(Integer.class);
+ ArgumentCaptor<byte[]> byteArrayCaptor = ArgumentCaptor.forClass(byte[].class);
InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mMockNative);
mDut.enableUsage();
@@ -1642,17 +1643,49 @@ public class WifiNanStateManagerTest {
inOrder.verify(mockSessionCallback).onMatch(requestorId, peerSsi.getBytes(),
peerMatchFilter.getBytes());
- // (3) message Tx successful queuing
- mDut.sendMessage(clientId, sessionId.getValue(), requestorId, msg, messageId, 0);
+ // (3) message null Tx successful queuing
+ mDut.sendMessage(clientId, sessionId.getValue(), requestorId, null, messageId, 0);
mMockLooper.dispatchAll();
inOrder.verify(mMockNative).sendMessage(transactionId.capture(), eq(subscribeId),
- eq(requestorId), eq(peerMac), eq(msg), eq(messageId));
- short tid1 = transactionId.getValue();
- mDut.onMessageSendQueuedSuccessResponse(tid1);
+ eq(requestorId), eq(peerMac), isNull(byte[].class), eq(messageId));
+ short tid = transactionId.getValue();
+ mDut.onMessageSendQueuedSuccessResponse(tid);
mMockLooper.dispatchAll();
// (4) final Tx results (on-air results)
- mDut.onMessageSendSuccessNotification(tid1);
+ mDut.onMessageSendSuccessNotification(tid);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mockSessionCallback).onMessageSendSuccess(messageId);
+ validateInternalSendMessageQueuesCleanedUp(messageId);
+
+ // (5) message byte[0] Tx successful queuing
+ mDut.sendMessage(clientId, sessionId.getValue(), requestorId, new byte[0], messageId, 0);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).sendMessage(transactionId.capture(), eq(subscribeId),
+ eq(requestorId), eq(peerMac), eq(new byte[0]), eq(messageId));
+ tid = transactionId.getValue();
+ mDut.onMessageSendQueuedSuccessResponse(tid);
+ mMockLooper.dispatchAll();
+
+ // (6) final Tx results (on-air results)
+ mDut.onMessageSendSuccessNotification(tid);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mockSessionCallback).onMessageSendSuccess(messageId);
+ validateInternalSendMessageQueuesCleanedUp(messageId);
+
+ // (7) message "" Tx successful queuing
+ mDut.sendMessage(clientId, sessionId.getValue(), requestorId, "".getBytes(), messageId, 0);
+ mMockLooper.dispatchAll();
+ inOrder.verify(mMockNative).sendMessage(transactionId.capture(), eq(subscribeId),
+ eq(requestorId), eq(peerMac), byteArrayCaptor.capture(), eq(messageId));
+ collector.checkThat("Empty message contents", "",
+ equalTo(new String(byteArrayCaptor.getValue())));
+ tid = transactionId.getValue();
+ mDut.onMessageSendQueuedSuccessResponse(tid);
+ mMockLooper.dispatchAll();
+
+ // (8) final Tx results (on-air results)
+ mDut.onMessageSendSuccessNotification(tid);
mMockLooper.dispatchAll();
inOrder.verify(mockSessionCallback).onMessageSendSuccess(messageId);
validateInternalSendMessageQueuesCleanedUp(messageId);