[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
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 37c0ac5..ab87815 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 @@
         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 @@
             mSubscribeDiscoverySession = null;
             return session;
         }
-
     }
 
     @Override
@@ -528,9 +527,43 @@
         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();