[android/test] Add pipeline api test for mqtt elements
authorYongjoo Ahn <yongjoo1.ahn@samsung.com>
Tue, 16 Nov 2021 00:54:01 +0000 (09:54 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 17 Nov 2021 00:25:39 +0000 (09:25 +0900)
- Add a test for mqtt elements. Because it needs running mqtt broker,
  it should be ignored at this moment.
- At least it is passed in configured environment (mqtt broker is
  installed in the android device and running locally)
- Add permisiion for internet in AndroidManifest.xml

Signed-off-by: Yongjoo Ahn <yongjoo1.ahn@samsung.com>
java/android/nnstreamer/src/androidTest/java/org/nnsuite/nnstreamer/APITestPipeline.java
java/android/nnstreamer/src/main/AndroidManifest.xml

index 4a49fe6..dde5cfd 100644 (file)
@@ -7,6 +7,7 @@ import android.view.Surface;
 import android.view.SurfaceView;
 
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -2273,4 +2274,45 @@ public class APITestPipeline {
             fail();
         }
     }
+
+    @Ignore("Checking available mqtt broker is not ready, please ignore")
+    @Test
+    public void testMQTTElement() {
+        String sub_desc = "mqttsrc sub-topic=test/videotestsrc ! " +
+                "video/x-raw,format=RGB,width=40,height=40,framerate=5/1 ! " +
+                "tensor_converter ! tensor_sink name=sinkx";
+        String pub_desc = "videotestsrc is-live=true num-buffers=10 ! " +
+                "video/x-raw,format=RGB,width=40,height=40,framerate=5/1 ! " +
+                "mqttsink pub-topic=test/videotestsrc";
+
+        try {
+            Pipeline sub_pipe = new Pipeline(sub_desc);
+            /* register sink callback */
+            sub_pipe.registerSinkCallback("sinkx", new Pipeline.NewDataCallback() {
+                @Override
+                public void onNewDataReceived(TensorsData data) {
+                    if (data == null || data.getTensorsCount() != 1) {
+                        mInvalidState = true;
+                        return;
+                    }
+                    mReceived++;
+                }
+            });
+            sub_pipe.start();
+
+            Pipeline pub_pipe = new Pipeline(pub_desc);
+            pub_pipe.start();
+
+            Thread.sleep(3000);
+
+            sub_pipe.stop();
+            pub_pipe.stop();
+
+            /* check received data from sink */
+            assertFalse(mInvalidState);
+            assertEquals(10, mReceived);
+        } catch (Exception e) {
+            fail();
+        }
+    }
 }
index 9b0a6f1..5d9f71a 100644 (file)
@@ -3,6 +3,7 @@
 
     <uses-feature android:glEsVersion="0x00020000"/>
     <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
+    <uses-permission android:name="android.permission.INTERNET" />
 
     <application
         android:extractNativeLibs="true"