mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 15:23:25 +08:00
[tool] Add Kotlin autoformatting (#5374)
Updates the tooling to fetch and use `ktfmt` for Kotlin code, the same way it currently does for the Google Java formatter, and applies that formatting (in the default mode; see discussion in the linked issue) to the repository. In the future we could revisit the formatter or mode, but since this currently seems to be the most consistent with our other languages and to google3 formatting this is likely the option we'll want to stick with. Fixes https://github.com/flutter/flutter/issues/118756
This commit is contained in:
5
.ci.yaml
5
.ci.yaml
@ -131,10 +131,11 @@ targets:
|
||||
target_file: repo_checks.yaml
|
||||
channel: master
|
||||
version_file: flutter_master.version
|
||||
# The format check requires clang-format.
|
||||
# The format check requires clang-format, and the current version of ktfmt requires JDK 11+.
|
||||
dependencies: >-
|
||||
[
|
||||
{"dependency": "clang", "version": "git_revision:5d5aba78dbbee75508f01bcaa69aedb2ab79065a"}
|
||||
{"dependency": "clang", "version": "git_revision:5d5aba78dbbee75508f01bcaa69aedb2ab79065a"},
|
||||
{"dependency": "open_jdk", "version": "version:17"}
|
||||
]
|
||||
|
||||
- name: Linux dart_unit_test_shard_1 master
|
||||
|
@ -5,6 +5,4 @@ package dev.flutter.packages.animations.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,5 +5,4 @@ package com.example.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package dev.flutter.plugins.file_selector_example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package dev.flutter.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package com.example.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,5 +5,4 @@ package io.flutter.packages.flutter_markdown_example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package com.example.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,6 +5,4 @@ package io.flutter.packages.palettegenerator.imagecolors
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -146,14 +146,14 @@ private class PigeonApiImplementation: ExampleHostApi {
|
||||
### Kotlin
|
||||
<?code-excerpt "android/app/src/main/kotlin/dev/flutter/pigeon_example_app/MainActivity.kt (kotlin-class)"?>
|
||||
```kotlin
|
||||
private class PigeonApiImplementation: ExampleHostApi {
|
||||
private class PigeonApiImplementation : ExampleHostApi {
|
||||
override fun getHostLanguage(): String {
|
||||
return "Kotlin"
|
||||
}
|
||||
|
||||
override fun add(a: Long, b: Long): Long {
|
||||
if (a < 0L || b < 0L) {
|
||||
throw FlutterError("code", "message", "details");
|
||||
throw FlutterError("code", "message", "details")
|
||||
}
|
||||
return a + b
|
||||
}
|
||||
@ -258,9 +258,7 @@ private class PigeonFlutterApi {
|
||||
}
|
||||
|
||||
fun callFlutterMethod(aString: String, callback: (Result<String>) -> Unit) {
|
||||
flutterApi!!.flutterMethod(aString) {
|
||||
echo -> callback(Result.success(echo))
|
||||
}
|
||||
flutterApi!!.flutterMethod(aString) { echo -> callback(Result.success(echo)) }
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -5,24 +5,23 @@
|
||||
package dev.flutter.pigeon_example_app
|
||||
|
||||
import ExampleHostApi
|
||||
import FlutterError
|
||||
import MessageData
|
||||
import MessageFlutterApi
|
||||
import FlutterError
|
||||
|
||||
import androidx.annotation.NonNull
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
|
||||
// #docregion kotlin-class
|
||||
private class PigeonApiImplementation: ExampleHostApi {
|
||||
private class PigeonApiImplementation : ExampleHostApi {
|
||||
override fun getHostLanguage(): String {
|
||||
return "Kotlin"
|
||||
}
|
||||
|
||||
override fun add(a: Long, b: Long): Long {
|
||||
if (a < 0L || b < 0L) {
|
||||
throw FlutterError("code", "message", "details");
|
||||
throw FlutterError("code", "message", "details")
|
||||
}
|
||||
return a + b
|
||||
}
|
||||
@ -47,18 +46,16 @@ private class PigeonFlutterApi {
|
||||
}
|
||||
|
||||
fun callFlutterMethod(aString: String, callback: (Result<String>) -> Unit) {
|
||||
flutterApi!!.flutterMethod(aString) {
|
||||
echo -> callback(Result.success(echo))
|
||||
}
|
||||
flutterApi!!.flutterMethod(aString) { echo -> callback(Result.success(echo)) }
|
||||
}
|
||||
}
|
||||
// #enddocregion kotlin-class-flutter
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
class MainActivity : FlutterActivity() {
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
val api = PigeonApiImplementation()
|
||||
ExampleHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api);
|
||||
ExampleHostApi.setUp(flutterEngine.dartExecutor.binaryMessenger, api)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
// Autogenerated from Pigeon, do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
|
||||
import android.util.Log
|
||||
import io.flutter.plugin.common.BasicMessageChannel
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
@ -19,33 +18,31 @@ private fun wrapResult(result: Any?): List<Any?> {
|
||||
|
||||
private fun wrapError(exception: Throwable): List<Any?> {
|
||||
if (exception is FlutterError) {
|
||||
return listOf(
|
||||
exception.code,
|
||||
exception.message,
|
||||
exception.details
|
||||
)
|
||||
return listOf(exception.code, exception.message, exception.details)
|
||||
} else {
|
||||
return listOf(
|
||||
exception.javaClass.simpleName,
|
||||
exception.toString(),
|
||||
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
|
||||
)
|
||||
exception.javaClass.simpleName,
|
||||
exception.toString(),
|
||||
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception))
|
||||
}
|
||||
}
|
||||
|
||||
private fun createConnectionError(channelName: String): FlutterError {
|
||||
return FlutterError("channel-error", "Unable to establish connection on channel: '$channelName'.", "")}
|
||||
return FlutterError(
|
||||
"channel-error", "Unable to establish connection on channel: '$channelName'.", "")
|
||||
}
|
||||
|
||||
/**
|
||||
* Error class for passing custom error details to Flutter via a thrown PlatformException.
|
||||
*
|
||||
* @property code The error code.
|
||||
* @property message The error message.
|
||||
* @property details The error details. Must be a datatype supported by the api codec.
|
||||
*/
|
||||
class FlutterError (
|
||||
val code: String,
|
||||
override val message: String? = null,
|
||||
val details: Any? = null
|
||||
class FlutterError(
|
||||
val code: String,
|
||||
override val message: String? = null,
|
||||
val details: Any? = null
|
||||
) : Throwable()
|
||||
|
||||
enum class Code(val raw: Int) {
|
||||
@ -60,12 +57,11 @@ enum class Code(val raw: Int) {
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
data class MessageData (
|
||||
val name: String? = null,
|
||||
val description: String? = null,
|
||||
val code: Code,
|
||||
val data: Map<String?, String?>
|
||||
|
||||
data class MessageData(
|
||||
val name: String? = null,
|
||||
val description: String? = null,
|
||||
val code: Code,
|
||||
val data: Map<String?, String?>
|
||||
) {
|
||||
companion object {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@ -77,12 +73,13 @@ data class MessageData (
|
||||
return MessageData(name, description, code, data)
|
||||
}
|
||||
}
|
||||
|
||||
fun toList(): List<Any?> {
|
||||
return listOf<Any?>(
|
||||
name,
|
||||
description,
|
||||
code.raw,
|
||||
data,
|
||||
name,
|
||||
description,
|
||||
code.raw,
|
||||
data,
|
||||
)
|
||||
}
|
||||
}
|
||||
@ -92,14 +89,13 @@ private object ExampleHostApiCodec : StandardMessageCodec() {
|
||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||
return when (type) {
|
||||
128.toByte() -> {
|
||||
return (readValue(buffer) as? List<Any?>)?.let {
|
||||
MessageData.fromList(it)
|
||||
}
|
||||
return (readValue(buffer) as? List<Any?>)?.let { MessageData.fromList(it) }
|
||||
}
|
||||
else -> super.readValueOfType(type, buffer)
|
||||
}
|
||||
}
|
||||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
|
||||
|
||||
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
|
||||
when (value) {
|
||||
is MessageData -> {
|
||||
stream.write(128)
|
||||
@ -113,19 +109,23 @@ private object ExampleHostApiCodec : StandardMessageCodec() {
|
||||
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
|
||||
interface ExampleHostApi {
|
||||
fun getHostLanguage(): String
|
||||
|
||||
fun add(a: Long, b: Long): Long
|
||||
|
||||
fun sendMessage(message: MessageData, callback: (Result<Boolean>) -> Unit)
|
||||
|
||||
companion object {
|
||||
/** The codec used by ExampleHostApi. */
|
||||
val codec: MessageCodec<Any?> by lazy {
|
||||
ExampleHostApiCodec
|
||||
}
|
||||
val codec: MessageCodec<Any?> by lazy { ExampleHostApiCodec }
|
||||
/** Sets up an instance of `ExampleHostApi` to handle messages through the `binaryMessenger`. */
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun setUp(binaryMessenger: BinaryMessenger, api: ExampleHostApi?) {
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage", codec)
|
||||
val channel =
|
||||
BasicMessageChannel<Any?>(
|
||||
binaryMessenger,
|
||||
"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.getHostLanguage",
|
||||
codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { _, reply ->
|
||||
var wrapped: List<Any?>
|
||||
@ -141,7 +141,11 @@ interface ExampleHostApi {
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add", codec)
|
||||
val channel =
|
||||
BasicMessageChannel<Any?>(
|
||||
binaryMessenger,
|
||||
"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.add",
|
||||
codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val args = message as List<Any?>
|
||||
@ -160,7 +164,11 @@ interface ExampleHostApi {
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage", codec)
|
||||
val channel =
|
||||
BasicMessageChannel<Any?>(
|
||||
binaryMessenger,
|
||||
"dev.flutter.pigeon.pigeon_example_package.ExampleHostApi.sendMessage",
|
||||
codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val args = message as List<Any?>
|
||||
@ -187,26 +195,30 @@ interface ExampleHostApi {
|
||||
class MessageFlutterApi(private val binaryMessenger: BinaryMessenger) {
|
||||
companion object {
|
||||
/** The codec used by MessageFlutterApi. */
|
||||
val codec: MessageCodec<Any?> by lazy {
|
||||
StandardMessageCodec()
|
||||
}
|
||||
val codec: MessageCodec<Any?> by lazy { StandardMessageCodec() }
|
||||
}
|
||||
|
||||
fun flutterMethod(aStringArg: String?, callback: (Result<String>) -> Unit) {
|
||||
val channelName = "dev.flutter.pigeon.pigeon_example_package.MessageFlutterApi.flutterMethod"
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, channelName, codec)
|
||||
channel.send(listOf(aStringArg)) {
|
||||
if (it is List<*>) {
|
||||
if (it.size > 1) {
|
||||
callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)));
|
||||
callback(Result.failure(FlutterError(it[0] as String, it[1] as String, it[2] as String?)))
|
||||
} else if (it[0] == null) {
|
||||
callback(Result.failure(FlutterError("null-error", "Flutter api returned null value for non-null return value.", "")));
|
||||
callback(
|
||||
Result.failure(
|
||||
FlutterError(
|
||||
"null-error",
|
||||
"Flutter api returned null value for non-null return value.",
|
||||
"")))
|
||||
} else {
|
||||
val output = it[0] as String
|
||||
callback(Result.success(output));
|
||||
callback(Result.success(output))
|
||||
}
|
||||
} else {
|
||||
callback(Result.failure(createConnectionError(channelName)));
|
||||
}
|
||||
callback(Result.failure(createConnectionError(channelName)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -5,17 +5,10 @@
|
||||
package com.example.test_plugin
|
||||
|
||||
import androidx.annotation.NonNull
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin
|
||||
import io.flutter.plugin.common.MethodCall
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
|
||||
|
||||
/**
|
||||
* This plugin handles the native side of the integration tests in
|
||||
* example/integration_test/.
|
||||
*/
|
||||
class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
/** This plugin handles the native side of the integration tests in example/integration_test/. */
|
||||
class TestPlugin : FlutterPlugin, HostIntegrationCoreApi {
|
||||
var flutterApi: FlutterIntegrationCoreApi? = null
|
||||
|
||||
override fun onAttachedToEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
@ -23,13 +16,11 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
flutterApi = FlutterIntegrationCoreApi(binding.getBinaryMessenger())
|
||||
}
|
||||
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
|
||||
}
|
||||
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {}
|
||||
|
||||
// HostIntegrationCoreApi
|
||||
|
||||
override fun noop() {
|
||||
}
|
||||
override fun noop() {}
|
||||
|
||||
override fun echoAllTypes(everything: AllTypes): AllTypes {
|
||||
return everything
|
||||
@ -40,15 +31,15 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
}
|
||||
|
||||
override fun throwError(): Any? {
|
||||
throw Exception("An error");
|
||||
throw Exception("An error")
|
||||
}
|
||||
|
||||
override fun throwErrorFromVoid() {
|
||||
throw Exception("An error");
|
||||
throw Exception("An error")
|
||||
}
|
||||
|
||||
override fun throwFlutterError(): Any? {
|
||||
throw FlutterError("code", "message", "details");
|
||||
throw FlutterError("code", "message", "details")
|
||||
}
|
||||
|
||||
override fun echoInt(anInt: Long): Long {
|
||||
@ -99,8 +90,15 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
return AllClassesWrapper(AllNullableTypes(aNullableString = nullableString))
|
||||
}
|
||||
|
||||
override fun sendMultipleNullableTypes(aNullableBool: Boolean?, aNullableInt: Long?, aNullableString: String?): AllNullableTypes {
|
||||
return AllNullableTypes(aNullableBool = aNullableBool, aNullableInt = aNullableInt, aNullableString = aNullableString)
|
||||
override fun sendMultipleNullableTypes(
|
||||
aNullableBool: Boolean?,
|
||||
aNullableInt: Long?,
|
||||
aNullableString: String?
|
||||
): AllNullableTypes {
|
||||
return AllNullableTypes(
|
||||
aNullableBool = aNullableBool,
|
||||
aNullableInt = aNullableInt,
|
||||
aNullableString = aNullableString)
|
||||
}
|
||||
|
||||
override fun echoNullableInt(aNullableInt: Long?): Long? {
|
||||
@ -159,7 +157,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
callback(Result.success(everything))
|
||||
}
|
||||
|
||||
override fun echoAsyncNullableAllNullableTypes(everything: AllNullableTypes?, callback: (Result<AllNullableTypes?>) -> Unit) {
|
||||
override fun echoAsyncNullableAllNullableTypes(
|
||||
everything: AllNullableTypes?,
|
||||
callback: (Result<AllNullableTypes?>) -> Unit
|
||||
) {
|
||||
callback(Result.success(everything))
|
||||
}
|
||||
|
||||
@ -191,7 +192,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
callback(Result.success(aList))
|
||||
}
|
||||
|
||||
override fun echoAsyncMap(aMap: Map<String?, Any?>, callback: (Result<Map<String?, Any?>>) -> Unit) {
|
||||
override fun echoAsyncMap(
|
||||
aMap: Map<String?, Any?>,
|
||||
callback: (Result<Map<String?, Any?>>) -> Unit
|
||||
) {
|
||||
callback(Result.success(aMap))
|
||||
}
|
||||
|
||||
@ -215,7 +219,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
callback(Result.success(aString))
|
||||
}
|
||||
|
||||
override fun echoAsyncNullableUint8List(aUint8List: ByteArray?, callback: (Result<ByteArray?>) -> Unit) {
|
||||
override fun echoAsyncNullableUint8List(
|
||||
aUint8List: ByteArray?,
|
||||
callback: (Result<ByteArray?>) -> Unit
|
||||
) {
|
||||
callback(Result.success(aUint8List))
|
||||
}
|
||||
|
||||
@ -227,7 +234,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
callback(Result.success(aList))
|
||||
}
|
||||
|
||||
override fun echoAsyncNullableMap(aMap: Map<String?, Any?>?, callback: (Result<Map<String?, Any?>?>) -> Unit) {
|
||||
override fun echoAsyncNullableMap(
|
||||
aMap: Map<String?, Any?>?,
|
||||
callback: (Result<Map<String?, Any?>?>) -> Unit
|
||||
) {
|
||||
callback(Result.success(aMap))
|
||||
}
|
||||
|
||||
@ -242,6 +252,7 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
override fun callFlutterThrowError(callback: (Result<Any?>) -> Unit) {
|
||||
flutterApi!!.throwError() { result -> callback(result) }
|
||||
}
|
||||
|
||||
override fun callFlutterThrowErrorFromVoid(callback: (Result<Unit>) -> Unit) {
|
||||
flutterApi!!.throwErrorFromVoid() { result -> callback(result) }
|
||||
}
|
||||
@ -251,13 +262,13 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
}
|
||||
|
||||
override fun callFlutterSendMultipleNullableTypes(
|
||||
aNullableBool: Boolean?,
|
||||
aNullableInt: Long?,
|
||||
aNullableString: String?,
|
||||
callback: (Result<AllNullableTypes>) -> Unit
|
||||
aNullableBool: Boolean?,
|
||||
aNullableInt: Long?,
|
||||
aNullableString: String?,
|
||||
callback: (Result<AllNullableTypes>) -> Unit
|
||||
) {
|
||||
flutterApi!!.sendMultipleNullableTypes(aNullableBool, aNullableInt, aNullableString) {
|
||||
echo -> callback(echo)
|
||||
flutterApi!!.sendMultipleNullableTypes(aNullableBool, aNullableInt, aNullableString) { echo ->
|
||||
callback(echo)
|
||||
}
|
||||
}
|
||||
|
||||
@ -281,11 +292,14 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
flutterApi!!.echoUint8List(aList) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoList(aList: List<Any?>, callback: (Result<List<Any?>>) -> Unit){
|
||||
override fun callFlutterEchoList(aList: List<Any?>, callback: (Result<List<Any?>>) -> Unit) {
|
||||
flutterApi!!.echoList(aList) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoMap(aMap: Map<String?, Any?>, callback: (Result<Map<String?, Any?>>) -> Unit) {
|
||||
override fun callFlutterEchoMap(
|
||||
aMap: Map<String?, Any?>,
|
||||
callback: (Result<Map<String?, Any?>>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoMap(aMap) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
@ -293,7 +307,10 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
flutterApi!!.echoEnum(anEnum) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoAllNullableTypes(everything: AllNullableTypes?, callback: (Result<AllNullableTypes?>) -> Unit) {
|
||||
override fun callFlutterEchoAllNullableTypes(
|
||||
everything: AllNullableTypes?,
|
||||
callback: (Result<AllNullableTypes?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoAllNullableTypes(everything) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
@ -305,28 +322,42 @@ class TestPlugin: FlutterPlugin, HostIntegrationCoreApi {
|
||||
flutterApi!!.echoNullableInt(anInt) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableDouble(aDouble: Double?, callback: (Result<Double?>) -> Unit) {
|
||||
override fun callFlutterEchoNullableDouble(
|
||||
aDouble: Double?,
|
||||
callback: (Result<Double?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoNullableDouble(aDouble) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableString(aString: String?, callback: (Result<String?>) -> Unit) {
|
||||
override fun callFlutterEchoNullableString(
|
||||
aString: String?,
|
||||
callback: (Result<String?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoNullableString(aString) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableUint8List(aList: ByteArray?, callback: (Result<ByteArray?>) -> Unit) {
|
||||
override fun callFlutterEchoNullableUint8List(
|
||||
aList: ByteArray?,
|
||||
callback: (Result<ByteArray?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoNullableUint8List(aList) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableList(aList: List<Any?>?, callback: (Result<List<Any?>?>) -> Unit) {
|
||||
override fun callFlutterEchoNullableList(
|
||||
aList: List<Any?>?,
|
||||
callback: (Result<List<Any?>?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoNullableList(aList) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableMap(aMap: Map<String?, Any?>?, callback: (Result<Map<String?, Any?>?>) -> Unit) {
|
||||
override fun callFlutterEchoNullableMap(
|
||||
aMap: Map<String?, Any?>?,
|
||||
callback: (Result<Map<String?, Any?>?>) -> Unit
|
||||
) {
|
||||
flutterApi!!.echoNullableMap(aMap) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
override fun callFlutterEchoNullableEnum(anEnum: AnEnum?, callback: (Result<AnEnum?>) -> Unit) {
|
||||
flutterApi!!.echoNullableEnum(anEnum) { echo -> callback(echo) }
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,95 +7,96 @@ package com.example.test_plugin
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
internal class AllDatatypesTest : TestCase() {
|
||||
fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?) {
|
||||
assertEquals(firstTypes == null, secondTypes == null)
|
||||
if (firstTypes == null || secondTypes == null) {
|
||||
return
|
||||
}
|
||||
assertEquals(firstTypes.aBool, secondTypes.aBool)
|
||||
assertEquals(firstTypes.anInt, secondTypes.anInt)
|
||||
assertEquals(firstTypes.anInt64, secondTypes.anInt64)
|
||||
assertEquals(firstTypes.aDouble, secondTypes.aDouble)
|
||||
assertEquals(firstTypes.aString, secondTypes.aString)
|
||||
assertTrue(firstTypes.aByteArray.contentEquals(secondTypes.aByteArray))
|
||||
assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray))
|
||||
assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray))
|
||||
assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray))
|
||||
assertEquals(firstTypes.aList, secondTypes.aList)
|
||||
assertEquals(firstTypes.aMap, secondTypes.aMap)
|
||||
assertEquals(firstTypes.anEnum, secondTypes.anEnum)
|
||||
assertEquals(firstTypes.anObject, secondTypes.anObject)
|
||||
}
|
||||
|
||||
internal class AllDatatypesTest: TestCase() {
|
||||
fun compareAllTypes(firstTypes: AllTypes?, secondTypes: AllTypes?) {
|
||||
assertEquals(firstTypes == null, secondTypes == null)
|
||||
if (firstTypes == null || secondTypes == null) {
|
||||
return
|
||||
fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?) {
|
||||
assertEquals(firstTypes == null, secondTypes == null)
|
||||
if (firstTypes == null || secondTypes == null) {
|
||||
return
|
||||
}
|
||||
assertEquals(firstTypes.aNullableBool, secondTypes.aNullableBool)
|
||||
assertEquals(firstTypes.aNullableInt, secondTypes.aNullableInt)
|
||||
assertEquals(firstTypes.aNullableDouble, secondTypes.aNullableDouble)
|
||||
assertEquals(firstTypes.aNullableString, secondTypes.aNullableString)
|
||||
assertTrue(firstTypes.aNullableByteArray.contentEquals(secondTypes.aNullableByteArray))
|
||||
assertTrue(firstTypes.aNullable4ByteArray.contentEquals(secondTypes.aNullable4ByteArray))
|
||||
assertTrue(firstTypes.aNullable8ByteArray.contentEquals(secondTypes.aNullable8ByteArray))
|
||||
assertTrue(firstTypes.aNullableFloatArray.contentEquals(secondTypes.aNullableFloatArray))
|
||||
assertEquals(firstTypes.aNullableList, secondTypes.aNullableList)
|
||||
assertEquals(firstTypes.aNullableMap, secondTypes.aNullableMap)
|
||||
assertEquals(firstTypes.nullableMapWithObject, secondTypes.nullableMapWithObject)
|
||||
assertEquals(firstTypes.aNullableObject, secondTypes.aNullableObject)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNullValues() {
|
||||
val everything = AllNullableTypes()
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
assertEquals(firstTypes.aBool, secondTypes.aBool)
|
||||
assertEquals(firstTypes.anInt, secondTypes.anInt)
|
||||
assertEquals(firstTypes.anInt64, secondTypes.anInt64)
|
||||
assertEquals(firstTypes.aDouble, secondTypes.aDouble)
|
||||
assertEquals(firstTypes.aString, secondTypes.aString)
|
||||
assertTrue(firstTypes.aByteArray.contentEquals(secondTypes.aByteArray))
|
||||
assertTrue(firstTypes.a4ByteArray.contentEquals(secondTypes.a4ByteArray))
|
||||
assertTrue(firstTypes.a8ByteArray.contentEquals(secondTypes.a8ByteArray))
|
||||
assertTrue(firstTypes.aFloatArray.contentEquals(secondTypes.aFloatArray))
|
||||
assertEquals(firstTypes.aList, secondTypes.aList)
|
||||
assertEquals(firstTypes.aMap, secondTypes.aMap)
|
||||
assertEquals(firstTypes.anEnum, secondTypes.anEnum)
|
||||
assertEquals(firstTypes.anObject, secondTypes.anObject)
|
||||
|
||||
var didCall = false
|
||||
api.echoAllNullableTypes(everything) {
|
||||
didCall = true
|
||||
val output =
|
||||
(it.getOrNull())?.let {
|
||||
assertNull(it.aNullableBool)
|
||||
assertNull(it.aNullableInt)
|
||||
assertNull(it.aNullableDouble)
|
||||
assertNull(it.aNullableString)
|
||||
assertNull(it.aNullableByteArray)
|
||||
assertNull(it.aNullable4ByteArray)
|
||||
assertNull(it.aNullable8ByteArray)
|
||||
assertNull(it.aNullableFloatArray)
|
||||
assertNull(it.aNullableList)
|
||||
assertNull(it.aNullableMap)
|
||||
assertNull(it.nullableMapWithObject)
|
||||
}
|
||||
assertNotNull(output)
|
||||
}
|
||||
|
||||
fun compareAllNullableTypes(firstTypes: AllNullableTypes?, secondTypes: AllNullableTypes?) {
|
||||
assertEquals(firstTypes == null, secondTypes == null)
|
||||
if (firstTypes == null || secondTypes == null) {
|
||||
return
|
||||
}
|
||||
assertEquals(firstTypes.aNullableBool, secondTypes.aNullableBool)
|
||||
assertEquals(firstTypes.aNullableInt, secondTypes.aNullableInt)
|
||||
assertEquals(firstTypes.aNullableDouble, secondTypes.aNullableDouble)
|
||||
assertEquals(firstTypes.aNullableString, secondTypes.aNullableString)
|
||||
assertTrue(firstTypes.aNullableByteArray.contentEquals(secondTypes.aNullableByteArray))
|
||||
assertTrue(firstTypes.aNullable4ByteArray.contentEquals(secondTypes.aNullable4ByteArray))
|
||||
assertTrue(firstTypes.aNullable8ByteArray.contentEquals(secondTypes.aNullable8ByteArray))
|
||||
assertTrue(firstTypes.aNullableFloatArray.contentEquals(secondTypes.aNullableFloatArray))
|
||||
assertEquals(firstTypes.aNullableList, secondTypes.aNullableList)
|
||||
assertEquals(firstTypes.aNullableMap, secondTypes.aNullableMap)
|
||||
assertEquals(firstTypes.nullableMapWithObject, secondTypes.nullableMapWithObject)
|
||||
assertEquals(firstTypes.aNullableObject, secondTypes.aNullableObject)
|
||||
}
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNullValues() {
|
||||
val everything = AllNullableTypes()
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.echoAllNullableTypes(everything) {
|
||||
didCall = true
|
||||
val output = (it.getOrNull())?.let {
|
||||
assertNull(it.aNullableBool)
|
||||
assertNull(it.aNullableInt)
|
||||
assertNull(it.aNullableDouble)
|
||||
assertNull(it.aNullableString)
|
||||
assertNull(it.aNullableByteArray)
|
||||
assertNull(it.aNullable4ByteArray)
|
||||
assertNull(it.aNullable8ByteArray)
|
||||
assertNull(it.aNullableFloatArray)
|
||||
assertNull(it.aNullableList)
|
||||
assertNull(it.aNullableMap)
|
||||
assertNull(it.nullableMapWithObject)
|
||||
}
|
||||
assertNotNull(output)
|
||||
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testHasValues() {
|
||||
val everything = AllNullableTypes(
|
||||
@Test
|
||||
fun testHasValues() {
|
||||
val everything =
|
||||
AllNullableTypes(
|
||||
aNullableBool = false,
|
||||
aNullableInt = 1234L,
|
||||
aNullableDouble = 2.0,
|
||||
@ -109,41 +110,59 @@ internal class AllDatatypesTest: TestCase() {
|
||||
nullableMapWithObject = mapOf("hello" to 1234),
|
||||
aNullableObject = 0,
|
||||
)
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.echoAllNullableTypes(everything) {
|
||||
didCall = true
|
||||
compareAllNullableTypes(everything, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.echoAllNullableTypes(everything) {
|
||||
didCall = true
|
||||
compareAllNullableTypes(everything, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIntegerToLong() {
|
||||
val everything = AllNullableTypes(aNullableInt = 123L)
|
||||
val list = everything.toList()
|
||||
assertNotNull(list)
|
||||
assertNull(list.first())
|
||||
assertNotNull(list[1])
|
||||
assertTrue(list[1] == 123L)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val list2 = listOf(null, 123, null, null, null, null, null, null, null, null, null, null, null, null, null, null)
|
||||
val everything2 = AllNullableTypes.fromList(list2)
|
||||
@Test
|
||||
fun testIntegerToLong() {
|
||||
val everything = AllNullableTypes(aNullableInt = 123L)
|
||||
val list = everything.toList()
|
||||
assertNotNull(list)
|
||||
assertNull(list.first())
|
||||
assertNotNull(list[1])
|
||||
assertTrue(list[1] == 123L)
|
||||
|
||||
assertEquals(everything.aNullableInt, everything2.aNullableInt)
|
||||
}
|
||||
val list2 =
|
||||
listOf(
|
||||
null,
|
||||
123,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null)
|
||||
val everything2 = AllNullableTypes.fromList(list2)
|
||||
|
||||
assertEquals(everything.aNullableInt, everything2.aNullableInt)
|
||||
}
|
||||
}
|
||||
|
@ -9,116 +9,115 @@ import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import io.mockk.verify
|
||||
import java.nio.ByteBuffer
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
internal class AsyncHandlersTest : TestCase() {
|
||||
@Test
|
||||
fun testAsyncHost2Flutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
|
||||
internal class AsyncHandlersTest: TestCase() {
|
||||
@Test
|
||||
fun testAsyncHost2Flutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterIntegrationCoreApi(binaryMessenger)
|
||||
val value = "Test"
|
||||
|
||||
val value = "Test"
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val replyData = codec.encodeMessage(listOf(value))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = FlutterIntegrationCoreApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val replyData = codec.encodeMessage(listOf(value))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.echoAsyncString(value) {
|
||||
didCall = true
|
||||
assertEquals(it.getOrNull(), value)
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
|
||||
verify {
|
||||
binaryMessenger.send(
|
||||
"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString",
|
||||
any(),
|
||||
any()
|
||||
)
|
||||
}
|
||||
var didCall = false
|
||||
api.echoAsyncString(value) {
|
||||
didCall = true
|
||||
assertEquals(it.getOrNull(), value)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAsyncFlutter2HostEcho() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<HostSmallApi>()
|
||||
assertTrue(didCall)
|
||||
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
verify {
|
||||
binaryMessenger.send(
|
||||
"dev.flutter.pigeon.pigeon_integration_tests.FlutterIntegrationCoreApi.echoAsyncString",
|
||||
any(),
|
||||
any())
|
||||
}
|
||||
}
|
||||
|
||||
val input = "Test"
|
||||
val output = input
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo"
|
||||
@Test
|
||||
fun testAsyncFlutter2HostEcho() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<HostSmallApi>()
|
||||
|
||||
every {
|
||||
binaryMessenger.setMessageHandler("dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid", any())
|
||||
} returns Unit
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.echo(any(), any()) } answers {
|
||||
val callback = arg<(Result<String>) -> Unit>(1)
|
||||
callback(Result.success(output))
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
val input = "Test"
|
||||
val output = input
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo"
|
||||
|
||||
every {
|
||||
binaryMessenger.setMessageHandler(
|
||||
"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid", any())
|
||||
} returns Unit
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.echo(any(), any()) } answers
|
||||
{
|
||||
val callback = arg<(Result<String>) -> Unit>(1)
|
||||
callback(Result.success(output))
|
||||
}
|
||||
|
||||
HostSmallApi.setUp(binaryMessenger, api)
|
||||
HostSmallApi.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = HostSmallApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
assertNotNull(it)
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as MutableList<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(output, wrapped.first())
|
||||
}
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.echo(input, any()) }
|
||||
val codec = HostSmallApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
assertNotNull(it)
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as MutableList<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(output, wrapped.first()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun asyncFlutter2HostVoidVoid() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<HostSmallApi>()
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.echo(input, any()) }
|
||||
}
|
||||
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
@Test
|
||||
fun asyncFlutter2HostVoidVoid() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<HostSmallApi>()
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every {
|
||||
binaryMessenger.setMessageHandler("dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo", any())
|
||||
} returns Unit
|
||||
every { api.voidVoid(any()) } answers {
|
||||
val callback = arg<() -> Unit>(0)
|
||||
callback()
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid"
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every {
|
||||
binaryMessenger.setMessageHandler(
|
||||
"dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.echo", any())
|
||||
} returns Unit
|
||||
every { api.voidVoid(any()) } answers
|
||||
{
|
||||
val callback = arg<() -> Unit>(0)
|
||||
callback()
|
||||
}
|
||||
|
||||
HostSmallApi.setUp(binaryMessenger, api)
|
||||
HostSmallApi.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = HostSmallApi.codec
|
||||
val message = codec.encodeMessage(null)
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as MutableList<Any>?
|
||||
assertNull(wrapped)
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.voidVoid(any()) }
|
||||
val codec = HostSmallApi.codec
|
||||
val message = codec.encodeMessage(null)
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as MutableList<Any>?
|
||||
assertNull(wrapped)
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.voidVoid(any()) }
|
||||
}
|
||||
}
|
||||
|
@ -6,33 +6,23 @@ package com.example.test_plugin
|
||||
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.flutter.plugin.common.MessageCodec
|
||||
import io.flutter.plugin.common.StandardMessageCodec
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
|
||||
internal class EchoBinaryMessenger(private val codec: MessageCodec<Any?>) : BinaryMessenger {
|
||||
override fun send(channel: String, message: ByteBuffer?) {
|
||||
// Method not implemented because this messenger is just for echoing.
|
||||
}
|
||||
|
||||
internal class EchoBinaryMessenger(private val codec: MessageCodec<Any?>): BinaryMessenger {
|
||||
override fun send(channel: String, message: ByteBuffer?) {
|
||||
// Method not implemented because this messenger is just for echoing.
|
||||
}
|
||||
|
||||
override fun send(
|
||||
channel: String,
|
||||
message: ByteBuffer?,
|
||||
callback: BinaryMessenger.BinaryReply?
|
||||
) {
|
||||
message?.rewind()
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
callback?.reply(replyData)
|
||||
}
|
||||
|
||||
override fun setMessageHandler(
|
||||
channel: String,
|
||||
handler: BinaryMessenger.BinaryMessageHandler?
|
||||
) {
|
||||
// Method not implemented because this messenger is just for echoing.
|
||||
}
|
||||
override fun send(channel: String, message: ByteBuffer?, callback: BinaryMessenger.BinaryReply?) {
|
||||
message?.rewind()
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
callback?.reply(replyData)
|
||||
}
|
||||
|
||||
override fun setMessageHandler(channel: String, handler: BinaryMessenger.BinaryMessageHandler?) {
|
||||
// Method not implemented because this messenger is just for echoing.
|
||||
}
|
||||
}
|
||||
|
@ -9,69 +9,69 @@ import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import io.mockk.verify
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
internal class EnumTest: TestCase() {
|
||||
@Test
|
||||
fun testEchoHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<EnumApi2Host>()
|
||||
internal class EnumTest : TestCase() {
|
||||
@Test
|
||||
fun testEchoHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<EnumApi2Host>()
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo"
|
||||
val input = DataWithEnum(EnumState.SUCCESS)
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.EnumApi2Host.echo"
|
||||
val input = DataWithEnum(EnumState.SUCCESS)
|
||||
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.echo(any()) } returnsArgument 0
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.echo(any()) } returnsArgument 0
|
||||
|
||||
EnumApi2Host.setUp(binaryMessenger, api)
|
||||
EnumApi2Host.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = EnumApi2Host.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertNotNull(wrapped[0])
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.echo(input) }
|
||||
val codec = EnumApi2Host.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertNotNull(wrapped[0])
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testEchoFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = EnumApi2Flutter(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.echo(input) }
|
||||
}
|
||||
|
||||
val input = DataWithEnum(EnumState.SUCCESS)
|
||||
@Test
|
||||
fun testEchoFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = EnumApi2Flutter(binaryMessenger)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = EnumApi2Flutter.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
val input = DataWithEnum(EnumState.SUCCESS)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = EnumApi2Flutter.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.echo(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.echo(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
}
|
||||
|
@ -7,37 +7,38 @@ package com.example.test_plugin
|
||||
import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
class ListTest: TestCase() {
|
||||
@Test
|
||||
fun testListInList() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterSmallApi(binaryMessenger)
|
||||
class ListTest : TestCase() {
|
||||
@Test
|
||||
fun testListInList() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = FlutterSmallApi(binaryMessenger)
|
||||
|
||||
val inside = TestMessage(listOf(1, 2, 3))
|
||||
val input = TestMessage(listOf(inside))
|
||||
val inside = TestMessage(listOf(1, 2, 3))
|
||||
val input = TestMessage(listOf(inside))
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = FlutterSmallApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = FlutterSmallApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val replyData = codec.encodeMessage(args)
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.echoWrappedList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.echoWrappedList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
}
|
||||
|
@ -8,69 +8,67 @@ import io.flutter.plugin.common.BinaryMessenger
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.slot
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
class MultipleArityTests: TestCase() {
|
||||
@Test
|
||||
fun testSimpleHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<MultipleArityHostApi>()
|
||||
class MultipleArityTests : TestCase() {
|
||||
@Test
|
||||
fun testSimpleHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = mockk<MultipleArityHostApi>()
|
||||
|
||||
val inputX = 10L
|
||||
val inputY = 5L
|
||||
val inputX = 10L
|
||||
val inputY = 5L
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.MultipleArityHostApi.subtract"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.subtract(any(), any()) } answers { firstArg<Long>() - secondArg<Long>() }
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.subtract(any(), any()) } answers { firstArg<Long>() - secondArg<Long>() }
|
||||
|
||||
MultipleArityHostApi.setUp(binaryMessenger, api)
|
||||
MultipleArityHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = MultipleArityHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(inputX, inputY))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(inputX - inputY, wrapped[0])
|
||||
}
|
||||
val codec = MultipleArityHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(inputX, inputY))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(inputX - inputY, wrapped[0]) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = MultipleArityFlutterApi(binaryMessenger)
|
||||
|
||||
val inputX = 10L
|
||||
val inputY = 5L
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = MultipleArityFlutterApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val argX = args[0] as Long
|
||||
val argY = args[1] as Long
|
||||
val replyData = codec.encodeMessage(listOf(argX - argY))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.subtract(inputX, inputY) {
|
||||
didCall = true
|
||||
assertEquals(inputX - inputY, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSimpleFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = MultipleArityFlutterApi(binaryMessenger)
|
||||
|
||||
val inputX = 10L
|
||||
val inputY = 5L
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = MultipleArityFlutterApi.codec
|
||||
val message = arg<ByteBuffer>(1)
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
message.position(0)
|
||||
val args = codec.decodeMessage(message) as ArrayList<*>
|
||||
val argX = args[0] as Long
|
||||
val argY = args[1] as Long
|
||||
val replyData = codec.encodeMessage(listOf(argX - argY))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.subtract(inputX, inputY) {
|
||||
didCall = true
|
||||
assertEquals(inputX - inputY, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
assertTrue(didCall)
|
||||
}
|
||||
}
|
||||
|
@ -7,10 +7,10 @@ package com.example.test_plugin
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
class NonNullFieldsTests: TestCase() {
|
||||
@Test
|
||||
fun testMake() {
|
||||
val request = NonNullFieldSearchRequest("hello")
|
||||
assertEquals("hello", request.query)
|
||||
}
|
||||
class NonNullFieldsTests : TestCase() {
|
||||
@Test
|
||||
fun testMake() {
|
||||
val request = NonNullFieldSearchRequest("hello")
|
||||
assertEquals("hello", request.query)
|
||||
}
|
||||
}
|
||||
|
@ -12,60 +12,58 @@ import io.mockk.verify
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
|
||||
class NullableReturnsTest: TestCase() {
|
||||
@Test
|
||||
fun testNullableParameterHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<NullableReturnHostApi>(relaxed = true)
|
||||
class NullableReturnsTest : TestCase() {
|
||||
@Test
|
||||
fun testNullableParameterHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<NullableReturnHostApi>(relaxed = true)
|
||||
|
||||
val output = 1L
|
||||
val output = 1L
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.NullableReturnHostApi.doit"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.doit() } returns output
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.doit() } returns output
|
||||
|
||||
NullableReturnHostApi.setUp(binaryMessenger, api)
|
||||
NullableReturnHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(null)
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(output, wrapped[0])
|
||||
}
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.doit() }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(null)
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(output, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNullableParameterFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = NullableReturnFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.doit() }
|
||||
}
|
||||
|
||||
val output = 12L
|
||||
@Test
|
||||
fun testNullableParameterFlutter() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>()
|
||||
val api = NullableReturnFlutterApi(binaryMessenger)
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers {
|
||||
val codec = NullableReturnFlutterApi.codec
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
val replyData = codec.encodeMessage(listOf(output))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
val output = 12L
|
||||
|
||||
every { binaryMessenger.send(any(), any(), any()) } answers
|
||||
{
|
||||
val codec = NullableReturnFlutterApi.codec
|
||||
val reply = arg<BinaryMessenger.BinaryReply>(2)
|
||||
val replyData = codec.encodeMessage(listOf(output))
|
||||
replyData?.position(0)
|
||||
reply.reply(replyData)
|
||||
}
|
||||
|
||||
var didCall = false
|
||||
api.doit {
|
||||
didCall = true
|
||||
assertEquals(output, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.doit {
|
||||
didCall = true
|
||||
assertEquals(output, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
}
|
||||
|
@ -11,424 +11,394 @@ import io.mockk.slot
|
||||
import io.mockk.verify
|
||||
import junit.framework.TestCase
|
||||
import org.junit.Test
|
||||
import java.nio.ByteBuffer
|
||||
import java.util.ArrayList
|
||||
|
||||
class PrimitiveTest: TestCase() {
|
||||
@Test
|
||||
fun testIntPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
class PrimitiveTest : TestCase() {
|
||||
@Test
|
||||
fun testIntPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val input = 1
|
||||
val input = 1
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.anInt(any()) } returnsArgument 0
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.anInt(any()) } returnsArgument 0
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input.toLong(), wrapped[0])
|
||||
}
|
||||
}
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.anInt(input.toLong()) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input.toLong(), wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIntPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.anInt(input.toLong()) }
|
||||
}
|
||||
|
||||
val input = 1L
|
||||
@Test
|
||||
fun testIntPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.anInt(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = 1L
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.anInt(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoolPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = true
|
||||
@Test
|
||||
fun testBoolPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBool"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = true
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aBool(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBool"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aBool(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aBool(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoolPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aBool(input) }
|
||||
}
|
||||
|
||||
val input = true
|
||||
@Test
|
||||
fun testBoolPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aBool(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = true
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aBool(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = "Hello"
|
||||
@Test
|
||||
fun testStringPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aString"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = "Hello"
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aString(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aString"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aString(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aString(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoublePrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aString(input) }
|
||||
}
|
||||
|
||||
val input = 1.0
|
||||
@Test
|
||||
fun testDoublePrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aDouble"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = 1.0
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aDouble(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aDouble"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aDouble(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aDouble(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDoublePrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aDouble(input) }
|
||||
}
|
||||
|
||||
val input = 1.0
|
||||
@Test
|
||||
fun testDoublePrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aDouble(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = 1.0
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aDouble(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = mapOf<Any, Any?>("a" to 1, "b" to 2)
|
||||
@Test
|
||||
fun testMapPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aMap"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = mapOf<Any, Any?>("a" to 1, "b" to 2)
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aMap(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aMap"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aMap(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aMap(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMapPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aMap(input) }
|
||||
}
|
||||
|
||||
val input = mapOf<Any, Any?>("a" to 1, "b" to 2)
|
||||
@Test
|
||||
fun testMapPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aMap(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = mapOf<Any, Any?>("a" to 1, "b" to 2)
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aMap(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = listOf(1, 2, 3)
|
||||
@Test
|
||||
fun testListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aList"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = listOf(1, 2, 3)
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aList(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aList"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aList(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aList(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aList(input) }
|
||||
}
|
||||
|
||||
val input = listOf(1, 2, 3)
|
||||
@Test
|
||||
fun testListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = listOf(1, 2, 3)
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInt32ListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = intArrayOf(1, 2, 3)
|
||||
@Test
|
||||
fun testInt32ListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt32List"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = intArrayOf(1, 2, 3)
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.anInt32List(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.anInt32List"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.anInt32List(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertTrue(input.contentEquals(wrapped[0] as IntArray))
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.anInt32List(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertTrue(input.contentEquals(wrapped[0] as IntArray)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testInt32ListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.anInt32List(input) }
|
||||
}
|
||||
|
||||
val input = intArrayOf(1, 2, 3)
|
||||
@Test
|
||||
fun testInt32ListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.anInt32List(input) {
|
||||
didCall = true
|
||||
assertTrue(input.contentEquals(it.getOrNull()))
|
||||
}
|
||||
val input = intArrayOf(1, 2, 3)
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.anInt32List(input) {
|
||||
didCall = true
|
||||
assertTrue(input.contentEquals(it.getOrNull()))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoolListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = listOf(true, false, true)
|
||||
@Test
|
||||
fun testBoolListPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = listOf(true, false, true)
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aBoolList(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aBoolList"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aBoolList(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aBoolList(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testBoolListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aBoolList(input) }
|
||||
}
|
||||
|
||||
val input = listOf(true, false, true)
|
||||
@Test
|
||||
fun testBoolListPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aBoolList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = listOf(true, false, true)
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aBoolList(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringIntMapPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
assertTrue(didCall)
|
||||
}
|
||||
|
||||
val input = mapOf<String?, Long?>("a" to 1, "b" to 2)
|
||||
@Test
|
||||
fun testStringIntMapPrimitiveHost() {
|
||||
val binaryMessenger = mockk<BinaryMessenger>(relaxed = true)
|
||||
val api = mockk<PrimitiveHostApi>(relaxed = true)
|
||||
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
val input = mapOf<String?, Long?>("a" to 1, "b" to 2)
|
||||
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aStringIntMap(any()) } returnsArgument 0
|
||||
val channelName = "dev.flutter.pigeon.pigeon_integration_tests.PrimitiveHostApi.aStringIntMap"
|
||||
val handlerSlot = slot<BinaryMessenger.BinaryMessageHandler>()
|
||||
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
every { binaryMessenger.setMessageHandler(channelName, capture(handlerSlot)) } returns Unit
|
||||
every { api.aStringIntMap(any()) } returnsArgument 0
|
||||
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let {
|
||||
assertEquals(input, wrapped[0])
|
||||
}
|
||||
}
|
||||
PrimitiveHostApi.setUp(binaryMessenger, api)
|
||||
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aStringIntMap(input) }
|
||||
val codec = PrimitiveHostApi.codec
|
||||
val message = codec.encodeMessage(listOf(input))
|
||||
message?.rewind()
|
||||
handlerSlot.captured.onMessage(message) {
|
||||
it?.rewind()
|
||||
@Suppress("UNCHECKED_CAST") val wrapped = codec.decodeMessage(it) as List<Any>?
|
||||
assertNotNull(wrapped)
|
||||
wrapped?.let { assertEquals(input, wrapped[0]) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringIntMapPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
verify { binaryMessenger.setMessageHandler(channelName, handlerSlot.captured) }
|
||||
verify { api.aStringIntMap(input) }
|
||||
}
|
||||
|
||||
val input = mapOf<String?, Long?>("a" to 1, "b" to 2)
|
||||
@Test
|
||||
fun testStringIntMapPrimitiveFlutter() {
|
||||
val binaryMessenger = EchoBinaryMessenger(MultipleArityFlutterApi.codec)
|
||||
val api = PrimitiveFlutterApi(binaryMessenger)
|
||||
|
||||
var didCall = false
|
||||
api.aStringIntMap(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
val input = mapOf<String?, Long?>("a" to 1, "b" to 2)
|
||||
|
||||
assertTrue(didCall)
|
||||
var didCall = false
|
||||
api.aStringIntMap(input) {
|
||||
didCall = true
|
||||
assertEquals(input, it.getOrNull())
|
||||
}
|
||||
|
||||
assertTrue(didCall)
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,4 @@ package com.example.test_plugin_example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package dev.flutter.plaform_example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,5 +5,4 @@ package dev.flutter.rfw.examples.hello
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,5 +5,4 @@ package dev.flutter.rfw.examples.local
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -5,5 +5,4 @@ package dev.flutter.rfw.examples.remote
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -6,5 +6,4 @@ package com.example.example
|
||||
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
|
||||
class MainActivity: FlutterActivity() {
|
||||
}
|
||||
class MainActivity : FlutterActivity() {}
|
||||
|
@ -32,9 +32,12 @@ const int _exitJavaFormatFailed = 5;
|
||||
const int _exitGitFailed = 6;
|
||||
const int _exitDependencyMissing = 7;
|
||||
const int _exitSwiftFormatFailed = 8;
|
||||
const int _exitKotlinFormatFailed = 9;
|
||||
|
||||
final Uri _googleFormatterUrl = Uri.https('github.com',
|
||||
final Uri _javaFormatterUrl = Uri.https('github.com',
|
||||
'/google/google-java-format/releases/download/google-java-format-1.3/google-java-format-1.3-all-deps.jar');
|
||||
final Uri _kotlinFormatterUrl = Uri.https('maven.org',
|
||||
'/maven2/com/facebook/ktfmt/0.46/ktfmt-0.46-jar-with-dependencies.jar');
|
||||
|
||||
/// A command to format all package code.
|
||||
class FormatCommand extends PackageCommand {
|
||||
@ -62,14 +65,15 @@ class FormatCommand extends PackageCommand {
|
||||
|
||||
@override
|
||||
final String description =
|
||||
'Formats the code of all packages (Java, Objective-C, C++, Dart, and '
|
||||
'optionally Swift).\n\n'
|
||||
'This command requires "git", "flutter" and "clang-format" v5 to be in '
|
||||
'your path.';
|
||||
'Formats the code of all packages (C++, Dart, Java, Kotlin, Objective-C, '
|
||||
'and optionally Swift).\n\n'
|
||||
'This command requires "git", "flutter", "java", and "clang-format" v5 '
|
||||
'to be in your path.';
|
||||
|
||||
@override
|
||||
Future<void> run() async {
|
||||
final String googleFormatterPath = await _getGoogleFormatterPath();
|
||||
final String javaFormatterPath = await _getJavaFormatterPath();
|
||||
final String kotlinFormatterPath = await _getKotlinFormatterPath();
|
||||
|
||||
// This class is not based on PackageLoopingCommand because running the
|
||||
// formatters separately for each package is an order of magnitude slower,
|
||||
@ -77,7 +81,8 @@ class FormatCommand extends PackageCommand {
|
||||
final Iterable<String> files =
|
||||
await _getFilteredFilePaths(getFiles(), relativeTo: packagesDir);
|
||||
await _formatDart(files);
|
||||
await _formatJava(files, googleFormatterPath);
|
||||
await _formatJava(files, javaFormatterPath);
|
||||
await _formatKotlin(files, kotlinFormatterPath);
|
||||
await _formatCppAndObjectiveC(files);
|
||||
final String? swiftFormat = getNullableStringArg(_swiftFormatArg);
|
||||
if (swiftFormat != null) {
|
||||
@ -187,8 +192,7 @@ class FormatCommand extends PackageCommand {
|
||||
throw ToolExit(_exitDependencyMissing);
|
||||
}
|
||||
|
||||
Future<void> _formatJava(
|
||||
Iterable<String> files, String googleFormatterPath) async {
|
||||
Future<void> _formatJava(Iterable<String> files, String formatterPath) async {
|
||||
final Iterable<String> javaFiles =
|
||||
_getPathsWithExtensions(files, <String>{'.java'});
|
||||
if (javaFiles.isNotEmpty) {
|
||||
@ -202,7 +206,7 @@ class FormatCommand extends PackageCommand {
|
||||
|
||||
print('Formatting .java files...');
|
||||
final int exitCode = await _runBatched(
|
||||
java, <String>['-jar', googleFormatterPath, '--replace'],
|
||||
java, <String>['-jar', formatterPath, '--replace'],
|
||||
files: javaFiles);
|
||||
if (exitCode != 0) {
|
||||
printError('Failed to format Java files: exit code $exitCode.');
|
||||
@ -211,6 +215,30 @@ class FormatCommand extends PackageCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _formatKotlin(
|
||||
Iterable<String> files, String formatterPath) async {
|
||||
final Iterable<String> kotlinFiles =
|
||||
_getPathsWithExtensions(files, <String>{'.kt'});
|
||||
if (kotlinFiles.isNotEmpty) {
|
||||
final String java = getStringArg('java');
|
||||
if (!await _hasDependency(java)) {
|
||||
printError(
|
||||
'Unable to run "java". Make sure that it is in your path, or '
|
||||
'provide a full path with --java.');
|
||||
throw ToolExit(_exitDependencyMissing);
|
||||
}
|
||||
|
||||
print('Formatting .kt files...');
|
||||
final int exitCode = await _runBatched(
|
||||
java, <String>['-jar', formatterPath],
|
||||
files: kotlinFiles);
|
||||
if (exitCode != 0) {
|
||||
printError('Failed to format Kotlin files: exit code $exitCode.');
|
||||
throw ToolExit(_exitKotlinFormatFailed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _formatDart(Iterable<String> files) async {
|
||||
final Iterable<String> dartFiles =
|
||||
_getPathsWithExtensions(files, <String>{'.dart'});
|
||||
@ -283,7 +311,7 @@ class FormatCommand extends PackageCommand {
|
||||
(String filePath) => extensions.contains(path.extension(filePath)));
|
||||
}
|
||||
|
||||
Future<String> _getGoogleFormatterPath() async {
|
||||
Future<String> _getJavaFormatterPath() async {
|
||||
final String javaFormatterPath = path.join(
|
||||
path.dirname(path.fromUri(platform.script)),
|
||||
'google-java-format-1.3-all-deps.jar');
|
||||
@ -292,13 +320,29 @@ class FormatCommand extends PackageCommand {
|
||||
|
||||
if (!javaFormatterFile.existsSync()) {
|
||||
print('Downloading Google Java Format...');
|
||||
final http.Response response = await http.get(_googleFormatterUrl);
|
||||
final http.Response response = await http.get(_javaFormatterUrl);
|
||||
javaFormatterFile.writeAsBytesSync(response.bodyBytes);
|
||||
}
|
||||
|
||||
return javaFormatterPath;
|
||||
}
|
||||
|
||||
Future<String> _getKotlinFormatterPath() async {
|
||||
final String kotlinFormatterPath = path.join(
|
||||
path.dirname(path.fromUri(platform.script)),
|
||||
'ktfmt-0.46-jar-with-dependencies.jar');
|
||||
final File kotlinFormatterFile =
|
||||
packagesDir.fileSystem.file(kotlinFormatterPath);
|
||||
|
||||
if (!kotlinFormatterFile.existsSync()) {
|
||||
print('Downloading ktfmt...');
|
||||
final http.Response response = await http.get(_kotlinFormatterUrl);
|
||||
kotlinFormatterFile.writeAsBytesSync(response.bodyBytes);
|
||||
}
|
||||
|
||||
return kotlinFormatterPath;
|
||||
}
|
||||
|
||||
/// Returns true if [command] can be run successfully.
|
||||
Future<bool> _hasDependency(String command) async {
|
||||
// Some versions of Java accept both -version and --version, but some only
|
||||
|
@ -22,6 +22,7 @@ void main() {
|
||||
late FormatCommand analyzeCommand;
|
||||
late CommandRunner<void> runner;
|
||||
late String javaFormatPath;
|
||||
late String kotlinFormatPath;
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem();
|
||||
@ -34,12 +35,16 @@ void main() {
|
||||
platform: mockPlatform,
|
||||
);
|
||||
|
||||
// Create the java formatter file that the command checks for, to avoid
|
||||
// a download.
|
||||
// Create the Java and Kotlin formatter files that the command checks for,
|
||||
// to avoid a download.
|
||||
final p.Context path = analyzeCommand.path;
|
||||
javaFormatPath = path.join(path.dirname(path.fromUri(mockPlatform.script)),
|
||||
'google-java-format-1.3-all-deps.jar');
|
||||
fileSystem.file(javaFormatPath).createSync(recursive: true);
|
||||
kotlinFormatPath = path.join(
|
||||
path.dirname(path.fromUri(mockPlatform.script)),
|
||||
'ktfmt-0.46-jar-with-dependencies.jar');
|
||||
fileSystem.file(kotlinFormatPath).createSync(recursive: true);
|
||||
|
||||
runner = CommandRunner<void>('format_command', 'Test for format_command');
|
||||
runner.addCommand(analyzeCommand);
|
||||
@ -428,6 +433,62 @@ void main() {
|
||||
]));
|
||||
});
|
||||
|
||||
group('kotlin-format', () {
|
||||
test('formats .kt files', () async {
|
||||
const List<String> files = <String>[
|
||||
'android/src/main/kotlin/io/flutter/plugins/a_plugin/a.kt',
|
||||
'android/src/main/kotlin/io/flutter/plugins/a_plugin/b.kt',
|
||||
];
|
||||
final RepositoryPackage plugin = createFakePlugin(
|
||||
'a_plugin',
|
||||
packagesDir,
|
||||
extraFiles: files,
|
||||
);
|
||||
|
||||
await runCapturingPrint(runner, <String>['format']);
|
||||
|
||||
expect(
|
||||
processRunner.recordedCalls,
|
||||
orderedEquals(<ProcessCall>[
|
||||
const ProcessCall('java', <String>['-version'], null),
|
||||
ProcessCall(
|
||||
'java',
|
||||
<String>[
|
||||
'-jar',
|
||||
kotlinFormatPath,
|
||||
...getPackagesDirRelativePaths(plugin, files)
|
||||
],
|
||||
packagesDir.path),
|
||||
]));
|
||||
});
|
||||
|
||||
test('fails if Kotlin formatter fails', () async {
|
||||
const List<String> files = <String>[
|
||||
'android/src/main/kotlin/io/flutter/plugins/a_plugin/a.kt',
|
||||
'android/src/main/kotlin/io/flutter/plugins/a_plugin/b.kt',
|
||||
];
|
||||
createFakePlugin('a_plugin', packagesDir, extraFiles: files);
|
||||
|
||||
processRunner.mockProcessesForExecutable['java'] = <FakeProcessInfo>[
|
||||
FakeProcessInfo(
|
||||
MockProcess(), <String>['-version']), // check for working java
|
||||
FakeProcessInfo(MockProcess(exitCode: 1), <String>['-jar']), // format
|
||||
];
|
||||
Error? commandError;
|
||||
final List<String> output = await runCapturingPrint(
|
||||
runner, <String>['format'], errorHandler: (Error e) {
|
||||
commandError = e;
|
||||
});
|
||||
|
||||
expect(commandError, isA<ToolExit>());
|
||||
expect(
|
||||
output,
|
||||
containsAllInOrder(<Matcher>[
|
||||
contains('Failed to format Kotlin files: exit code 1.'),
|
||||
]));
|
||||
});
|
||||
});
|
||||
|
||||
group('swift-format', () {
|
||||
test('formats Swift if --swift-format flag is provided', () async {
|
||||
const List<String> files = <String>[
|
||||
|
Reference in New Issue
Block a user