From e7ea19682a1ef50891f6c894e374e9787048cfc2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Tue, 28 Jan 2020 21:10:14 +0800 Subject: [PATCH] Fix test --- .../chat/receive/MessageSvc.PushNotify.kt | 2 +- .../JceDecoderTest.kt | 20 ++++++++++++------- .../utils/io/TypeConversion.kt | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PushNotify.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PushNotify.kt index 42c2687b5..a20ada6e3 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PushNotify.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.PushNotify.kt @@ -35,7 +35,7 @@ class MessageSvc { .readRemainingAsJceStruct(RequestPushNotify.serializer()) println(requestPushNotify.contentToString()) - TODO() + return requestPushNotify } } } diff --git a/mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt b/mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt index 1d6f56942..95be01e6b 100644 --- a/mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt +++ b/mirai-core-qqandroid/src/jvmTest/kotlin/net.mamoe.mirai.qqandroid.io.serialization/JceDecoderTest.kt @@ -9,10 +9,6 @@ import net.mamoe.mirai.qqandroid.io.buildJcePacket import net.mamoe.mirai.utils.cryptor.contentToString import kotlin.test.Test -fun main() { - JceDecoderTest().testSimpleMap() -} - class JceDecoderTest { @Serializable @@ -40,7 +36,7 @@ class JceDecoderTest { @Serializable class TestComplexJceStruct( @SerialId(6) val string: String = "haha", - @SerialId(7) val byteArray: ByteArray = ByteArray(2000), + @SerialId(7) val byteArray: ByteArray = ByteArray(500), @SerialId(8) val byteList: List = listOf(1, 2, 3), // error here @SerialId(9) val map: Map> = mapOf("哈哈" to mapOf("哈哈" to byteArrayOf(1, 2, 3))), // @SerialId(10) val nestedJceStruct: TestSimpleJceStruct = TestSimpleJceStruct(), @@ -59,12 +55,22 @@ class JceDecoderTest { @Test fun testEncoder() { - println(TestComplexJceStruct().toByteArray(TestComplexJceStruct.serializer()).loadAs(TestComplexNullableJceStruct.serializer()).contentToString()) + println( + TestComplexJceStruct().toByteArray(TestComplexJceStruct.serializer()).loadAs( + TestComplexNullableJceStruct.serializer(), + JceCharset.UTF8 + ).contentToString() + ) } @Test fun testEncoder3() { - println(TestComplexNullableJceStruct().toByteArray(TestComplexNullableJceStruct.serializer()).loadAs(TestComplexNullableJceStruct.serializer()).contentToString()) + println( + TestComplexNullableJceStruct().toByteArray(TestComplexNullableJceStruct.serializer()).loadAs( + TestComplexNullableJceStruct.serializer(), + JceCharset.UTF8 + ).contentToString() + ) } @Test diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConversion.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConversion.kt index 8c65f1e4a..7f41ad346 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConversion.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/io/TypeConversion.kt @@ -181,4 +181,4 @@ fun ByteArray.toInt(): Int = * 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入. * 注意回收 ([ObjectPool.recycle]) */ -fun ByteArray.toIoBuffer(offset: Int = 0, length: Int = this.size - offset): IoBuffer = IoBuffer.Pool.borrow().let { it.writeFully(this, offset, length); it } \ No newline at end of file +fun ByteArray.toIoBuffer(offset: Int = 0, length: Int = this.size - offset, pool: ObjectPool = IoBuffer.Pool): IoBuffer = pool.borrow().let { it.writeFully(this, offset, length); it } \ No newline at end of file