network tests: InitializeS2CP

See #93
This commit is contained in:
Moritz Zwerger 2023-07-27 14:00:55 +02:00
parent 0ef29f3eee
commit ebb5b8a04e
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 63 additions and 1 deletions

View File

@ -0,0 +1,61 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.protocol.packets.s2c.play
import de.bixilon.minosoft.data.abilities.Gamemodes
import de.bixilon.minosoft.data.registries.dimension.effects.OverworldEffects
import org.testng.Assert.*
import org.testng.annotations.Test
@Test(groups = ["packet"])
class InitializeS2CPTest {
fun vanilla_1_15_2() {
val packet = PacketReadingTestUtil.read("initialize/vanilla_1_15_2", "1.15.2", constructor = ::InitializeS2CP)
assertEquals(packet.gamemode, Gamemodes.SURVIVAL)
assertEquals(packet.dimension?.effects, OverworldEffects)
assertEquals(packet.entityId, 424)
assertEquals(packet.viewDistance, 9)
}
fun vanilla_1_16_5() {
val packet = PacketReadingTestUtil.read("initialize/vanilla_1_16_5", "1.16.5", constructor = ::InitializeS2CP)
assertEquals(packet.gamemode, Gamemodes.CREATIVE)
assertEquals(packet.dimension?.effects, OverworldEffects)
assertEquals(packet.entityId, 321)
assertEquals(packet.viewDistance, 8)
assertEquals(packet.registries?.size, 2)
assertTrue(packet.registries!!["minecraft:worldgen/biome"] is Map<*, *>)
}
fun hypixel_1_19_4() {
val packet = PacketReadingTestUtil.read("initialize/hypixel_1_19_4", "1.19.4", constructor = ::InitializeS2CP)
assertEquals(packet.gamemode, Gamemodes.SURVIVAL)
assertEquals(packet.dimensionName, OverworldEffects.identifier)
assertEquals(packet.entityId, 11659106)
assertNull(packet.lastDeathPosition)
assertEquals(packet.registries?.size, 6)
assertTrue(packet.registries!!["minecraft:worldgen/biome"] is Map<*, *>)
}
fun vanilla_1_20_1() {
val packet = PacketReadingTestUtil.read("initialize/vanilla_1_20_1", "1.20.1", constructor = ::InitializeS2CP)
assertEquals(packet.gamemode, Gamemodes.CREATIVE)
assertEquals(packet.dimensionName, OverworldEffects.identifier)
assertNull(packet.lastDeathPosition)
assertEquals(packet.registries?.size, 6)
assertTrue(packet.registries!!["minecraft:worldgen/biome"] is Map<*, *>)
}
}

View File

@ -17,11 +17,12 @@ import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.s2c.S2CPacket
import de.bixilon.minosoft.protocol.protocol.buffers.play.PlayInByteBuffer
import java.io.FileNotFoundException
object PacketReadingTestUtil {
fun <T : S2CPacket> read(name: String, version: String, connection: PlayConnection = ConnectionTestUtil.createConnection(version = version), constructor: (PlayInByteBuffer) -> T): T {
val data = PacketReadingTestUtil::class.java.getResourceAsStream("/packets/$name.bin")!!.readAllBytes()
val data = PacketReadingTestUtil::class.java.getResourceAsStream("/packets/$name.bin")?.readAllBytes() ?: throw FileNotFoundException("Can not find packet blob $name")
val buffer = PlayInByteBuffer(data, connection)