]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/unittest/test_connection.cpp
Fix bone-attached entities (#10015)
[dragonfireclient.git] / src / unittest / test_connection.cpp
index 3ea3d74447982490c3a76426357e07a67fded464..c5e4085e1de4c380ac1137c6928d204239286815 100644 (file)
@@ -20,10 +20,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "test.h"
 
 #include "log.h"
-#include "socket.h"
+#include "porting.h"
 #include "settings.h"
 #include "util/serialize.h"
 #include "network/connection.h"
+#include "network/networkpacket.h"
+#include "network/socket.h"
 
 class TestConnection : public TestBase {
 public:
@@ -80,7 +82,7 @@ void TestConnection::testHelpers()
 {
        // Some constants for testing
        u32 proto_id = 0x12345678;
-       u16 peer_id = 123;
+       session_t peer_id = 123;
        u8 channel = 2;
        SharedBuffer<u8> data1(1);
        data1[0] = 100;
@@ -93,7 +95,7 @@ void TestConnection::testHelpers()
                We should now have a packet with this data:
                Header:
                        [0] u32 protocol_id
-                       [4] u16 sender_peer_id
+                       [4] session_t sender_peer_id
                        [6] u8 channel
                Data:
                        [7] u8 data1[0]
@@ -114,7 +116,7 @@ void TestConnection::testHelpers()
        infostream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
 
        UASSERT(p2.getSize() == 3 + data1.getSize());
-       UASSERT(readU8(&p2[0]) == TYPE_RELIABLE);
+       UASSERT(readU8(&p2[0]) == con::PACKET_TYPE_RELIABLE);
        UASSERT(readU16(&p2[1]) == seqnum);
        UASSERT(readU8(&p2[3]) == data1[0]);
 }
@@ -122,8 +124,6 @@ void TestConnection::testHelpers()
 
 void TestConnection::testConnectSendReceive()
 {
-       DSTACK("TestConnection::Run");
-
        /*
                Test some real connections
 
@@ -245,7 +245,7 @@ void TestConnection::testConnectSendReceive()
                NetworkPacket pkt;
                pkt.putRawPacket((u8*) "Hello World !", 14, 0);
 
-               Buffer<u8> sentdata = pkt.oldForgePacket();
+               SharedBuffer<u8> sentdata = pkt.oldForgePacket();
 
                infostream<<"** running client.Send()"<<std::endl;
                client.Send(PEER_ID_SERVER, 0, &pkt, true);
@@ -260,12 +260,12 @@ void TestConnection::testConnectSendReceive()
                                << ", data=" << (const char*)pkt.getU8Ptr(0)
                                << std::endl;
 
-               Buffer<u8> recvdata = pkt.oldForgePacket();
+               SharedBuffer<u8> recvdata = pkt.oldForgePacket();
 
                UASSERT(memcmp(*sentdata, *recvdata, recvdata.getSize()) == 0);
        }
 
-       u16 peer_id_client = 2;
+       session_t peer_id_client = 2;
        /*
                Send a large packet
        */
@@ -281,7 +281,7 @@ void TestConnection::testConnectSendReceive()
                        if (i % 2 == 0)
                                infostream << " ";
                        char buf[10];
-                       snprintf(buf, 10, "%.2X",
+                       porting::mt_snprintf(buf, sizeof(buf), "%.2X",
                                ((int)((const char *)pkt.getU8Ptr(0))[i]) & 0xff);
                        infostream<<buf;
                }
@@ -289,15 +289,15 @@ void TestConnection::testConnectSendReceive()
                        infostream << "...";
                infostream << std::endl;
 
-               Buffer<u8> sentdata = pkt.oldForgePacket();
+               SharedBuffer<u8> sentdata = pkt.oldForgePacket();
 
                server.Send(peer_id_client, 0, &pkt, true);
 
                //sleep_ms(3000);
 
-               Buffer<u8> recvdata;
+               SharedBuffer<u8> recvdata;
                infostream << "** running client.Receive()" << std::endl;
-               u16 peer_id = 132;
+               session_t peer_id = 132;
                u16 size = 0;
                bool received = false;
                u64 timems0 = porting::getTimeMs();
@@ -324,7 +324,7 @@ void TestConnection::testConnectSendReceive()
                        if (i % 2 == 0)
                                infostream << " ";
                        char buf[10];
-                       snprintf(buf, 10, "%.2X", ((int)(recvdata[i])) & 0xff);
+                       porting::mt_snprintf(buf, sizeof(buf), "%.2X", ((int)(recvdata[i])) & 0xff);
                        infostream << buf;
                }
                if (size > 20)