9f2558f640
To separate interop modules to different packages, .def files should be treated similarly to .kt files: 1) package directive should be prepended with test-specific synthetic package, or, if, absent, package directive with synthetic package should be added. 2) in .kt files, import directives and fully-qualified import from interop modules should be prepended with same test-specific synthetic package.
37 lines
907 B
Kotlin
Vendored
37 lines
907 B
Kotlin
Vendored
/*
|
|
* Copyright 2010-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
|
* that can be found in the LICENSE file.
|
|
*/
|
|
// TARGET_BACKEND: NATIVE
|
|
// MODULE: cinterop
|
|
// FILE: cstdlib.def
|
|
headers = stdlib.h
|
|
|
|
// MODULE: main(cinterop)
|
|
// FILE: main.kt
|
|
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
|
|
|
import cstdlib.*
|
|
import kotlinx.cinterop.*
|
|
import kotlin.test.*
|
|
|
|
fun box(): String {
|
|
val values = intArrayOf(14, 12, 9, 13, 8)
|
|
val count = values.size
|
|
|
|
qsort(values.refTo(0), count.convert(), IntVar.size.convert(), staticCFunction { a, b ->
|
|
val aValue = a!!.reinterpret<IntVar>()[0]
|
|
val bValue = b!!.reinterpret<IntVar>()[0]
|
|
|
|
(aValue - bValue)
|
|
})
|
|
|
|
assertEquals(8, values[0])
|
|
assertEquals(9, values[1])
|
|
assertEquals(12, values[2])
|
|
assertEquals(13, values[3])
|
|
assertEquals(14, values[4])
|
|
|
|
return "OK"
|
|
}
|