Commit e7ea1968 authored by Him188's avatar Him188

Fix test

parent 2f9d104f
...@@ -35,7 +35,7 @@ class MessageSvc { ...@@ -35,7 +35,7 @@ class MessageSvc {
.readRemainingAsJceStruct(RequestPushNotify.serializer()) .readRemainingAsJceStruct(RequestPushNotify.serializer())
println(requestPushNotify.contentToString()) println(requestPushNotify.contentToString())
TODO() return requestPushNotify
} }
} }
} }
......
...@@ -9,10 +9,6 @@ import net.mamoe.mirai.qqandroid.io.buildJcePacket ...@@ -9,10 +9,6 @@ import net.mamoe.mirai.qqandroid.io.buildJcePacket
import net.mamoe.mirai.utils.cryptor.contentToString import net.mamoe.mirai.utils.cryptor.contentToString
import kotlin.test.Test import kotlin.test.Test
fun main() {
JceDecoderTest().testSimpleMap()
}
class JceDecoderTest { class JceDecoderTest {
@Serializable @Serializable
...@@ -40,7 +36,7 @@ class JceDecoderTest { ...@@ -40,7 +36,7 @@ class JceDecoderTest {
@Serializable @Serializable
class TestComplexJceStruct( class TestComplexJceStruct(
@SerialId(6) val string: String = "haha", @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<Byte> = listOf(1, 2, 3), // error here @SerialId(8) val byteList: List<Byte> = listOf(1, 2, 3), // error here
@SerialId(9) val map: Map<String, Map<String, ByteArray>> = mapOf("哈哈" to mapOf("哈哈" to byteArrayOf(1, 2, 3))), @SerialId(9) val map: Map<String, Map<String, ByteArray>> = mapOf("哈哈" to mapOf("哈哈" to byteArrayOf(1, 2, 3))),
// @SerialId(10) val nestedJceStruct: TestSimpleJceStruct = TestSimpleJceStruct(), // @SerialId(10) val nestedJceStruct: TestSimpleJceStruct = TestSimpleJceStruct(),
...@@ -59,12 +55,22 @@ class JceDecoderTest { ...@@ -59,12 +55,22 @@ class JceDecoderTest {
@Test @Test
fun testEncoder() { fun testEncoder() {
println(TestComplexJceStruct().toByteArray(TestComplexJceStruct.serializer()).loadAs(TestComplexNullableJceStruct.serializer()).contentToString()) println(
TestComplexJceStruct().toByteArray(TestComplexJceStruct.serializer()).loadAs(
TestComplexNullableJceStruct.serializer(),
JceCharset.UTF8
).contentToString()
)
} }
@Test @Test
fun testEncoder3() { fun testEncoder3() {
println(TestComplexNullableJceStruct().toByteArray(TestComplexNullableJceStruct.serializer()).loadAs(TestComplexNullableJceStruct.serializer()).contentToString()) println(
TestComplexNullableJceStruct().toByteArray(TestComplexNullableJceStruct.serializer()).loadAs(
TestComplexNullableJceStruct.serializer(),
JceCharset.UTF8
).contentToString()
)
} }
@Test @Test
......
...@@ -181,4 +181,4 @@ fun ByteArray.toInt(): Int = ...@@ -181,4 +181,4 @@ fun ByteArray.toInt(): Int =
* 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入. * 从 [IoBuffer.Pool] [borrow][ObjectPool.borrow] 一个 [IoBuffer] 然后将 [this] 写入.
* 注意回收 ([ObjectPool.recycle]) * 注意回收 ([ObjectPool.recycle])
*/ */
fun ByteArray.toIoBuffer(offset: Int = 0, length: Int = this.size - offset): IoBuffer = IoBuffer.Pool.borrow().let { it.writeFully(this, offset, length); it } fun ByteArray.toIoBuffer(offset: Int = 0, length: Int = this.size - offset, pool: ObjectPool<IoBuffer> = IoBuffer.Pool): IoBuffer = pool.borrow().let { it.writeFully(this, offset, length); it }
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment