[Interop] Add test for different types of struct fields
This commit is contained in:
committed by
Sergey Bogolepov
parent
07e6d9d0ad
commit
1618e19b8d
@@ -3345,6 +3345,10 @@ createInterop("cvalues") {
|
||||
it.defFile 'interop/basics/cvalues.def'
|
||||
}
|
||||
|
||||
createInterop("cstructs") {
|
||||
it.defFile 'interop/basics/cstructs.def'
|
||||
}
|
||||
|
||||
createInterop("ccallbacksAndVarargs") {
|
||||
it.defFile 'interop/basics/ccallbacksAndVarargs.def'
|
||||
}
|
||||
@@ -3520,6 +3524,12 @@ interopTest("interop_values") {
|
||||
interop = 'cvalues'
|
||||
}
|
||||
|
||||
interopTest("interop_structs") {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
source = "interop/basics/structs.kt"
|
||||
interop = 'cstructs'
|
||||
}
|
||||
|
||||
interopTest("interop_callbacksAndVarargs") {
|
||||
disabled = (project.testTarget == 'wasm32') // No interop for wasm yet.
|
||||
source = "interop/basics/callbacksAndVarargs.kt"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
---
|
||||
typedef float __attribute__ ((__vector_size__ (16))) KVector4f;
|
||||
|
||||
typedef struct {
|
||||
int i;
|
||||
} Trivial;
|
||||
|
||||
enum E {
|
||||
R, G, B
|
||||
};
|
||||
|
||||
struct Complex {
|
||||
unsigned int ui;
|
||||
KVector4f vec4f;
|
||||
Trivial t;
|
||||
struct Complex* next;
|
||||
enum E e;
|
||||
int arr[2];
|
||||
};
|
||||
|
||||
struct Complex produceComplex() {
|
||||
struct Complex complex;
|
||||
complex.ui = 128;
|
||||
KVector4f vec = { 1.0, 1.0, 1.0, 1.0 };
|
||||
complex.vec4f = vec;
|
||||
Trivial t = { .i = 1 };
|
||||
complex.t = t;
|
||||
complex.next = 0;
|
||||
complex.e = R;
|
||||
complex.arr[0] = -51;
|
||||
complex.arr[1] = -19;
|
||||
return complex;
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import cstructs.*
|
||||
import kotlinx.cinterop.*
|
||||
import kotlin.test.*
|
||||
|
||||
fun main() {
|
||||
produceComplex().useContents {
|
||||
assertEquals(ui, 128u)
|
||||
ui = 333u
|
||||
assertEquals(ui, 333u)
|
||||
|
||||
assertEquals(t.i, 1)
|
||||
t.i += 15
|
||||
assertEquals(t.i, 16)
|
||||
|
||||
assertEquals(next, null)
|
||||
next = this.ptr
|
||||
assertEquals(next, this.ptr)
|
||||
|
||||
assertEquals(vec4f, vectorOf(1.0f, 1.0f, 1.0f, 1.0f))
|
||||
vec4f = vectorOf(0.0f, 0.0f, 0.0f, 0.0f)
|
||||
assertEquals(vec4f, vectorOf(0.0f, 0.0f, 0.0f, 0.0f))
|
||||
|
||||
assertEquals(e, E.R)
|
||||
e = E.G
|
||||
assertEquals(e, E.G)
|
||||
|
||||
assertEquals(arr[0], -51)
|
||||
assertEquals(arr[1], -19)
|
||||
arr[0] = 51
|
||||
arr[1] = 19
|
||||
assertEquals(arr[0], 51)
|
||||
assertEquals(arr[1], 19)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user