Files
kotlin-fork/plugins/atomicfu/atomicfu-compiler/testData/nativeBox/atomics_basic/InitializationOrderTest.kt
T
mvicsokolova 9ff0e0b046 [atomicfu-K/N] Tests for K/N atomicfu-compiler-plugin
* `nativeTest` task now allows to provide compiler plugins that may be enabled during test compilation
* test sets for JVM and K/N backends are equal

KT-60800 describes all the issues with native tests that were solved in this commit.

Co-authored-by: Dmitriy Dolovov <Dmitriy.Dolovov@jetbrains.com>

Merge-request: KT-MR-11401
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
2023-08-16 09:41:29 +00:00

34 lines
894 B
Kotlin
Vendored

import kotlinx.atomicfu.*
import kotlin.test.*
private class AAA {
private val _counter = atomic(5L)
val counterValue: Long get() = _counter.value
val delegateCounterValue by _counter
val lateInitInt: AtomicInt
val intArr: AtomicIntArray
// test ensures that transformation does not change the order of initialization
init {
lateInitInt = atomic(10)
assertTrue(lateInitInt.compareAndSet(10, 100))
assertEquals(100, lateInitInt.value)
intArr = AtomicIntArray(10)
intArr[0].value = 10
assertTrue(intArr[0].compareAndSet(10, 100))
intArr[1].value = 20
}
init {
assertEquals(5L, _counter.value)
assertEquals(5L,counterValue)
assertEquals(5L, delegateCounterValue)
assertEquals(120, intArr[0].value + intArr[1].value)
}
}
@Test
fun box() {
val intClass = AAA()
}