Parcelize: Add a test for sealed Parcelable classes
This commit is contained in:
committed by
Yan Zhulanow
parent
77fb0ddd32
commit
9bf3f105d9
+5
@@ -249,6 +249,11 @@ public class ParcelBoxTestGenerated extends AbstractParcelBoxTest {
|
|||||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/primitiveTypes.kt");
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/primitiveTypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("sealedClass.kt")
|
||||||
|
public void testSealedClass() throws Exception {
|
||||||
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/sealedClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/simple.kt");
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/simple.kt");
|
||||||
|
|||||||
+5
@@ -249,6 +249,11 @@ public class ParcelIrBoxTestGenerated extends AbstractParcelIrBoxTest {
|
|||||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/primitiveTypes.kt");
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/primitiveTypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("sealedClass.kt")
|
||||||
|
public void testSealedClass() throws Exception {
|
||||||
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/sealedClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("simple.kt")
|
@TestMetadata("simple.kt")
|
||||||
public void testSimple() throws Exception {
|
public void testSimple() throws Exception {
|
||||||
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/simple.kt");
|
runTest("plugins/android-extensions/android-extensions-compiler/testData/parcel/box/simple.kt");
|
||||||
|
|||||||
+33
@@ -0,0 +1,33 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.android.parcel.*
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
sealed class Foo : Parcelable {
|
||||||
|
@Parcelize
|
||||||
|
data class A(val x: Int) : Foo()
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class B (val x: String) : Foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class Bar(val a: Foo) : Parcelable
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
val first = Bar(Foo.B("OK"))
|
||||||
|
|
||||||
|
first.writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val second = readFromParcel<Bar>(parcel)
|
||||||
|
|
||||||
|
assert(first == second)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user