Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addtional testing for network layer #78

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.minestom.server.network.packet.client.common;

import net.minestom.server.network.NetworkBuffer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ClientKeepAlivePacketTest {

@Test
void testClientKeepAlivePacket() {
NetworkBuffer networkBuffer = new NetworkBuffer();
ClientKeepAlivePacket clientKeepAlivePacket = new ClientKeepAlivePacket(0L);

clientKeepAlivePacket.write(networkBuffer);

var packet = new ClientKeepAlivePacket(networkBuffer);

assertEquals(0L, packet.id());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.minestom.server.network.packet.client.common;

import net.minestom.server.network.NetworkBuffer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ClientPingRequestPacketTest {

@Test
void testClientPingRequestPacket() {
NetworkBuffer networkBuffer = new NetworkBuffer();
ClientPingRequestPacket requestPacket = new ClientPingRequestPacket(0L);

requestPacket.write(networkBuffer);

var packet = new ClientPingRequestPacket(networkBuffer);

assertEquals(0L, packet.number());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package net.minestom.server.network.packet.client.common;

import net.minestom.server.network.NetworkBuffer;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ClientPluginMessagePacketTest {

// TODO: Fix bug with empty byte array
@Disabled
@Test
void testClientPluginMessagePacket() {
NetworkBuffer networkBuffer = new NetworkBuffer();
ClientPluginMessagePacket clientPluginMessagePacket = new ClientPluginMessagePacket("channel", new byte[0]);

clientPluginMessagePacket.write(networkBuffer);

var packet = new ClientPluginMessagePacket(networkBuffer);

assertEquals("channel", packet.channel());
assertArrayEquals(new byte[0], packet.data());
}

@Test
void testClientPluginMessagePacketException() {
StringBuilder channel = new StringBuilder();
channel.append("a".repeat(257));
assertThrows(IllegalArgumentException.class, () -> new ClientPluginMessagePacket(channel.toString(), new byte[0]));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.minestom.server.network.packet.client.common;

import net.minestom.server.network.NetworkBuffer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ClientPongPacketTest {

@Test
void testClientPongPacket() {
ClientPongPacket clientPongPacket = new ClientPongPacket(0);
NetworkBuffer networkBuffer = new NetworkBuffer();
clientPongPacket.write(networkBuffer);
var packet = new ClientPongPacket(networkBuffer);
assertEquals(0, packet.id());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package net.minestom.server.network.packet.client.common;

import net.minestom.server.entity.Player;
import net.minestom.server.message.ChatMessageType;
import net.minestom.server.network.NetworkBuffer;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ClientSettingsPacketTest {

@Test
void testClientSettingsPacket() {
ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(
"locale",
(byte)0,
ChatMessageType.FULL,
true,
(byte) 0,
Player.MainHand.RIGHT,
true,
true);
NetworkBuffer networkBuffer = new NetworkBuffer();
clientSettingsPacket.write(networkBuffer);
var packet = new ClientSettingsPacket(networkBuffer);
assertEquals("locale", packet.locale());
assertEquals(0, packet.viewDistance());
assertEquals(ChatMessageType.FULL, packet.chatMessageType());
assertTrue(packet.chatColors());
assertEquals(0, packet.displayedSkinParts());
assertEquals(Player.MainHand.RIGHT, packet.mainHand());
assertTrue(packet.enableTextFiltering());
assertTrue(packet.allowsListing());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.minestom.server.network.packet.client.configuration;

import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.network.packet.server.configuration.SelectKnownPacksPacket;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;

class ClientSelectKnownPacksPacketTest {

void testClientSelectKnownPacksPacket() {
theEvilReaper marked this conversation as resolved.
Show resolved Hide resolved
ClientSelectKnownPacksPacket clientSelectKnownPacksPacket = new ClientSelectKnownPacksPacket(
List.of(
new SelectKnownPacksPacket.Entry("a", "a", "a")
)
);
NetworkBuffer networkBuffer = new NetworkBuffer();
clientSelectKnownPacksPacket.write(networkBuffer);
var packet = new ClientSelectKnownPacksPacket(networkBuffer);

assertArrayEquals(clientSelectKnownPacksPacket.entries().toArray(), packet.entries().toArray());
}
}
Loading