From dbc6d2b2ed6f1a3789728e99a93b9185d16c5def Mon Sep 17 00:00:00 2001 From: Darius Maitia Date: Thu, 19 Sep 2024 17:50:24 +0200 Subject: [PATCH] fix(scouting): error when providing config (#223) --- .../commonMain/kotlin/io/zenoh/jni/JNIScout.kt | 4 ++-- .../src/commonTest/kotlin/io/zenoh/ScoutTest.kt | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNIScout.kt b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNIScout.kt index f697c9c8a..c89684507 100644 --- a/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNIScout.kt +++ b/zenoh-kotlin/src/commonMain/kotlin/io/zenoh/jni/JNIScout.kt @@ -40,7 +40,7 @@ internal class JNIScout(private val ptr: Long) { callback.run(Hello(WhatAmI.fromInt(whatAmI2), ZenohID(id), locators)) } val binaryWhatAmI: Int = whatAmI.map { it.value }.reduce { acc, it -> acc or it } - val ptr = scoutViaJNI(binaryWhatAmI, scoutCallback, config?.jniConfig?.ptr) + val ptr = scoutViaJNI(binaryWhatAmI, scoutCallback, config?.jniConfig?.ptr ?: 0) Scout(receiver, JNIScout(ptr)) } @@ -48,7 +48,7 @@ internal class JNIScout(private val ptr: Long) { private external fun scoutViaJNI( whatAmI: Int, callback: JNIScoutCallback, - configPtr: Long?, + configPtr: Long, ): Long @Throws(Exception::class) diff --git a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ScoutTest.kt b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ScoutTest.kt index 622204719..cba34d9c9 100644 --- a/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ScoutTest.kt +++ b/zenoh-kotlin/src/commonTest/kotlin/io/zenoh/ScoutTest.kt @@ -29,17 +29,7 @@ class ScoutTest { @Test fun `scouting detects session test`() { - - val config = Config.fromJson(""" - { - "mode": "peer", - "connect": { - "endpoints": ["tcp/localhost:7450"] - }, - } - """.trimIndent()).getOrThrow() - - val session = Session.open(config).getOrThrow() + val session = Session.open(Config.default()).getOrThrow() var hello: Hello? = null Zenoh.scout(callback = { @@ -51,4 +41,9 @@ class ScoutTest { assertNotNull(hello) session.close() } + + @Test + fun `scouting loads config successfully test`() { + Zenoh.scout({}, config = Config.default()).getOrThrow() + } } \ No newline at end of file