diff --git a/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/CyclicStructC.kt b/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/CyclicStructC.kt new file mode 100644 index 000000000..b36218410 --- /dev/null +++ b/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/CyclicStructC.kt @@ -0,0 +1,43 @@ +package dev.diplomattest.somelib + +import com.sun.jna.Callback +import com.sun.jna.Library +import com.sun.jna.Native +import com.sun.jna.Pointer +import com.sun.jna.Structure + +internal interface CyclicStructCLib: Library { + fun CyclicStructC_cyclic_out(nativeStruct: CyclicStructCNative, write: Pointer): Unit +} + +internal class CyclicStructCNative: Structure(), Structure.ByValue { + @JvmField + internal var a: CyclicStructANative = CyclicStructANative(); + + // Define the fields of the struct + override fun getFieldOrder(): List { + return listOf("a") + } +} + +class CyclicStructC internal constructor ( + internal val nativeStruct: CyclicStructCNative) { + val a: CyclicStructA = CyclicStructA(nativeStruct.a) + + companion object { + internal val libClass: Class = CyclicStructCLib::class.java + internal val lib: CyclicStructCLib = Native.load("somelib", libClass) + val NATIVESIZE: Long = Native.getNativeSize(CyclicStructCNative::class.java).toLong() + } + + fun cyclicOut(): String { + val write = DW.lib.diplomat_buffer_write_create(0) + val returnVal = lib.CyclicStructC_cyclic_out(nativeStruct, write); + + val returnString = DW.writeToString(write) + return returnString + } + + +} +