geforkt von Mirrors/Velocity
Fix the tests for now. More extensive ones later.
Dieser Commit ist enthalten in:
Ursprung
e672f8d7cd
Commit
dcc40dd06b
@ -110,6 +110,9 @@ public enum StateRegistry {
|
|||||||
|
|
||||||
for (final PacketMapping mapping : mappings) {
|
for (final PacketMapping mapping : mappings) {
|
||||||
ProtocolVersion version = this.versions.get(mapping.protocolVersion);
|
ProtocolVersion version = this.versions.get(mapping.protocolVersion);
|
||||||
|
if (version == null) {
|
||||||
|
throw new IllegalArgumentException("Unknown protocol version " + mapping.protocolVersion);
|
||||||
|
}
|
||||||
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
version.packetIdToSupplier.put(mapping.id, packetSupplier);
|
||||||
version.packetClassToId.put(clazz, mapping.id);
|
version.packetClassToId.put(clazz, mapping.id);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.velocitypowered.proxy.protocol;
|
package com.velocitypowered.proxy.protocol;
|
||||||
|
|
||||||
import com.velocitypowered.proxy.protocol.packets.Handshake;
|
import com.velocitypowered.proxy.protocol.packets.Handshake;
|
||||||
import com.velocitypowered.proxy.protocol.packets.Ping;
|
import com.velocitypowered.proxy.protocol.packets.KeepAlive;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
@ -9,38 +9,27 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
class PacketRegistryTest {
|
class PacketRegistryTest {
|
||||||
private StateRegistry.PacketRegistry setupRegistry() {
|
private StateRegistry.PacketRegistry setupRegistry() {
|
||||||
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND);
|
StateRegistry.PacketRegistry registry = new StateRegistry.PacketRegistry(ProtocolConstants.Direction.CLIENTBOUND);
|
||||||
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, 1));
|
registry.register(Handshake.class, Handshake::new, new StateRegistry.PacketMapping(0x00, ProtocolConstants.MINECRAFT_1_12));
|
||||||
registry.register(Ping.class, Ping::new, new StateRegistry.PacketMapping(0x01, 1),
|
|
||||||
new StateRegistry.PacketMapping(0x02, 5));
|
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void packetRegistryWorks() {
|
void packetRegistryWorks() {
|
||||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
StateRegistry.PacketRegistry registry = setupRegistry();
|
||||||
MinecraftPacket packet = registry.getVersion(1).createPacket(0);
|
MinecraftPacket packet = registry.getVersion(ProtocolConstants.MINECRAFT_1_12).createPacket(0);
|
||||||
assertNotNull(packet, "Packet was not found in registry");
|
assertNotNull(packet, "Packet was not found in registry");
|
||||||
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
||||||
|
|
||||||
assertEquals(0, registry.getVersion(1).getPacketId(packet), "Registry did not return the correct packet ID");
|
assertEquals(0, registry.getVersion(ProtocolConstants.MINECRAFT_1_12).getPacketId(packet), "Registry did not return the correct packet ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void packetRegistryRevertsToBestOldVersion() {
|
void packetRegistryLinkingWorks() {
|
||||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
StateRegistry.PacketRegistry registry = setupRegistry();
|
||||||
MinecraftPacket packet = registry.getVersion(2).createPacket(0);
|
MinecraftPacket packet = registry.getVersion(ProtocolConstants.MINECRAFT_1_12_1).createPacket(0);
|
||||||
assertNotNull(packet, "Packet was not found in registry");
|
assertNotNull(packet, "Packet was not found in registry");
|
||||||
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
assertEquals(Handshake.class, packet.getClass(), "Registry returned wrong class");
|
||||||
|
assertEquals(0, registry.getVersion(ProtocolConstants.MINECRAFT_1_12_1).getPacketId(packet), "Registry did not return the correct packet ID");
|
||||||
assertEquals(0, registry.getVersion(2).getPacketId(packet), "Registry did not return the correct packet ID");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void packetRegistryDoesntProvideNewPacketsForOld() {
|
|
||||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
|
||||||
assertNull(registry.getVersion(0).createPacket(0), "Packet was found in registry despite being too new");
|
|
||||||
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> registry.getVersion(0).getPacketId(new Handshake()), "Registry provided new packets for an old protocol version");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -49,16 +38,4 @@ class PacketRegistryTest {
|
|||||||
assertThrows(IllegalArgumentException.class, () -> registry.register(Handshake.class, Handshake::new));
|
assertThrows(IllegalArgumentException.class, () -> registry.register(Handshake.class, Handshake::new));
|
||||||
assertThrows(IllegalArgumentException.class, () -> registry.getVersion(0).getPacketId(new Handshake()));
|
assertThrows(IllegalArgumentException.class, () -> registry.getVersion(0).getPacketId(new Handshake()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
void packetRegistryProvidesCorrectVersionsForMultipleMappings() {
|
|
||||||
StateRegistry.PacketRegistry registry = setupRegistry();
|
|
||||||
assertNotNull(registry.getVersion(1).createPacket(1), "Packet was not found in registry despite being being registered with ID 1 and version 1");
|
|
||||||
assertNotNull(registry.getVersion(2).createPacket(1), "Packet was not found in registry despite being being registered with ID 1 and version 1 (we are looking up version 2)");
|
|
||||||
assertNotNull(registry.getVersion(5).createPacket(2), "Packet was not found in registry despite being being registered with ID 2 and version 5");
|
|
||||||
assertNotNull(registry.getVersion(6).createPacket(2), "Packet was not found in registry despite being being registered with ID 2 and version 5 (we are looking up version 6)");
|
|
||||||
|
|
||||||
assertEquals(1, registry.getVersion(1).getPacketId(new Ping()), "Wrong ID provided from registry");
|
|
||||||
assertEquals(2, registry.getVersion(5).getPacketId(new Ping()), "Wrong ID provided from registry");
|
|
||||||
}
|
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren