Add test cases to android aitt
authorPraveen Naik S <praveen.s@samsung.com>
Mon, 11 Sep 2023 14:43:30 +0000 (20:13 +0530)
committerPraveen Naik S <praveen.s@samsung.com>
Wed, 13 Sep 2023 02:45:26 +0000 (11:45 +0900)
- Add test cases to different modules of android-aitt.
- Improve the test coverage

android/aitt/src/main/java/com/samsung/android/aitt/handler/WebRTCHandler.java
android/aitt/src/test/java/com/samsung/android/aitt/AittMessageUnitTest.java
android/aitt/src/test/java/com/samsung/android/aitt/AittUnitTest.java
android/modules/rtsp/src/androidTest/java/com/samsung/android/modules/rtsp/RTSPInstrumentedTest.java
android/modules/webrtc/src/androidTest/java/com/samsung/android/modules/webrtc/WebRTCInstrumentedTest.java

index a89ed70..690816f 100644 (file)
@@ -37,6 +37,9 @@ public final class WebRTCHandler extends StreamHandler {
         if (protocol != Aitt.Protocol.WEBRTC)
             throw new InvalidParameterException("Invalid protocol");
 
+        if (topic == null || topic.isEmpty())
+            throw new InvalidParameterException("Invalid topic");
+
         if (role == AittStream.StreamRole.SUBSCRIBER) {
             return createSubscriberStream(topic, role, context);
         } else {
index 286149d..601c8db 100644 (file)
@@ -168,4 +168,10 @@ public class AittMessageUnitTest {
         byte[] newPayload = aittMessage.getPayload();
         assertEquals("Received payload and expected payload are equal", 0, newPayload.length);
     }
+
+    @Test(expected = NullPointerException.class)
+    public void testGetInvalidPayload_N() {
+        AittMessage aittMessage = new AittMessage(null);
+        byte[] newPayload = aittMessage.getPayload();
+    }
 }
index 5e45896..8882549 100644 (file)
@@ -17,6 +17,7 @@ package com.samsung.android.aitt;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.mock;
@@ -663,6 +664,21 @@ public class AittUnitTest {
     }
 
     @Test
+    public void testSubscribeIpcInvalidCallback_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.subscribe(topic, null, Aitt.Protocol.IPC, Aitt.QoS.AT_MOST_ONCE));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testSubscribeIpcInvalidCallback " + e);
+        }
+    }
+
+    @Test
     public void testSubscribeAnyProtocol_P() {
         try {
             shadowJniInterface.setInitReturn(true);
@@ -1002,7 +1018,7 @@ public class AittUnitTest {
     }
 
     @Test
-    public void testCreateRTSPStreamInvalidTopic_N() {
+    public void testCreateRTSPSubscriberStreamEmptyTopic_N() {
         try {
             shadowJniInterface.setInitReturn(true);
             Aitt aitt = new Aitt(appContext, aittId);
@@ -1012,7 +1028,144 @@ public class AittUnitTest {
 
             aitt.disconnect();
         } catch (Exception e) {
-            fail("Failed testCreateRTSPStreamInvalidTopic " + e);
+            fail("Failed testCreateRTSPSubscriberStreamEmptyTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateRTSPPublisherStreamEmptyTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, "", AittStream.StreamRole.PUBLISHER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateRTSPPublisherStreamEmptyTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateRTSPSubscriberStreamNullTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, null, AittStream.StreamRole.SUBSCRIBER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateRTSPSubscriberStreamNullTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateRTSPPublisherStreamNullTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.RTSP, null, AittStream.StreamRole.PUBLISHER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateRTSPPublisherStreamNullTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateWebRTCSubscriberStreamEmptyTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, "", AittStream.StreamRole.SUBSCRIBER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateWebRTCSubscriberStreamEmptyTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateWebRTCPublisherStreamEmptyTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, "", AittStream.StreamRole.PUBLISHER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateWebRTCPublisherStreamEmptyTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateWebRTCSubscriberStreamNullTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, null, AittStream.StreamRole.SUBSCRIBER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateWebRTCSubscriberStreamNullTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateWebRTCPublisherStreamNullTopic_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            assertThrows(IllegalArgumentException.class, () -> aitt.createStream(Aitt.Protocol.WEBRTC, null, AittStream.StreamRole.PUBLISHER));
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateWebRTCPublisherStreamNullTopic " + e);
+        }
+    }
+
+    @Test
+    public void testCreateMqttStream_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            AittStream aittStream = aitt.createStream(Aitt.Protocol.MQTT, topic, AittStream.StreamRole.PUBLISHER);
+            assertNull(aittStream);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateMqttStream " + e);
+        }
+    }
+
+    @Test
+    public void testCreateTcpStream_N() {
+        try {
+            shadowJniInterface.setInitReturn(true);
+            Aitt aitt = new Aitt(appContext, aittId);
+            aitt.connect(brokerIp, port);
+
+            AittStream aittStream = aitt.createStream(Aitt.Protocol.TCP, topic, AittStream.StreamRole.PUBLISHER);
+            assertNull(aittStream);
+
+            aitt.disconnect();
+        } catch (Exception e) {
+            fail("Failed testCreateTcpStream " + e);
         }
     }
 }
index 8995f21..ab4f175 100644 (file)
@@ -245,6 +245,38 @@ public class RTSPInstrumentedTest {
     }
 
     @Test
+    public void testRTSPSetNullUri_N() {
+        try {
+            Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
+            aitt.connect(brokerIp, PORT);
+
+            AittStream publisher = aitt.createStream(Aitt.Protocol.RTSP, TEST_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisher.setConfig("URI", null));
+
+            publisher.disconnect();
+        } catch (Exception e) {
+            fail("Failed testRTSPSetNullUri, (" + e + ")");
+        }
+    }
+
+    @Test
+    public void testRTSPSetInvalidUri_N() {
+        try {
+            Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
+            aitt.connect(brokerIp, PORT);
+
+            AittStream publisher = aitt.createStream(Aitt.Protocol.RTSP, TEST_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisher.setConfig("URI", "tcp://someurl"));
+
+            publisher.disconnect();
+        } catch (Exception e) {
+            fail("Failed testRTSPSetInvalidUri, (" + e + ")");
+        }
+    }
+
+    @Test
     public void testRTSPSetNullKey_N() {
         try {
             Aitt aitt = new Aitt(appContext, AITT_ID, wifiIP, true);
index e7aeb84..1f297d5 100644 (file)
@@ -456,7 +456,7 @@ public class WebRTCInstrumentedTest {
     }
 
     @Test
-    public void testWebRTCStreamInvalidWidth_N() {
+    public void testWebRTCStreamNegativeWidth_N() {
         try {
             Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
             publisher.connect(brokerIp, PORT);
@@ -467,12 +467,28 @@ public class WebRTCInstrumentedTest {
 
             publisherStream.disconnect();
         } catch (Exception e) {
-            fail("Failed testWebRTCStreamInvalidWidth, (" + e + ")");
+            fail("Failed testWebRTCStreamNegativeWidth, (" + e + ")");
         }
     }
 
     @Test
-    public void testWebRTCStreamInvalidHeight_N() {
+    public void testWebRTCStreamZeroWidth_N() {
+        try {
+            Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+            publisher.connect(brokerIp, PORT);
+            AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("WIDTH", "0")
+                    .setConfig("HEIGHT", "240"));
+
+            publisherStream.disconnect();
+        } catch (Exception e) {
+            fail("Failed testWebRTCStreamZeroWidth, (" + e + ")");
+        }
+    }
+
+    @Test
+    public void testWebRTCStreamNegativeHeight_N() {
         try {
             Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
             publisher.connect(brokerIp, PORT);
@@ -483,11 +499,26 @@ public class WebRTCInstrumentedTest {
 
             publisherStream.disconnect();
         } catch (Exception e) {
-            fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+            fail("Failed testWebRTCStreamNegativeHeight, (" + e + ")");
         }
     }
 
     @Test
+    public void testWebRTCStreamZeroHeight_N() {
+        try {
+            Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+            publisher.connect(brokerIp, PORT);
+            AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("WIDTH", "320")
+                    .setConfig("HEIGHT", "0"));
+
+            publisherStream.disconnect();
+        } catch (Exception e) {
+            fail("Failed testWebRTCStreamZeroHeight, (" + e + ")");
+        }
+    }
+    @Test
     public void testWebRTCStreamInvalidSourceType_N() {
         try {
             Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
@@ -498,12 +529,26 @@ public class WebRTCInstrumentedTest {
 
             publisherStream.disconnect();
         } catch (Exception e) {
-            fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+            fail("Failed testWebRTCStreamInvalidSourceType, (" + e + ")");
+        }
+    }
+    @Test
+    public void testWebRTCStreamInvalidMediaFormat_N() {
+        try {
+            Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+            publisher.connect(brokerIp, PORT);
+            AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("MEDIA_FORMAT", "A"));
+
+            publisherStream.disconnect();
+        } catch (Exception e) {
+            fail("Failed testWebRTCStreamInvalidMediaFormat, (" + e + ")");
         }
     }
 
     @Test
-    public void testWebRTCStreamInvalidFrameRate_N() {
+    public void testWebRTCStreamNegativeFrameRate_N() {
         try {
             Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
             publisher.connect(brokerIp, PORT);
@@ -513,7 +558,22 @@ public class WebRTCInstrumentedTest {
 
             publisherStream.disconnect();
         } catch (Exception e) {
-            fail("Failed testWebRTCStreamInvalidHeight, (" + e + ")");
+            fail("Failed testWebRTCStreamNegativeFrameRate, (" + e + ")");
+        }
+    }
+
+    @Test
+    public void testWebRTCStreamZeroFrameRate_N() {
+        try {
+            Aitt publisher = new Aitt(appContext, AITT_WEBRTC_CLIENT_ID + VIDEO_PREFIX, wifiIP, true);
+            publisher.connect(brokerIp, PORT);
+            AittStream publisherStream = publisher.createStream(Aitt.Protocol.WEBRTC, TEST_VIDEO_TOPIC, PUBLISHER);
+
+            assertThrows(IllegalArgumentException.class, () -> publisherStream.setConfig("FRAME_RATE", "0"));
+
+            publisherStream.disconnect();
+        } catch (Exception e) {
+            fail("Failed testWebRTCStreamZeroFrameRate, (" + e + ")");
         }
     }