From d1a2143c201a409b4771534e6a4aedfd31af900b Mon Sep 17 00:00:00 2001 From: Chanhee Lee Date: Thu, 1 Sep 2022 17:25:49 +0900 Subject: [PATCH] Add initial instrumentation tests for Android TCP. [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 | 7 ++ android/modules/tcp/.gitignore | 1 + android/modules/tcp/build.gradle | 37 +++++++++ android/modules/tcp/consumer-rules.pro | 0 android/modules/tcp/proguard-rules.pro | 21 +++++ .../android/modules/tcp/TCPInstrumentedTest.java | 89 ++++++++++++++++++++++ android/modules/tcp/src/main/AndroidManifest.xml | 5 ++ android/settings.gradle | 1 + debian/control | 2 +- settings.gradle | 1 + 10 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 android/modules/tcp/.gitignore create mode 100644 android/modules/tcp/build.gradle create mode 100644 android/modules/tcp/consumer-rules.pro create mode 100644 android/modules/tcp/proguard-rules.pro create mode 100644 android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java create mode 100644 android/modules/tcp/src/main/AndroidManifest.xml diff --git a/android/aitt/build.gradle b/android/aitt/build.gradle index f8634a8..1429134 100644 --- a/android/aitt/build.gradle +++ b/android/aitt/build.gradle @@ -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 index 0000000..796b96d --- /dev/null +++ b/android/modules/tcp/.gitignore @@ -0,0 +1 @@ +/build diff --git a/android/modules/tcp/build.gradle b/android/modules/tcp/build.gradle new file mode 100644 index 0000000..503bed7 --- /dev/null +++ b/android/modules/tcp/build.gradle @@ -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 index 0000000..e69de29 diff --git a/android/modules/tcp/proguard-rules.pro b/android/modules/tcp/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/android/modules/tcp/proguard-rules.pro @@ -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 index 0000000..bb08157 --- /dev/null +++ b/android/modules/tcp/src/androidTest/java/com/samsung/android/modules/tcp/TCPInstrumentedTest.java @@ -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 index 0000000..0c655be --- /dev/null +++ b/android/modules/tcp/src/main/AndroidManifest.xml @@ -0,0 +1,5 @@ + + + + diff --git a/android/settings.gradle b/android/settings.gradle index aa2ce81..1883453 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,5 @@ include ':aitt' include ':flatbuffers' include ':mosquitto' +include ':modules:tcp' include ':modules:webrtc' diff --git a/debian/control b/debian/control index c4c06ab..b7bc322 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: aitt Section: libs Priority: optional Maintainer: Semun Lee -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 diff --git a/settings.gradle b/settings.gradle index a8e5154..2869ff7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ include ':android:aitt' include ':android:flatbuffers' include ':android:mosquitto' +include ':android:modules:tcp' include ':android:modules:webrtc' -- 2.7.4