Files
kotlin-fork/plugins/android-extensions/android-extensions-compiler/testData/parcel/box/kt26221.kt
T
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00

40 lines
1.0 KiB
Kotlin
Vendored

// IGNORE_BACKEND: JVM
// Fails with a VerifyError in Foo.writeToParcel
// WITH_STDLIB
@file:JvmName("TestKt")
package test
import kotlinx.android.parcel.*
import android.os.Parcel
import android.os.Parcelable
import android.util.SparseArray
@Parcelize
data class PInt(val x: Int) : Parcelable
@Parcelize
data class Foo(val values: SparseArray<SparseArray<Parcelable>>) : Parcelable
fun box() = parcelTest { parcel ->
val pint = PInt(0)
val sarray = SparseArray<Parcelable>()
sarray.put(0, pint)
val sarray2 = SparseArray<SparseArray<Parcelable>>()
sarray2.put(1, sarray)
val foo = Foo(sarray2)
foo.writeToParcel(parcel, 0)
val bytes = parcel.marshall()
parcel.unmarshall(bytes, 0, bytes.size)
parcel.setDataPosition(0)
val foo2 = readFromParcel<Foo>(parcel)
assert(foo2.values.size() == 1)
assert(foo2.values.get(1) != null) // SparseArray.contains was only added in Android R
assert(foo2.values.get(1).size() == 1)
assert(foo2.values.get(1).get(0) != null)
assert(foo2.values.get(1).get(0) == pint)
}