Add initial instrumentation tests for Android TCP.
authorChanhee Lee <ch2102.lee@samsung.com>
Thu, 1 Sep 2022 08:25:49 +0000 (17:25 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 15 Sep 2022 05:38:55 +0000 (14:38 +0900)
[Problem] There's no implementation for Android TCP.
[Solution] At first, add basic and empty instrumentation test cases
           to describe expected Android TCP functionalities.

android/aitt/build.gradle
android/modules/tcp/.gitignore [new file with mode: 0644]
android/modules/tcp/build.gradle [new file with mode: 0644]
android/modules/tcp/consumer-rules.pro [new file with mode: 0644]
android/modules/tcp/proguard-rules.pro [new file with mode: 0644]
android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java [new file with mode: 0644]
android/modules/tcp/src/main/AndroidManifest.xml [new file with mode: 0644]
android/settings.gradle
debian/control
settings.gradle

index f8634a8..1429134 100644 (file)
@@ -45,6 +45,9 @@ android {
     }
 
     buildTypes {
+        debug {
+            debuggable true
+        }
         release {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
@@ -84,12 +87,16 @@ dependencies {
 
     implementation 'androidx.appcompat:appcompat:1.4.1'
     implementation 'com.google.flatbuffers:flatbuffers-java:2.0.0'
+
+    implementation project(path: ':android:modules:tcp')
     implementation project(path: ':android:modules:webrtc')
+
     testImplementation 'junit:junit:4.13.2'
     testImplementation 'org.mockito:mockito-core:2.25.0'
     testImplementation 'org.powermock:powermock-core:2.0.0-beta.5'
     testImplementation 'org.powermock:powermock-module-junit4:2.0.0-beta.5'
     testImplementation 'org.powermock:powermock-api-mockito2:2.0.0-beta.5'
+
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
 }
 
diff --git a/android/modules/tcp/.gitignore b/android/modules/tcp/.gitignore
new file mode 100644 (file)
index 0000000..796b96d
--- /dev/null
@@ -0,0 +1 @@
+/build
diff --git a/android/modules/tcp/build.gradle b/android/modules/tcp/build.gradle
new file mode 100644 (file)
index 0000000..503bed7
--- /dev/null
@@ -0,0 +1,37 @@
+plugins {
+    id 'com.android.library'
+}
+
+android {
+    compileSdkVersion 31
+
+    defaultConfig {
+        minSdkVersion 28
+        targetSdkVersion 31
+
+        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
+        consumerProguardFiles "consumer-rules.pro"
+    }
+
+    buildTypes {
+        release {
+            minifyEnabled false
+            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+        }
+    }
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
+    }
+}
+
+dependencies {
+    implementation 'androidx.appcompat:appcompat:1.4.1'
+    implementation 'com.google.android.material:material:1.4.0'
+
+    testImplementation 'junit:junit:4.13.2'
+
+    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
+    androidTestImplementation project(path: ':android:aitt')
+}
diff --git a/android/modules/tcp/consumer-rules.pro b/android/modules/tcp/consumer-rules.pro
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/android/modules/tcp/proguard-rules.pro b/android/modules/tcp/proguard-rules.pro
new file mode 100644 (file)
index 0000000..f1b4245
--- /dev/null
@@ -0,0 +1,21 @@
+# Add project specific ProGuard rules here.
+# You can control the set of applied configuration files using the
+# proguardFiles setting in build.gradle.
+#
+# For more details, see
+#   http://developer.android.com/guide/developing/tools/proguard.html
+
+# If your project uses WebView with JS, uncomment the following
+# and specify the fully qualified class name to the JavaScript interface
+# class:
+#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
+#   public *;
+#}
+
+# Uncomment this to preserve the line number information for
+# debugging stack traces.
+#-keepattributes SourceFile,LineNumberTable
+
+# If you keep the line number information, uncomment this to
+# hide the original source file name.
+#-renamesourcefileattribute SourceFile
diff --git a/android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java b/android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java
new file mode 100644 (file)
index 0000000..bb08157
--- /dev/null
@@ -0,0 +1,89 @@
+package com.samsung.android.modules.tcp;
+
+import android.content.Context;
+import android.util.Log;
+
+import androidx.test.platform.app.InstrumentationRegistry;
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.*;
+
+import com.samsung.android.aitt.Aitt;
+
+@RunWith(AndroidJUnit4.class)
+public class TCPInstrumentedTest {
+
+    private static Context appContext;
+
+    private static final String TAG = "AITT-ANDROID";
+    private static final String aittId = "aitt";
+    private final String topic = "aitt/test";
+    private final String message = "test message";
+
+    @BeforeClass
+    public static void initialize() throws InstantiationException {
+        appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+    }
+
+    @Test
+    public void testPublishWithTCP_P() {
+        try {
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("AITT instance is null.", aitt);
+            // TODO: aitt.connect(brokerIp, port);
+
+            byte[] payload = message.getBytes();
+            aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
+
+            // TODO: aitt.disconnect();
+        } catch(Exception e) {
+            fail("Failed to execute testPublishWithTCP_P " + e);
+        }
+    }
+
+    @Test
+    public void testSubscribeWithTCP_P() {
+        try {
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("AITT instance is null.", aitt);
+            // TODO: aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, message -> {
+                Log.i(TAG, "Subscription callback is called");
+            }, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE);
+
+            // TODO: aitt.disconnect();
+        } catch(Exception e) {
+            fail("Failed testSubscribeWithTCP_P " + e);
+        }
+    }
+
+    @Test
+    public void testPublishSubscribeWithTCP_P() {
+        try {
+            Aitt aitt = new Aitt(appContext, aittId);
+
+            assertNotNull("AITT instance is null.", aitt);
+            // TODO: aitt.connect(brokerIp, port);
+
+            aitt.subscribe(topic, message -> {
+                String _topic = message.getTopic();
+                byte[] _payload = message.getPayload();
+                Log.i(TAG, "Topic = " + _topic + ", Payload = " + _payload);
+            }, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE);
+
+            byte[] payload = message.getBytes();
+            aitt.publish(topic, payload, Aitt.Protocol.TCP, Aitt.QoS.AT_LEAST_ONCE, false);
+
+            // TODO: aitt.disconnect();
+        } catch(Exception e) {
+            fail("Failed testPublishSubscribeWithTCP_P " + e);
+        }
+    }
+}
diff --git a/android/modules/tcp/src/main/AndroidManifest.xml b/android/modules/tcp/src/main/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..0c655be
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.samsung.android.modules.tcp">
+
+</manifest>
index aa2ce81..1883453 100644 (file)
@@ -1,4 +1,5 @@
 include ':aitt'
 include ':flatbuffers'
 include ':mosquitto'
+include ':modules:tcp'
 include ':modules:webrtc'
index c4c06ab..b7bc322 100644 (file)
@@ -2,7 +2,7 @@ Source: aitt
 Section: libs
 Priority: optional
 Maintainer: Semun Lee <semun.lee@samsung.com>
-Build-Depends: gcc-9 | gcc-8 | gcc-7 | gcc-6 | gcc-5 (>=5.4),
+Build-Depends: gcc-11 | gcc-9 | gcc-8 | gcc-7 | gcc-6 | gcc-5 (>=5.4),
  cmake, debhelper (>=9), libmosquitto-dev, lcov, libgmock-dev, libflatbuffers-dev, libglib2.0-dev
 Standards-Version: 0.0.1
 
index a8e5154..2869ff7 100644 (file)
@@ -1,4 +1,5 @@
 include ':android:aitt'
 include ':android:flatbuffers'
 include ':android:mosquitto'
+include ':android:modules:tcp'
 include ':android:modules:webrtc'