mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 00:51:34 +01:00
Add junit params
This commit is contained in:
parent
735184b909
commit
cc46b6f130
@ -44,6 +44,7 @@ tasks {
|
|||||||
dependencies {
|
dependencies {
|
||||||
// Junit Testing Framework
|
// Junit Testing Framework
|
||||||
testImplementation(libs.junit.api)
|
testImplementation(libs.junit.api)
|
||||||
|
testImplementation(libs.junit.params)
|
||||||
testRuntimeOnly(libs.junit.engine)
|
testRuntimeOnly(libs.junit.engine)
|
||||||
// Only here to ensure J9 module support for extensions and our classloaders
|
// Only here to ensure J9 module support for extensions and our classloaders
|
||||||
testCompileOnly(libs.mockito.core)
|
testCompileOnly(libs.mockito.core)
|
||||||
|
@ -76,6 +76,7 @@ jcTools = { group = "org.jctools", name = "jctools-core", version.ref = "jcTools
|
|||||||
# Test
|
# Test
|
||||||
junit-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" }
|
junit-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junit-jupiter" }
|
||||||
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" }
|
junit-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junit-jupiter" }
|
||||||
|
junit-params = { group = "org.junit.jupiter", name = "junit-jupiter-params", version.ref = "junit-jupiter" }
|
||||||
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
|
mockito-core = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }
|
||||||
|
|
||||||
# Code Generation
|
# Code Generation
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package net.minestom.server.network;
|
package net.minestom.server.network;
|
||||||
|
|
||||||
import net.minestom.server.network.packet.client.play.ClientChatMessagePacket;
|
|
||||||
import net.minestom.server.network.packet.client.play.ClientPluginMessagePacket;
|
import net.minestom.server.network.packet.client.play.ClientPluginMessagePacket;
|
||||||
import net.minestom.server.utils.PacketUtils;
|
import net.minestom.server.utils.PacketUtils;
|
||||||
import net.minestom.server.utils.binary.BinaryBuffer;
|
import net.minestom.server.utils.binary.BinaryBuffer;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.binary.PooledBuffers;
|
import net.minestom.server.utils.binary.PooledBuffers;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
import java.util.zip.DataFormatException;
|
import java.util.zip.DataFormatException;
|
||||||
|
|
||||||
@ -15,38 +15,20 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||||||
|
|
||||||
public class SocketReadTest {
|
public class SocketReadTest {
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest
|
||||||
public void completeUncompressed() throws DataFormatException {
|
@ValueSource(booleans = {false, true})
|
||||||
var packet = new ClientChatMessagePacket("Hello World!");
|
public void complete(boolean compressed) throws DataFormatException {
|
||||||
|
|
||||||
var buffer = PooledBuffers.packetBuffer();
|
|
||||||
PacketUtils.writeFramedPacket(buffer, 3, packet, 0);
|
|
||||||
|
|
||||||
var wrapper = BinaryBuffer.wrap(buffer);
|
|
||||||
wrapper.reset(0, buffer.position());
|
|
||||||
|
|
||||||
var result = PacketUtils.readPackets(wrapper, false);
|
|
||||||
assertNull(result.remaining());
|
|
||||||
var packets = result.packets();
|
|
||||||
assertEquals(1, packets.size());
|
|
||||||
var rawPacket = packets.get(0);
|
|
||||||
assertEquals(3, rawPacket.id());
|
|
||||||
var readPacket = new ClientChatMessagePacket(new BinaryReader(rawPacket.payload()));
|
|
||||||
assertEquals("Hello World!", readPacket.message());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void completeCompressed() throws DataFormatException {
|
|
||||||
var packet = new ClientPluginMessagePacket("channel", new byte[2000]);
|
var packet = new ClientPluginMessagePacket("channel", new byte[2000]);
|
||||||
|
|
||||||
var buffer = PooledBuffers.packetBuffer();
|
var buffer = PooledBuffers.packetBuffer();
|
||||||
PacketUtils.writeFramedPacket(buffer, 0x0A, packet, 256);
|
PacketUtils.writeFramedPacket(buffer, 0x0A, packet, compressed ? 256 : 0);
|
||||||
|
|
||||||
var wrapper = BinaryBuffer.wrap(buffer);
|
var wrapper = BinaryBuffer.wrap(buffer);
|
||||||
wrapper.reset(0, buffer.position());
|
wrapper.reset(0, buffer.position());
|
||||||
|
|
||||||
var result = PacketUtils.readPackets(wrapper, true);
|
var result = PacketUtils.readPackets(wrapper, compressed);
|
||||||
assertNull(result.remaining());
|
assertNull(result.remaining());
|
||||||
|
|
||||||
var packets = result.packets();
|
var packets = result.packets();
|
||||||
assertEquals(1, packets.size());
|
assertEquals(1, packets.size());
|
||||||
var rawPacket = packets.get(0);
|
var rawPacket = packets.get(0);
|
||||||
@ -55,4 +37,29 @@ public class SocketReadTest {
|
|||||||
assertEquals("channel", readPacket.channel());
|
assertEquals("channel", readPacket.channel());
|
||||||
assertEquals(2000, readPacket.data().length);
|
assertEquals(2000, readPacket.data().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ParameterizedTest
|
||||||
|
@ValueSource(booleans = {false, true})
|
||||||
|
public void completeTwo(boolean compressed) throws DataFormatException {
|
||||||
|
var packet = new ClientPluginMessagePacket("channel", new byte[2000]);
|
||||||
|
|
||||||
|
var buffer = PooledBuffers.packetBuffer();
|
||||||
|
PacketUtils.writeFramedPacket(buffer, 0x0A, packet, compressed ? 256 : 0);
|
||||||
|
PacketUtils.writeFramedPacket(buffer, 0x0A, packet, compressed ? 256 : 0);
|
||||||
|
|
||||||
|
var wrapper = BinaryBuffer.wrap(buffer);
|
||||||
|
wrapper.reset(0, buffer.position());
|
||||||
|
|
||||||
|
var result = PacketUtils.readPackets(wrapper, compressed);
|
||||||
|
assertNull(result.remaining());
|
||||||
|
|
||||||
|
var packets = result.packets();
|
||||||
|
assertEquals(2, packets.size());
|
||||||
|
for (var rawPacket : packets) {
|
||||||
|
assertEquals(0x0A, rawPacket.id());
|
||||||
|
var readPacket = new ClientPluginMessagePacket(new BinaryReader(rawPacket.payload()));
|
||||||
|
assertEquals("channel", readPacket.channel());
|
||||||
|
assertEquals(2000, readPacket.data().length);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user