From f068033400b0f4be2d1ce7f81316b5de09c40485 Mon Sep 17 00:00:00 2001 From: Him188 Date: Thu, 19 Mar 2020 11:07:18 +0800 Subject: [PATCH] Add test for skipping map --- .../JceInputTest.kt | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt b/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt index 36d421604..3733a3b2a 100644 --- a/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt +++ b/mirai-core-qqandroid/src/commonTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceInputTest.kt @@ -42,6 +42,73 @@ internal const val ZERO_TYPE: Byte = 12 @Suppress("INVISIBLE_MEMBER") // bug internal class JceInputTest { + @Test + fun testSkippingMap() { + @Serializable + data class TestSerializableClassC( + @JceId(5) val value3: Int = 123123 + ) + + @Serializable + data class TestSerializableClassB( + @JceId(0) val value: Int, + @JceId(123) val nested2: TestSerializableClassC, + @JceId(5) val value5: Int + ) + + @Serializable + data class TestSerializableClassA( + //@JceId(0) val map: Map + @JceId(1) val optional: String = "" + ) + + + val input = buildPacket { + writeJceHead(MAP, 0) // TestSerializableClassB + writeJceHead(BYTE, 0) + writeByte(1) + + writeJceHead(STRUCT_BEGIN, 0); + { + writeJceHead(INT, 0) + writeInt(123) + + writeJceHead(STRUCT_BEGIN, 123); // TestSerializableClassC + { + writeJceHead(INT, 5) + writeInt(123123) + }() + writeJceHead(STRUCT_END, 0) + + writeJceHead(INT, 5) + writeInt(9) + }() + writeJceHead(STRUCT_END, 0) + + writeJceHead(STRUCT_BEGIN, 1); + { + writeJceHead(INT, 5) + writeInt(123123) + }() + writeJceHead(STRUCT_END, 0) + + writeJceHead(STRING1, 1) + writeByte(1) + writeStringUtf8("1") + } + + assertEquals( + TestSerializableClassA( + /*mapOf( + TestSerializableClassB(123, TestSerializableClassC(123123), 9) + to TestSerializableClassC(123123) + )*/ + "1" + ), + Jce.UTF_8.load(TestSerializableClassA.serializer(), input) + ) + } + @Test fun testFuckingComprehensiveStruct() { @Serializable