From ac50361a72abef1e157d9ea3ed557eb012bba2c9 Mon Sep 17 00:00:00 2001 From: Eritque arcus Date: Sat, 4 Mar 2023 14:05:38 -0500 Subject: [PATCH] fix: fix groupFileList error, fix #188, and add mockTests for groupFileList --- cpp/mockTest/mockTestEntrance.cpp | 6 ++ .../src/commonMain/kotlin/PublicShared.kt | 13 ++-- .../jvmTest/kotlin/events/OperationTest.kt | 77 ++++++++++++++++--- 3 files changed, 77 insertions(+), 19 deletions(-) diff --git a/cpp/mockTest/mockTestEntrance.cpp b/cpp/mockTest/mockTestEntrance.cpp index 8f4949ea0..233609980 100644 --- a/cpp/mockTest/mockTestEntrance.cpp +++ b/cpp/mockTest/mockTestEntrance.cpp @@ -127,6 +127,12 @@ class Main : public CPPPlugin { TEST(sendFile, sendFileTest, { a.group.sendFile("/img/img.png", absolute(std::filesystem::path("./src/jvmTest/resources/img.png")).string()); }) + TEST(groupFileListRoot, groupFileListRootTest, { + Logger::logger.info("fileList:", a.group.getFileListString("/")); + }) + TEST(groupFileListFolder, groupFileListFolderTest, { + Logger::logger.info("fileList:", a.group.getFileListString("/a/")); + }) TEST_STARTWITH(remoteFileInfo, remoteFileInfoTest, { Logger::logger.info("reId" + a.group.getFile("/mic.amr").id); Logger::logger.info("reId" + a.group.getFileById(a.message[0]->content.substr(14)).id); diff --git a/kotlin/shared/src/commonMain/kotlin/PublicShared.kt b/kotlin/shared/src/commonMain/kotlin/PublicShared.kt index 06acdd5be..a7f517d21 100644 --- a/kotlin/shared/src/commonMain/kotlin/PublicShared.kt +++ b/kotlin/shared/src/commonMain/kotlin/PublicShared.kt @@ -496,13 +496,12 @@ object PublicShared { private suspend fun remoteFileList(path: String, c: Packets.Contact): String = c.withBot { bot -> c.withGroup(bot, "找不到对应群组,位置K-remoteFileInfo,gid:${c.id}") { group -> - var tmp = "[" - group.files.root.resolveFiles(path).toList().forEach { - tmp += "[\"${it.absolutePath}\", \"${it.id}\"]," - } - tmp = tmp.substring(0, tmp.length - 1) - tmp += "]" - return tmp + return "[" + + (if (path == "/") group.files.root.files() else group.files.root.resolveFiles(path)) + .toList().joinToString(",") { + "[\"${it.absolutePath}\", \"${it.id}\"]" + } + + "]" } } diff --git a/kotlin/shared/src/jvmTest/kotlin/events/OperationTest.kt b/kotlin/shared/src/jvmTest/kotlin/events/OperationTest.kt index 1670d7664..e7503ca8b 100644 --- a/kotlin/shared/src/jvmTest/kotlin/events/OperationTest.kt +++ b/kotlin/shared/src/jvmTest/kotlin/events/OperationTest.kt @@ -44,8 +44,7 @@ class OperationTest : TestBase() { member.says("honorMember") waitUntilEnd() val logs = TestUtils.logList.filter { it.contains("honorMember:") }.map { it.substringAfter("honorMember:") } - assertEquals(1, logs.size) - assertEquals(member.id.toString(), logs[0]) + assertContentEquals(listOf(member.id.toString()), logs) } @Test @@ -67,11 +66,7 @@ class OperationTest : TestBase() { member.says("botList") waitUntilEnd() val logs = TestUtils.logList.filter { it.contains("botList:") }.map { it.substringAfter("botList:") } - assertEquals(4, logs.size) - assertEquals(friend.id, logs[0].toLong()) - assertEquals(group.id, logs[1].toLong()) - assertEquals(member.id, logs[2].toLong()) - assertEquals(bot.id, logs[3].toLong()) + assertContentEquals(listOf(friend.id, group.id, member.id, bot.id), logs.map { it.toLong() }) } @Test @@ -104,9 +99,7 @@ class OperationTest : TestBase() { }.map { it.substringAfter("reId") } - assertEquals(2, logs.size) - assertEquals(file.id, logs[0]) - assertEquals(file.id, logs[1]) + assertContentEquals(listOf(file.id, file.id), logs) } @Test @@ -164,8 +157,7 @@ class OperationTest : TestBase() { }.map { it.substringAfter("reId") } - assertEquals(1, logs.size) - assertEquals(group.owner.id.toString(), logs[0]) + assertContentEquals(listOf(group.owner.id.toString()), logs) } @Test @@ -265,4 +257,65 @@ class OperationTest : TestBase() { waitUntilEnd() assertEquals("test", member.specialTitle) } + + @Test + fun groupFileListRootEmpty() = runBlocking { + member.says("groupFileListRoot") + waitUntilEnd() + val logs = TestUtils.logList.filter { + it.contains("fileList:") + }.map { + it.substringAfter("fileList:") + } + assertContentEquals(listOf("[]"), logs) + } + + @Test + fun groupFileListRoot() = runBlocking { + val file = this@OperationTest.javaClass.classLoader.getResourceAsStream("mic.amr")!!.use { res -> + res.toExternalResource().use { + group.files.root.uploadNewFile( + "/mic.amr", + it + ) + } + } + member.says("groupFileListRoot") + waitUntilEnd() + val logs = TestUtils.logList.filter { + it.contains("fileList:") + }.map { + it.substringAfter("fileList:") + } + assertContentEquals(listOf("[[\"/mic.amr\", \"${file.id}\"]]"), logs) + } + + @Test + fun groupFileListFolder() = runBlocking { + val file = this@OperationTest.javaClass.classLoader.getResourceAsStream("mic.amr")!!.use { res -> + res.toExternalResource().use { + listOf( + group.files.root.uploadNewFile( + "/a/mic.amr", + it + ), + group.files.root.uploadNewFile( + "/a/micb.amr", + it + ) + ) + } + } + member.says("groupFileListFolder") + waitUntilEnd() + val logs = TestUtils.logList.filter { + it.contains("fileList:") + }.map { + it.substringAfter("fileList:") + } + assertContentEquals( + listOf("[[\"/a/mic.amr\", \"${file[0].id}\"], [\"/a/micb.amr\", \"${file[1].id}\"]]"), + logs + ) + } } \ No newline at end of file