forked from Minestom/Minestom
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Addtional testing for network layer #78
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
Draft
TheMeinerLP
wants to merge
2
commits into
master
Choose a base branch
from
feature/network-packet-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...test/java/net/minestom/server/network/packet/client/common/ClientKeepAlivePacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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(packet.id(), 0L); | ||
} | ||
|
||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...st/java/net/minestom/server/network/packet/client/common/ClientPingRequestPacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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(packet.number(), 0L); | ||
theEvilReaper marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
.../java/net/minestom/server/network/packet/client/common/ClientPluginMessagePacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/java/net/minestom/server/network/packet/client/common/ClientPongPacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/net/minestom/server/network/packet/client/common/ClientSettingsPacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...minestom/server/network/packet/client/configuration/ClientSelectKnownPacksPacketTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.