|
@@ -27,7 +27,7 @@ static void tick(int ticks) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static void testConnect(Test& test, PacketType pt) {
|
|
|
+static void testConnect(Test& test, PacketSendMode mode) {
|
|
|
static bool clientConnected = false;
|
|
|
static bool clientDisconnected = false;
|
|
|
static bool clientPackage = false;
|
|
@@ -49,6 +49,8 @@ static void testConnect(Test& test, PacketType pt) {
|
|
|
static int32 data9 = 0;
|
|
|
static StringBuffer<20> data10;
|
|
|
static float data11 = 0.0f;
|
|
|
+ static IntVector3 data12;
|
|
|
+ static Vector3 data13;
|
|
|
|
|
|
serverConnected = false;
|
|
|
serverDisconnect = false;
|
|
@@ -63,33 +65,37 @@ static void testConnect(Test& test, PacketType pt) {
|
|
|
data9 = 0;
|
|
|
data10.clear();
|
|
|
data11 = 0.0f;
|
|
|
+ data12 = IntVector3();
|
|
|
+ data13 = Vector3();
|
|
|
|
|
|
Server::resetHandler();
|
|
|
Server::setConnectHandler([](Server::Client) { serverConnected = true; });
|
|
|
Server::setDisconnectHandler(
|
|
|
[](Server::Client) { serverDisconnect = true; });
|
|
|
Server::setPacketHandler([](Server::Client client, InPacket& in) {
|
|
|
- in.readU8(data1);
|
|
|
- in.readU16(data2);
|
|
|
- in.readU32(data3);
|
|
|
- in.readS8(data4);
|
|
|
- in.readS16(data5);
|
|
|
- in.readS32(data6);
|
|
|
- in.readS8(data7);
|
|
|
- in.readS16(data8);
|
|
|
- in.readS32(data9);
|
|
|
- in.readString(data10);
|
|
|
- in.readFloat(data11);
|
|
|
+ in.read(data1);
|
|
|
+ in.read(data2);
|
|
|
+ in.read(data3);
|
|
|
+ in.read(data4);
|
|
|
+ in.read(data5);
|
|
|
+ in.read(data6);
|
|
|
+ in.read(data7);
|
|
|
+ in.read(data8);
|
|
|
+ in.read(data9);
|
|
|
+ in.read(data10);
|
|
|
+ in.read(data11);
|
|
|
+ in.read(data12);
|
|
|
+ in.read(data13);
|
|
|
|
|
|
if(packageCounter == 0) {
|
|
|
OutPacket out(0);
|
|
|
- Server::send(client, out, PacketType::RELIABLE);
|
|
|
+ Server::send(client, out, PacketSendMode::RELIABLE);
|
|
|
} else if(packageCounter == 1) {
|
|
|
OutPacket out(0);
|
|
|
- Server::send(client, out, PacketType::SEQUENCED);
|
|
|
+ Server::send(client, out, PacketSendMode::SEQUENCED);
|
|
|
} else if(packageCounter == 2) {
|
|
|
OutPacket out(0);
|
|
|
- Server::send(client, out, PacketType::UNSEQUENCED);
|
|
|
+ Server::send(client, out, PacketSendMode::UNSEQUENCED);
|
|
|
}
|
|
|
packageCounter++;
|
|
|
});
|
|
@@ -123,7 +129,9 @@ static void testConnect(Test& test, PacketType pt) {
|
|
|
StringBuffer<20> s("Hi there");
|
|
|
out.writeString(s);
|
|
|
out.writeFloat(252345.983f);
|
|
|
- Client::send(out, pt);
|
|
|
+ out.writeVector(IntVector3(1, 2, 3));
|
|
|
+ out.writeVector(Vector3(1.5f, 2.5f, 3.5f));
|
|
|
+ Client::send(out, mode);
|
|
|
|
|
|
tick(100);
|
|
|
|
|
@@ -141,6 +149,12 @@ static void testConnect(Test& test, PacketType pt) {
|
|
|
test.checkEqual(0x71234567, data9, "correct value is sent 9");
|
|
|
test.checkEqual(s, data10, "correct value is sent 10");
|
|
|
test.checkFloat(252345.983f, data11, 0.01f, "correct value is sent 11");
|
|
|
+ test.checkEqual(1, data12[0], "correct value is sent 12|1");
|
|
|
+ test.checkEqual(2, data12[1], "correct value is sent 12|2");
|
|
|
+ test.checkEqual(3, data12[2], "correct value is sent 12|3");
|
|
|
+ test.checkFloat(1.5f, data13[0], 0.01f, "correct value is sent 13|1");
|
|
|
+ test.checkFloat(2.5f, data13[1], 0.01f, "correct value is sent 13|2");
|
|
|
+ test.checkFloat(3.5f, data13[2], 0.01f, "correct value is sent 13|3");
|
|
|
|
|
|
Client::disconnect(90);
|
|
|
test.checkFalse(Client::isConnected(), "client was disconnected");
|
|
@@ -195,9 +209,9 @@ static void testStop(Test& test) {
|
|
|
|
|
|
void NetworkTests::test() {
|
|
|
Test test("Network");
|
|
|
- testConnect(test, PacketType::UNSEQUENCED);
|
|
|
- testConnect(test, PacketType::RELIABLE);
|
|
|
- testConnect(test, PacketType::SEQUENCED);
|
|
|
+ testConnect(test, PacketSendMode::UNSEQUENCED);
|
|
|
+ testConnect(test, PacketSendMode::RELIABLE);
|
|
|
+ testConnect(test, PacketSendMode::SEQUENCED);
|
|
|
testDisconnect(test);
|
|
|
testStop(test);
|
|
|
test.finalize();
|