Files
kotlin-fork/kotlin-native/backend.native/tests/interop/basics/structs.kt
T
Stanislav Erokhin f624800b84 Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise
they would be ignored according .gitignore settings. Probably they
should be deleted from repo.

Interop/.idea/compiler.xml
Interop/.idea/gradle.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml
Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml
Interop/.idea/modules.xml
Interop/.idea/modules/Indexer/Indexer.iml
Interop/.idea/modules/Runtime/Runtime.iml
Interop/.idea/modules/StubGenerator/StubGenerator.iml
backend.native/backend.native.iml
backend.native/bc.frontend/bc.frontend.iml
backend.native/cli.bc/cli.bc.iml
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt
backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt
backend.native/tests/link/lib/foo.kt
backend.native/tests/link/lib/foo2.kt
backend.native/tests/teamcity-test.property
2020-10-27 21:00:28 +03:00

76 lines
1.8 KiB
Kotlin

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)
// Check null pointer because it has Nothing? type.
next = null
assertEquals(next, null)
assertEquals(e, E.R)
e = E.G
assertEquals(e, E.G)
assertEquals(K, nonStrict)
nonStrict = S
assertEquals(S, nonStrict)
assertEquals(arr[0], -51)
assertEquals(arr[1], -19)
arr[0] = 51
arr[1] = 19
assertEquals(arr[0], 51)
assertEquals(arr[1], 19)
assertEquals(true, b)
b = false
assertEquals(false, b)
// Check that subtyping via Nothing-returning functions does not break compiler.
assertFailsWith<NotImplementedError> {
ui = TODO()
t.i = TODO()
next = TODO()
e = TODO()
nonStrict = TODO()
b = TODO()
}
}
memScoped {
val packed = alloc<Packed>()
packed.i = -1
assertEquals(-1, packed.i)
packed.e = E.R
assertEquals(E.R, packed.e)
// Check that subtyping via Nothing-returning functions does not break compiler.
assertFailsWith<NotImplementedError> {
packed.i = TODO()
packed.e = TODO()
}
}
// Check that generics doesn't break anything.
checkEnumSubTyping(E.R)
checkIntSubTyping(630090)
}
fun <T : E> checkEnumSubTyping(e: T) = memScoped {
val s = alloc<Complex>()
s.e = e
}
fun <T : Int> checkIntSubTyping(x: T) = memScoped {
val s = alloc<Trivial>()
s.i = x
}