Parcelize: Add tests for obsolete issues
This commit is contained in:
committed by
Alexander Udalov
parent
eaf31b1ada
commit
0bbb36e765
@@ -0,0 +1,27 @@
|
|||||||
|
// See https://issuetracker.google.com/174827004
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Section<T : Parcelable>(val title: String, val faTitle: T) : Parcelable
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
val test = Section<Bundle>("title", Bundle())
|
||||||
|
test.writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val test2 = readFromParcel<Section<Bundle>>(parcel)
|
||||||
|
|
||||||
|
assert(test.title == test2.title)
|
||||||
|
assert(test2.faTitle.size() == 0)
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// See https://issuetracker.google.com/177856512
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
import android.util.SparseArray
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Data(val values: SparseArray<SparseArray<Parcelable>>) : Parcelable
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
val innerArray = SparseArray<Parcelable>()
|
||||||
|
innerArray.append(20, Bundle())
|
||||||
|
var array = SparseArray<SparseArray<Parcelable>>()
|
||||||
|
array.append(10, innerArray)
|
||||||
|
val first = Data(array)
|
||||||
|
|
||||||
|
first.writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val second = readFromParcel<Data>(parcel)
|
||||||
|
assert(second.values.size() == 1)
|
||||||
|
val secondInnerArray = second.values.get(10)
|
||||||
|
assert(secondInnerArray.size() == 1)
|
||||||
|
val innerBundle = secondInnerArray.get(20)
|
||||||
|
assert(innerBundle is Bundle)
|
||||||
|
assert((innerBundle as Bundle).size() == 0)
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// See https://issuetracker.google.com/178394826
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
parcel.writeParcelable(MyObject, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
parcel.readParcelable<MyObject>(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
private object MyObject : Parcelable
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// See KT-24842, https://issuetracker.google.com/189858212
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Data private constructor(val value: String) : Parcelable {
|
||||||
|
constructor() : this("OK")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
Data().writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val data = readFromParcel<Data>(parcel)
|
||||||
|
assert(data.value == "OK")
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
// IGNORE_BACKEND: JVM
|
||||||
|
// See https://issuetracker.google.com/178321044
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
data class Test(val sealedClass1 : SealedClass1<*, *>) : Parcelable
|
||||||
|
|
||||||
|
sealed class SealedClass1<out SC1 : SealedClass1<SC1, SC2>, out SC2 : SealedClass2<SC1, SC2>>(val sealedClass2Type: Class<out SC2>) : Parcelable {
|
||||||
|
@Parcelize
|
||||||
|
object SealedClass1Impl1 : SealedClass1<SealedClass1Impl1, SealedClass2.SealedClass2Impl1>(SealedClass2.SealedClass2Impl1::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class SealedClass2<out SC1 : SealedClass1<SC1, SC2>, out SC2 : SealedClass2<SC1, SC2>> : Parcelable {
|
||||||
|
@Parcelize
|
||||||
|
object SealedClass2Impl1 : SealedClass2<SealedClass1.SealedClass1Impl1, SealedClass2.SealedClass2Impl1>()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
val test = Test(SealedClass1.SealedClass1Impl1)
|
||||||
|
test.writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val test2 = readFromParcel<Test>(parcel)
|
||||||
|
assert(test == test2)
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
// See KT-44891, https://issuetracker.google.com/180193969
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@file:JvmName("TestKt")
|
||||||
|
package test
|
||||||
|
|
||||||
|
import kotlinx.parcelize.*
|
||||||
|
import android.os.Parcel
|
||||||
|
import android.os.Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Covariant<out T : CharSequence>(val block: () -> T) : Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Contravariant<in T : CharSequence>(val block: (T) -> Boolean) : Parcelable
|
||||||
|
|
||||||
|
@Parcelize
|
||||||
|
class Invariant<T : CharSequence>(val s: CharSequence) : Parcelable
|
||||||
|
|
||||||
|
fun box() = parcelTest { parcel ->
|
||||||
|
val covariant1 = Covariant<String> { "OK" }
|
||||||
|
val contravariant1 = Contravariant<String> { it == "OK" }
|
||||||
|
val invariant1 = Invariant<String>("OK")
|
||||||
|
covariant1.writeToParcel(parcel, 0)
|
||||||
|
contravariant1.writeToParcel(parcel, 0)
|
||||||
|
invariant1.writeToParcel(parcel, 0)
|
||||||
|
|
||||||
|
val bytes = parcel.marshall()
|
||||||
|
parcel.unmarshall(bytes, 0, bytes.size)
|
||||||
|
parcel.setDataPosition(0)
|
||||||
|
|
||||||
|
val covariant2 = readFromParcel<Covariant<String>>(parcel)
|
||||||
|
assert(covariant2.block() == "OK")
|
||||||
|
|
||||||
|
val contravariant2 = readFromParcel<Contravariant<String>>(parcel)
|
||||||
|
assert(contravariant2.block("OK"))
|
||||||
|
|
||||||
|
val invariant2 = readFromParcel<Invariant<String>>(parcel)
|
||||||
|
assert(invariant2.s.toString() == "OK")
|
||||||
|
}
|
||||||
+30
@@ -120,6 +120,11 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/functions.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/functions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("genericParcelable.kt")
|
||||||
|
public void testGenericParcelable() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/genericParcelable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("generics.kt")
|
@TestMetadata("generics.kt")
|
||||||
public void testGenerics() throws Exception {
|
public void testGenerics() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/generics.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/generics.kt");
|
||||||
@@ -260,6 +265,11 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nestedSparseArrays2.kt")
|
||||||
|
public void testNestedSparseArrays2() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("newArray.kt")
|
@TestMetadata("newArray.kt")
|
||||||
public void testNewArray() throws Exception {
|
public void testNewArray() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/newArray.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/newArray.kt");
|
||||||
@@ -280,6 +290,11 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/nullableTypesSimple.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nullableTypesSimple.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectWriteParcelable.kt")
|
||||||
|
public void testObjectWriteParcelable() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/objectWriteParcelable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objects.kt")
|
@TestMetadata("objects.kt")
|
||||||
public void testObjects() throws Exception {
|
public void testObjects() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/objects.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/objects.kt");
|
||||||
@@ -300,6 +315,16 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/primitiveTypes.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/primitiveTypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateConstructor.kt")
|
||||||
|
public void testPrivateConstructor() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/privateConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recursiveGenerics.kt")
|
||||||
|
public void testRecursiveGenerics() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/recursiveGenerics.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("sealedClass.kt")
|
@TestMetadata("sealedClass.kt")
|
||||||
public void testSealedClass() throws Exception {
|
public void testSealedClass() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt");
|
||||||
@@ -324,4 +349,9 @@ public class ParcelizeBoxTestGenerated extends AbstractParcelizeBoxTest {
|
|||||||
public void testSparseBooleanArray() throws Exception {
|
public void testSparseBooleanArray() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/sparseBooleanArray.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/sparseBooleanArray.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameters.kt")
|
||||||
|
public void testTypeParameters() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+30
@@ -120,6 +120,11 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/functions.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/functions.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("genericParcelable.kt")
|
||||||
|
public void testGenericParcelable() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/genericParcelable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("generics.kt")
|
@TestMetadata("generics.kt")
|
||||||
public void testGenerics() throws Exception {
|
public void testGenerics() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/generics.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/generics.kt");
|
||||||
@@ -260,6 +265,11 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("nestedSparseArrays2.kt")
|
||||||
|
public void testNestedSparseArrays2() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nestedSparseArrays2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("newArray.kt")
|
@TestMetadata("newArray.kt")
|
||||||
public void testNewArray() throws Exception {
|
public void testNewArray() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/newArray.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/newArray.kt");
|
||||||
@@ -280,6 +290,11 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/nullableTypesSimple.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/nullableTypesSimple.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectWriteParcelable.kt")
|
||||||
|
public void testObjectWriteParcelable() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/objectWriteParcelable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("objects.kt")
|
@TestMetadata("objects.kt")
|
||||||
public void testObjects() throws Exception {
|
public void testObjects() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/objects.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/objects.kt");
|
||||||
@@ -300,6 +315,16 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
|||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/primitiveTypes.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/primitiveTypes.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("privateConstructor.kt")
|
||||||
|
public void testPrivateConstructor() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/privateConstructor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recursiveGenerics.kt")
|
||||||
|
public void testRecursiveGenerics() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/recursiveGenerics.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("sealedClass.kt")
|
@TestMetadata("sealedClass.kt")
|
||||||
public void testSealedClass() throws Exception {
|
public void testSealedClass() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/sealedClass.kt");
|
||||||
@@ -324,4 +349,9 @@ public class ParcelizeIrBoxTestGenerated extends AbstractParcelizeIrBoxTest {
|
|||||||
public void testSparseBooleanArray() throws Exception {
|
public void testSparseBooleanArray() throws Exception {
|
||||||
runTest("plugins/parcelize/parcelize-compiler/testData/box/sparseBooleanArray.kt");
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/sparseBooleanArray.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("typeParameters.kt")
|
||||||
|
public void testTypeParameters() throws Exception {
|
||||||
|
runTest("plugins/parcelize/parcelize-compiler/testData/box/typeParameters.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user