backend/tests: add interop3 (uses callback)

This commit is contained in:
Svyatoslav Scherbina
2017-02-13 14:51:15 +07:00
committed by SvyatoslavScherbina
parent 9e716291c1
commit a85d30215d
2 changed files with 35 additions and 0 deletions
+6
View File
@@ -1359,6 +1359,12 @@ task interop2(type: RunInteropKonanTest) {
interop = 'cstdio'
}
task interop3(type: RunInteropKonanTest) {
goldValue = "8 9 12 13 14 \n"
source = "interop/basics/3.kt"
interop = 'cstdlib'
}
task interop_echo_server(type: RunInteropKonanTest) {
if (isLinux()) {
disabled = true
+29
View File
@@ -0,0 +1,29 @@
import kotlinx.cinterop.*
fun main(args: Array<String>) {
memScoped {
val count = 5
val values = allocArray<CInt32Var>(count)
values[0].value = 14
values[1].value = 12
values[2].value = 9
values[3].value = 13
values[4].value = 8
cstdlib.qsort(values[0].ptr, count.toLong(), CInt32Var.size, staticCFunction(::comparator))
for (i in 0 .. count - 1) {
print(values[i].value)
print(" ")
}
println()
}
}
private fun comparator(a: COpaquePointer?, b: COpaquePointer?): Int {
val aValue = a!!.reinterpret<CInt32Var>().pointed.value
val bValue = b!!.reinterpret<CInt32Var>().pointed.value
return (aValue - bValue)
}