From 2dac3b5d92b7b11adec70896cbb6730342e0f4b9 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 21 May 2022 16:04:14 +0100 Subject: [PATCH] Add FileMessage tests --- .../protocol/impl/FileMessageProtocol.kt | 3 - .../protocol/impl/FileMessageProtocolTest.kt | 64 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 mirai-core/src/commonTest/kotlin/message/protocol/impl/FileMessageProtocolTest.kt diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt index f0b857c7b..2b238a618 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/FileMessageProtocol.kt @@ -33,9 +33,6 @@ internal class FileMessageProtocol : MessageProtocol() { markAsConsumed() - processAlso(data) - process(data) - data.transElemInfo.elemValue.read { // group file feed // 01 00 77 08 06 12 0A 61 61 61 61 61 61 2E 74 78 74 1A 06 31 35 42 79 74 65 3A 5F 12 5D 08 66 12 25 2F 64 37 34 62 62 66 33 61 2D 37 62 32 35 2D 31 31 65 62 2D 38 34 66 38 2D 35 34 35 32 30 30 37 62 35 64 39 66 18 0F 22 0A 61 61 61 61 61 61 2E 74 78 74 28 00 3A 00 42 20 61 33 32 35 66 36 33 34 33 30 65 37 61 30 31 31 66 37 64 30 38 37 66 63 33 32 34 37 35 34 39 63 diff --git a/mirai-core/src/commonTest/kotlin/message/protocol/impl/FileMessageProtocolTest.kt b/mirai-core/src/commonTest/kotlin/message/protocol/impl/FileMessageProtocolTest.kt new file mode 100644 index 000000000..c078bb4e0 --- /dev/null +++ b/mirai-core/src/commonTest/kotlin/message/protocol/impl/FileMessageProtocolTest.kt @@ -0,0 +1,64 @@ +/* + * Copyright 2019-2022 Mamoe Technologies and contributors. + * + * 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证. + * Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link. + * + * https://github.com/mamoe/mirai/blob/dev/LICENSE + */ + +package net.mamoe.mirai.internal.message.protocol.impl + +import net.mamoe.mirai.contact.MemberPermission +import net.mamoe.mirai.internal.message.protocol.MessageProtocol +import net.mamoe.mirai.message.data.FileMessage +import net.mamoe.mirai.utils.hexToBytes +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test + +internal class FileMessageProtocolTest : AbstractMessageProtocolTest() { + override val protocols: Array = arrayOf(FileMessageProtocol(), TextProtocol()) + + @BeforeEach + fun `init group`() { + defaultTarget = bot.addGroup(123, 1230003).apply { + addMember(1230003, "user3", MemberPermission.OWNER) + } + } + + @Test + fun `test decode`() { + buildChecks { + elem( + net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( + elemFlags2 = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.ElemFlags2( + compatibleId = 1, + msgRptCnt = 1, + ), + ), + net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( + transElemInfo = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.TransElem( + elemType = 24, + elemValue = "01 00 7A 08 06 12 0C 73 65 73 73 69 6F 6E 2E 6C 6F 63 6B 1A 05 38 42 79 74 65 3A 61 12 5F 08 66 12 25 2F 38 34 33 35 32 37 64 38 2D 64 39 31 35 2D 31 31 65 63 2D 62 32 34 30 2D 35 34 35 32 30 30 37 62 64 61 61 34 18 08 22 0C 73 65 73 73 69 6F 6E 2E 6C 6F 63 6B 28 00 3A 00 42 20 39 30 33 65 39 36 34 35 36 38 38 62 63 62 32 35 35 64 30 36 64 31 64 61 31 35 33 66 64 36 32 64".hexToBytes(), + ), + ), + net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( + generalFlags = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.GeneralFlags( + glamourLevel = 3, + pbReserve = "08 0A 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 98 03 00 A0 03 20 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 02 10 0B 90 04 80 01 B8 04 02 C0 04 01 CA 04 00 F8 04 00 88 05 00".hexToBytes(), + ), + ), + net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.Elem( + extraInfo = net.mamoe.mirai.internal.network.protocol.data.proto.ImMsgBody.ExtraInfo( + nick = "Nick", + level = 1, + flags = 8, + groupMask = 1, + ), + ) + ) + message(FileMessage("/843527d8-d915-11ec-b240-5452007bdaa4", 102, "session.lock", 8)) + useOrdinaryEquality() + }.doDecoderChecks() + } +} \ No newline at end of file