[Interop][Test] Add tests for pointers and arrays
This commit is contained in:
committed by
Sergey Bogolepov
parent
47e505825e
commit
3bbcd38f0b
@@ -3473,6 +3473,10 @@ createInterop("cunion") {
|
|||||||
it.defFile 'interop/basics/cunion.def'
|
it.defFile 'interop/basics/cunion.def'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
createInterop("carrayPointers") {
|
||||||
|
it.defFile 'interop/basics/carrayPointers.def'
|
||||||
|
}
|
||||||
|
|
||||||
createInterop("auxiliaryCppSources") {
|
createInterop("auxiliaryCppSources") {
|
||||||
// We need to provide empty def file to create correct `KonanInteropTask`.
|
// We need to provide empty def file to create correct `KonanInteropTask`.
|
||||||
it.defFile 'interop/auxiliary_sources/auxiliaryCppSources.def'
|
it.defFile 'interop/auxiliary_sources/auxiliaryCppSources.def'
|
||||||
@@ -3728,6 +3732,12 @@ interopTest("interop_union") {
|
|||||||
source = "interop/basics/union.kt"
|
source = "interop/basics/union.kt"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interopTest("interop_array_pointers") {
|
||||||
|
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||||
|
interop = 'carrayPointers'
|
||||||
|
source = "interop/basics/arrayPointers.kt"
|
||||||
|
}
|
||||||
|
|
||||||
task interop_convert(type: KonanLocalTest) {
|
task interop_convert(type: KonanLocalTest) {
|
||||||
source = "codegen/intrinsics/interop_convert.kt"
|
source = "codegen/intrinsics/interop_convert.kt"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import carrayPointers.*
|
||||||
|
import kotlin.test.*
|
||||||
|
import kotlinx.cinterop.*
|
||||||
|
|
||||||
|
fun main() {
|
||||||
|
arrayPointer = globalArray
|
||||||
|
assertEquals(globalArray[0], arrayPointer!![0])
|
||||||
|
arrayPointer!![0] = 15
|
||||||
|
assertEquals(15, globalArray[0])
|
||||||
|
|
||||||
|
memScoped {
|
||||||
|
val struct = alloc<StructWithArrayPtr>()
|
||||||
|
struct.arrayPointer = globalArray
|
||||||
|
assertEquals(globalArray[0], struct.arrayPointer!![0])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
int (*arrayPointer)[1];
|
||||||
|
|
||||||
|
int globalArray[3] = {1, 2, 3};
|
||||||
|
|
||||||
|
struct StructWithArrayPtr {
|
||||||
|
int (*arrayPointer)[1];
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user