From ab5186e4f64233d72c1ea75716f7581d4b0f5ed9 Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Thu, 2 Mar 2017 13:54:14 -0800 Subject: [PATCH] [AWARE] CTS for failure mode of send message API Test that sending a message with invalid peer handle (null) fails as expected. Note: limited testing - Single device testing doesn't have a peer - Cannot create an invalid peer handle since opaque object Bug: 30556108 Test: CTS tests pass Change-Id: I72f4b67ea3c3dfc00aa48f6601d064b406dabde7 --- .../net/wifi/aware/cts/SingleDeviceTest.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java b/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java index 37c0ac5892..ab87815399 100644 --- a/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java +++ b/tests/cts/net/src/android/net/wifi/aware/cts/SingleDeviceTest.java @@ -75,7 +75,7 @@ public class SingleDeviceTest extends AndroidTestCase { boolean waitForStateChange() throws InterruptedException { return mBlocker.await(WAIT_FOR_AWARE_CHANGE_SECS, TimeUnit.SECONDS); } - }; + } private class AttachCallbackTest extends AttachCallback { static final int ATTACHED = 0; @@ -289,7 +289,6 @@ public class SingleDeviceTest extends AndroidTestCase { mSubscribeDiscoverySession = null; return session; } - } @Override @@ -528,9 +527,43 @@ public class SingleDeviceTest extends AndroidTestCase { session.destroy(); } + /** + * Test the send message flow. Since testing single device cannot send to a real peer - + * validate that sending to a bogus peer fails. + */ + public void testSendMessageFail() { + if (!TestUtils.shouldTestWifiAware(getContext())) { + return; + } + + WifiAwareSession session = attachAndGetSession(); + + PublishConfig publishConfig = new PublishConfig.Builder().setServiceName( + "ValidName").build(); + DiscoverySessionCallbackTest discoveryCb = new DiscoverySessionCallbackTest(); + + // 1. publish + session.publish(publishConfig, discoveryCb, null); + assertTrue("Publish started", + discoveryCb.waitForCallback(DiscoverySessionCallbackTest.ON_PUBLISH_STARTED)); + PublishDiscoverySession discoverySession = discoveryCb.getPublishDiscoverySession(); + assertNotNull("Publish session", discoverySession); + + // 2. send a message with a null peer-handle - expect exception + try { + discoverySession.sendMessage(null, -1290, "some message".getBytes()); + fail("Expected IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // empty + } + + discoverySession.destroy(); + session.destroy(); + } + // local utilities - WifiAwareSession attachAndGetSession() { + private WifiAwareSession attachAndGetSession() { AttachCallbackTest attachCb = new AttachCallbackTest(); mWifiAwareManager.attach(attachCb, null); int cbCalled = attachCb.waitForAnyCallback();