2016-07-16 21:46:23 +02:00
|
|
|
/**
|
|
|
|
* (c) 2016 dmulloy2
|
|
|
|
*/
|
|
|
|
package com.comphenix.protocol.injector;
|
|
|
|
|
2022-02-20 12:16:11 +01:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2016-07-16 21:46:23 +02:00
|
|
|
|
|
|
|
import com.comphenix.protocol.BukkitInitialization;
|
|
|
|
import com.comphenix.protocol.PacketType;
|
|
|
|
import com.comphenix.protocol.events.PacketContainer;
|
|
|
|
import com.comphenix.protocol.injector.netty.WirePacket;
|
|
|
|
import io.netty.buffer.ByteBuf;
|
2022-02-20 12:16:11 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import org.junit.jupiter.api.BeforeAll;
|
|
|
|
import org.junit.jupiter.api.Test;
|
2016-07-16 21:46:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author dmulloy2
|
|
|
|
*/
|
|
|
|
public class WirePacketTest {
|
2022-02-20 12:16:11 +01:00
|
|
|
|
|
|
|
@BeforeAll
|
2016-07-16 21:46:23 +02:00
|
|
|
public static void beforeClass() {
|
2022-02-20 12:16:11 +01:00
|
|
|
BukkitInitialization.initializeAll();
|
2016-07-16 21:46:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 02:35:41 +02:00
|
|
|
// @Test
|
2016-07-16 21:46:23 +02:00
|
|
|
public void testPackets() {
|
2020-06-30 02:35:41 +02:00
|
|
|
List<String> failures = new ArrayList<>();
|
|
|
|
|
|
|
|
for (PacketType type : PacketType.values()) {
|
2022-02-20 12:16:11 +01:00
|
|
|
if (type.isDeprecated()) {
|
2020-06-30 02:35:41 +02:00
|
|
|
continue;
|
2022-02-20 12:16:11 +01:00
|
|
|
}
|
2020-06-30 02:35:41 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
PacketContainer packet = new PacketContainer(type);
|
|
|
|
WirePacket wire = WirePacket.fromPacket(packet);
|
|
|
|
WirePacket handle = WirePacket.fromPacket(packet.getHandle());
|
|
|
|
assertEquals(wire, handle);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
failures.add(type + " :: " + ex.getMessage());
|
|
|
|
System.out.println(type);
|
|
|
|
ex.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assertEquals(failures, new ArrayList<>());
|
2016-07-16 21:46:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSerialization() {
|
|
|
|
int id = 42;
|
2022-02-20 12:16:11 +01:00
|
|
|
byte[] array = {1, 3, 7, 21, 88, 67, 8};
|
2016-07-16 21:46:23 +02:00
|
|
|
|
|
|
|
WirePacket packet = new WirePacket(id, array);
|
|
|
|
|
|
|
|
ByteBuf buf = packet.serialize();
|
|
|
|
|
|
|
|
int backId = WirePacket.readVarInt(buf);
|
|
|
|
byte[] backArray = new byte[buf.readableBytes()];
|
|
|
|
buf.readBytes(backArray);
|
|
|
|
|
|
|
|
assertEquals(id, backId);
|
|
|
|
assertArrayEquals(array, backArray);
|
|
|
|
}
|
|
|
|
}
|