|
@@ -24,7 +24,7 @@ static void testWriteRead(void) {
|
|
|
coreOutPacketWriteI32(&out, -534534);
|
|
|
coreOutPacketWriteFloat(&out, 64564.5346f);
|
|
|
const char s[] = "This is Great";
|
|
|
- coreOutPacketWriteString(&out, s, sizeof(s));
|
|
|
+ coreOutPacketWriteString(&out, s);
|
|
|
|
|
|
CoreInPacket in;
|
|
|
coreInitInPacket(&in, out.data.buffer, out.data.size);
|
|
@@ -61,10 +61,8 @@ static void testWriteRead(void) {
|
|
|
static void testTooShortBuffer(void) {
|
|
|
CoreOutPacket out;
|
|
|
coreInitOutPacket(&out);
|
|
|
- const char s[] = "This is Great";
|
|
|
- coreOutPacketWriteString(&out, s, sizeof(s));
|
|
|
- const char s2[] = "Well hoho";
|
|
|
- coreOutPacketWriteString(&out, s2, sizeof(s2));
|
|
|
+ coreOutPacketWriteString(&out, "This is Great");
|
|
|
+ coreOutPacketWriteString(&out, "Well hoho");
|
|
|
|
|
|
CoreInPacket in;
|
|
|
coreInitInPacket(&in, out.data.buffer, out.data.size);
|
|
@@ -118,52 +116,87 @@ static void testShortString(void) {
|
|
|
coreDestroyOutPacket(&out);
|
|
|
}
|
|
|
|
|
|
-/*static bool checkError(Test& test, const Error e, const char* msg) {
|
|
|
- if(e.has()) {
|
|
|
- test.checkFalse(true, msg);
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
-}
|
|
|
-
|
|
|
static void tickClient(int ticks) {
|
|
|
for(int i = 0; i < ticks; i++) {
|
|
|
- Client::tick();
|
|
|
+ coreClientTick();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
static void tick(int ticks) {
|
|
|
for(int i = 0; i < ticks; i++) {
|
|
|
- Client::tick();
|
|
|
- Server::tick();
|
|
|
+ coreClientTick();
|
|
|
+ coreServerTick();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static bool clientConnected = false;
|
|
|
+static bool clientDisconnected = false;
|
|
|
+static bool clientPackage = false;
|
|
|
+static int packageCounter = 0;
|
|
|
+static bool serverConnected = false;
|
|
|
+static bool serverDisconnect = false;
|
|
|
+static u8 data1 = 0;
|
|
|
+static u16 data2 = 0;
|
|
|
+static u32 data3 = 0;
|
|
|
+static i8 data4 = 0;
|
|
|
+static i16 data5 = 0;
|
|
|
+static i32 data6 = 0;
|
|
|
+static i8 data7 = 0;
|
|
|
+static i16 data8 = 0;
|
|
|
+static i32 data9 = 0;
|
|
|
+static char data10[20];
|
|
|
+static float data11 = 0.0f;
|
|
|
+
|
|
|
+static void onServerConnect(CoreClient) {
|
|
|
+ serverConnected = true;
|
|
|
+}
|
|
|
+
|
|
|
+static void onServerDisconnect(CoreClient) {
|
|
|
+ serverDisconnect = true;
|
|
|
+}
|
|
|
+
|
|
|
+static void onServerPacket(CoreClient client, CoreInPacket* in) {
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadU8(in, &data1));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadU16(in, &data2));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadU32(in, &data3));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI8(in, &data4));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI16(in, &data5));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI32(in, &data6));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI8(in, &data7));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI16(in, &data8));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadI32(in, &data9));
|
|
|
+ CORE_TEST_SIZE(9, coreInPacketReadString(in, data10, sizeof(data10)));
|
|
|
+ CORE_TEST_FALSE(coreInPacketReadFloat(in, &data11));
|
|
|
+
|
|
|
+ CoreOutPacket out;
|
|
|
+ coreInitOutPacket(&out);
|
|
|
+ if(packageCounter == 0) {
|
|
|
+ coreServerSend(client, &out, CORE_RELIABLE);
|
|
|
+ } else if(packageCounter == 1) {
|
|
|
+ coreServerSend(client, &out, CORE_SEQUENCED);
|
|
|
+ } else if(packageCounter == 2) {
|
|
|
+ coreServerSend(client, &out, CORE_UNSEQUENCED);
|
|
|
}
|
|
|
+ coreDestroyOutPacket(&out);
|
|
|
+ packageCounter++;
|
|
|
+}
|
|
|
+
|
|
|
+static void onClientConnect() {
|
|
|
+ clientConnected = true;
|
|
|
}
|
|
|
|
|
|
-static void testConnect(Test& test, PacketSendMode mode) {
|
|
|
- static bool clientConnected = false;
|
|
|
- static bool clientDisconnected = false;
|
|
|
- static bool clientPackage = false;
|
|
|
+static void onClientDisconnect() {
|
|
|
+ clientDisconnected = true;
|
|
|
+}
|
|
|
+
|
|
|
+static void onClientPacket(CoreInPacket*) {
|
|
|
+ clientPackage = true;
|
|
|
+}
|
|
|
+
|
|
|
+static void testConnect(CorePacketSendMode mode) {
|
|
|
clientConnected = false;
|
|
|
clientDisconnected = false;
|
|
|
clientPackage = false;
|
|
|
-
|
|
|
- static int packageCounter = 0;
|
|
|
- static bool serverConnected = false;
|
|
|
- static bool serverDisconnect = false;
|
|
|
- static uint8 data1 = 0;
|
|
|
- static uint16 data2 = 0;
|
|
|
- static uint32 data3 = 0;
|
|
|
- static int8 data4 = 0;
|
|
|
- static int16 data5 = 0;
|
|
|
- static int32 data6 = 0;
|
|
|
- static int8 data7 = 0;
|
|
|
- static int16 data8 = 0;
|
|
|
- static int32 data9 = 0;
|
|
|
- static StringBuffer<20> data10;
|
|
|
- static float data11 = 0.0f;
|
|
|
- static IntVector3 data12;
|
|
|
- static Vector3 data13;
|
|
|
-
|
|
|
serverConnected = false;
|
|
|
serverDisconnect = false;
|
|
|
data1 = 0;
|
|
@@ -175,158 +208,128 @@ static void testConnect(Test& test, PacketSendMode mode) {
|
|
|
data7 = 0;
|
|
|
data8 = 0;
|
|
|
data9 = 0;
|
|
|
- data10.clear();
|
|
|
+ *data10 = '\0';
|
|
|
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.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, PacketSendMode::RELIABLE);
|
|
|
- } else if(packageCounter == 1) {
|
|
|
- OutPacket out(0);
|
|
|
- Server::send(client, out, PacketSendMode::SEQUENCED);
|
|
|
- } else if(packageCounter == 2) {
|
|
|
- OutPacket out(0);
|
|
|
- Server::send(client, out, PacketSendMode::UNSEQUENCED);
|
|
|
- }
|
|
|
- packageCounter++;
|
|
|
- });
|
|
|
-
|
|
|
- Client::resetHandler();
|
|
|
- Client::setConnectHandler([]() { clientConnected = true; });
|
|
|
- Client::setDisconnectHandler([]() { clientDisconnected = true; });
|
|
|
- Client::setPacketHandler([](InPacket&) { clientPackage = true; });
|
|
|
-
|
|
|
- if(checkError(test, Server::start(54321, 5), "server can initialize")) {
|
|
|
+
|
|
|
+ coreServerResetHandler();
|
|
|
+ coreServerSetConnectHandler(onServerConnect);
|
|
|
+ coreServerSetDisconnectHandler(onServerDisconnect);
|
|
|
+ coreServerSetPacketHandler(onServerPacket);
|
|
|
+
|
|
|
+ coreClientResetHandler();
|
|
|
+ coreClientSetConnectHandler(onClientConnect);
|
|
|
+ coreClientSetDisconnectHandler(onClientDisconnect);
|
|
|
+ coreClientSetPacketHandler(onClientPacket);
|
|
|
+
|
|
|
+ if(!CORE_TEST_FALSE(coreServerStart(54321, 5))) {
|
|
|
return;
|
|
|
- } else if(checkError(test, Client::start(), "client can initialize")) {
|
|
|
+ } else if(!CORE_TEST_FALSE(coreClientStart())) {
|
|
|
return;
|
|
|
- } else if(checkError(test, Client::connect("127.0.0.1", 54321, 90),
|
|
|
- "start connection failed")) {
|
|
|
+ } else if(!CORE_TEST_FALSE(coreClientConnect("127.0.0.1", 54321, 90))) {
|
|
|
return;
|
|
|
}
|
|
|
- test.checkFalse(Client::isConnected(), "client not connected yet");
|
|
|
- test.checkTrue(Client::isConnecting(), "client is connecting");
|
|
|
-
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_TRUE(coreClientIsConnecting());
|
|
|
tick(100);
|
|
|
+ CORE_TEST_TRUE(clientConnected);
|
|
|
+ CORE_TEST_TRUE(coreClientIsConnected());
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnecting());
|
|
|
|
|
|
- test.checkTrue(clientConnected, "client called connect callback");
|
|
|
- test.checkTrue(Client::isConnected(), "client is connected");
|
|
|
- test.checkFalse(Client::isConnecting(), "client is no more connecting");
|
|
|
-
|
|
|
- OutPacket out(50);
|
|
|
- out.writeU8(0xF1).writeU16(0xF123).writeU32(0xF1234567);
|
|
|
- out.writeS8(-0x71).writeS16(-0x7123).writeS32(-0x71234567);
|
|
|
- out.writeS8(0x71).writeS16(0x7123).writeS32(0x71234567);
|
|
|
- StringBuffer<20> s("Hi there");
|
|
|
- out.writeString(s);
|
|
|
- out.writeFloat(252345.983f);
|
|
|
- out.writeVector(IntVector3(1, 2, 3));
|
|
|
- out.writeVector(Vector3(1.5f, 2.5f, 3.5f));
|
|
|
- Client::send(out, mode);
|
|
|
+ CoreOutPacket out;
|
|
|
+ coreInitOutPacket(&out);
|
|
|
+ coreOutPacketWriteU8(&out, 0xF1);
|
|
|
+ coreOutPacketWriteU16(&out, 0xF123);
|
|
|
+ coreOutPacketWriteU32(&out, 0xF1234567);
|
|
|
+ coreOutPacketWriteI8(&out, -0x71);
|
|
|
+ coreOutPacketWriteI16(&out, -0x7123);
|
|
|
+ coreOutPacketWriteI32(&out, -0x71234567);
|
|
|
+ coreOutPacketWriteI8(&out, 0x71);
|
|
|
+ coreOutPacketWriteI16(&out, 0x7123);
|
|
|
+ coreOutPacketWriteI32(&out, 0x71234567);
|
|
|
+ const char s[] = "Hi there";
|
|
|
+ coreOutPacketWriteString(&out, s);
|
|
|
+ coreOutPacketWriteFloat(&out, 252345.983f);
|
|
|
+ coreClientSend(&out, mode);
|
|
|
+ coreDestroyOutPacket(&out);
|
|
|
|
|
|
tick(100);
|
|
|
|
|
|
- test.checkTrue(clientPackage, "client has received data");
|
|
|
- test.checkTrue(serverConnected, "server has connection");
|
|
|
-
|
|
|
- test.checkUnsigned8(0xF1, data1, "correct value is sent 1");
|
|
|
- test.checkUnsigned16(0xF123, data2, "correct value is sent 2");
|
|
|
- test.checkEqual(0xF1234567u, data3, "correct value is sent 3");
|
|
|
- test.checkSigned8(-0x71, data4, "correct value is sent 4");
|
|
|
- test.checkSigned16(-0x7123, data5, "correct value is sent 5");
|
|
|
- test.checkEqual(-0x71234567, data6, "correct value is sent 6");
|
|
|
- test.checkSigned8(0x71, data7, "correct value is sent 7");
|
|
|
- test.checkSigned16(0x7123, data8, "correct value is sent 8");
|
|
|
- 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");
|
|
|
- test.checkFalse(Client::isConnecting(), "client is not connecting");
|
|
|
+ CORE_TEST_TRUE(clientPackage);
|
|
|
+ CORE_TEST_TRUE(serverConnected);
|
|
|
+
|
|
|
+ CORE_TEST_U64(0xF1, data1);
|
|
|
+ CORE_TEST_U64(0xF123, data2);
|
|
|
+ CORE_TEST_U64(0xF1234567, data3);
|
|
|
+ CORE_TEST_I64(-0x71, data4);
|
|
|
+ CORE_TEST_I64(-0x7123, data5);
|
|
|
+ CORE_TEST_I64(-0x71234567, data6);
|
|
|
+ CORE_TEST_I64(0x71, data7);
|
|
|
+ CORE_TEST_I64(0x7123, data8);
|
|
|
+ CORE_TEST_I64(0x71234567, data9);
|
|
|
+ CORE_TEST_STRING(s, data10);
|
|
|
+ CORE_TEST_FLOAT(252345.983f, data11, 0.01f);
|
|
|
+
|
|
|
+ coreClientDisconnect(90);
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnecting());
|
|
|
tick(100);
|
|
|
- test.checkTrue(clientDisconnected, "client has disconnected");
|
|
|
- test.checkTrue(serverDisconnect, "client has disconnected on server");
|
|
|
+ CORE_TEST_TRUE(clientDisconnected);
|
|
|
+ CORE_TEST_TRUE(serverDisconnect);
|
|
|
+
|
|
|
+ coreClientStop();
|
|
|
+ coreServerStop();
|
|
|
+}
|
|
|
+
|
|
|
+static bool disconnected = false;
|
|
|
|
|
|
- Client::stop();
|
|
|
- Server::stop();
|
|
|
+static void testStopDisconnect(void) {
|
|
|
+ disconnected = true;
|
|
|
}
|
|
|
|
|
|
-static void testDisconnect(Test& test) {
|
|
|
- static bool disconnected = false;
|
|
|
+static void testDisconnect(void) {
|
|
|
disconnected = false;
|
|
|
- Client::resetHandler();
|
|
|
- Client::setDisconnectHandler([]() { disconnected = true; });
|
|
|
- if(checkError(test, Client::start(), "client can initialize")) {
|
|
|
+ coreClientResetHandler();
|
|
|
+ coreClientSetDisconnectHandler(testStopDisconnect);
|
|
|
+ if(!CORE_TEST_FALSE(coreClientStart())) {
|
|
|
return;
|
|
|
- } else if(checkError(test, Client::connect("127.0.0.1", 54321, 90),
|
|
|
- "start connection failed")) {
|
|
|
+ } else if(!CORE_TEST_FALSE(coreClientConnect("127.0.0.1", 54321, 90))) {
|
|
|
return;
|
|
|
}
|
|
|
- test.checkFalse(Client::isConnected(), "client not connected yet");
|
|
|
- test.checkTrue(Client::isConnecting(), "client is connecting");
|
|
|
- Client::disconnect(50);
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_TRUE(coreClientIsConnecting());
|
|
|
+ coreClientDisconnect(50);
|
|
|
tickClient(100);
|
|
|
- test.checkFalse(Client::isConnected(), "client was disconnected");
|
|
|
- test.checkFalse(Client::isConnecting(), "client is not connecting");
|
|
|
- test.checkTrue(disconnected, "client has disconnected");
|
|
|
- Client::stop();
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnecting());
|
|
|
+ CORE_TEST_TRUE(disconnected);
|
|
|
+ coreClientStop();
|
|
|
}
|
|
|
|
|
|
-static void testStop(Test& test) {
|
|
|
- static bool disconnected = false;
|
|
|
+static void testStop(void) {
|
|
|
disconnected = false;
|
|
|
- Client::resetHandler();
|
|
|
- Client::setDisconnectHandler([]() { disconnected = true; });
|
|
|
- if(checkError(test, Client::start(), "client can initialize")) {
|
|
|
+ coreClientResetHandler();
|
|
|
+ coreClientSetDisconnectHandler(testStopDisconnect);
|
|
|
+ if(!CORE_TEST_FALSE(coreClientStart())) {
|
|
|
return;
|
|
|
- } else if(checkError(test, Client::connect("127.0.0.1", 54321, 90),
|
|
|
- "start connection failed")) {
|
|
|
+ } else if(!CORE_TEST_FALSE(coreClientConnect("127.0.0.1", 54321, 90))) {
|
|
|
return;
|
|
|
}
|
|
|
- test.checkFalse(Client::isConnected(), "client not connected yet");
|
|
|
- test.checkTrue(Client::isConnecting(), "client is connecting");
|
|
|
- Client::stop();
|
|
|
- test.checkFalse(Client::isConnected(), "client was disconnected");
|
|
|
- test.checkFalse(Client::isConnecting(), "client is not connecting");
|
|
|
- test.checkTrue(disconnected, "client has disconnected");
|
|
|
-}*/
|
|
|
-
|
|
|
-void coreTestNetwork() {
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_TRUE(coreClientIsConnecting());
|
|
|
+ coreClientStop();
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnected());
|
|
|
+ CORE_TEST_FALSE(coreClientIsConnecting());
|
|
|
+ CORE_TEST_TRUE(disconnected);
|
|
|
+}
|
|
|
+
|
|
|
+void coreTestNetwork(void) {
|
|
|
testWriteRead();
|
|
|
testTooShortBuffer();
|
|
|
testBinaryData();
|
|
|
testShortString();
|
|
|
- // testConnect(test, PacketSendMode::UNSEQUENCED);
|
|
|
- // testConnect(test, PacketSendMode::RELIABLE);
|
|
|
- // testConnect(test, PacketSendMode::SEQUENCED);
|
|
|
- // testDisconnect(test);
|
|
|
- // testStop(test);
|
|
|
+ testConnect(CORE_UNSEQUENCED);
|
|
|
+ testConnect(CORE_SEQUENCED);
|
|
|
+ testConnect(CORE_RELIABLE);
|
|
|
+ testDisconnect();
|
|
|
+ testStop();
|
|
|
}
|