X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=tst%2Fnet%2FPacketTest.cpp;h=5b6deed47974c1285f679d824d227ab603a0bc3d;hb=ca90ec459ca0bd48c1483a45f30496aed61e9c21;hp=42d83480610f14842857ec8a52f78b60b0441247;hpb=c1da86ebab41895bf49ed747c75ecf722e8c5586;p=blank.git diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index 42d8348..5b6deed 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -1,6 +1,6 @@ #include "PacketTest.hpp" -#include "model/CompositeModel.hpp" +#include "model/Model.hpp" #include "world/Entity.hpp" CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::PacketTest); @@ -25,9 +25,27 @@ static constexpr uint32_t TEST_TAG = 0xFB1AB1AF; } +void PacketTest::testSizes() { + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected size of vec3", + size_t(12), sizeof(glm::vec3) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected size of vec3i", + size_t(12), sizeof(glm::ivec3) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected size of quat", + size_t(16), sizeof(glm::quat) + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "unexpected size of entity state", + size_t(64), sizeof(EntityState) + ); +} + void PacketTest::testControl() { - Packet::TControl ctrl; - ctrl.ack = 10; + Packet::TControl ctrl{ 0, 10, 0 }; CPPUNIT_ASSERT_MESSAGE( "TControl should ack the packet in the ack field", @@ -211,7 +229,7 @@ void PacketTest::testSpawnEntity() { Entity write_entity; write_entity.ID(534574); - CompositeModel model; + Model model; model.ID(23); model.Instantiate(write_entity.GetModel()); write_entity.GetState().chunk_pos = { 7, 2, -3 }; @@ -278,7 +296,7 @@ void PacketTest::testEntityUpdate() { pack.length = Packet::EntityUpdate::GetSize(3); CPPUNIT_ASSERT_EQUAL_MESSAGE( - "length not correctly set in DespawnEntity packet", + "length not correctly set in EntityUpdate packet", size_t(4 + 3 * 68), pack.length ); @@ -432,6 +450,106 @@ void PacketTest::testChunkData() { ); } +void PacketTest::testBlockUpdate() { + auto pack = Packet::Make(udp_pack); + AssertPacket("BlockUpdate", 11, 16, 484, pack); + + pack.length = Packet::BlockUpdate::GetSize(3); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "length not correctly set in BlockUpdate packet", + size_t(16 + 3 * 6), pack.length + ); + + glm::ivec3 write_coords(432, -325, 99998); + uint32_t write_count = 3; + uint16_t write_index = 432; + Block write_block(324, Block::FACE_DOWN, Block::TURN_AROUND); + + pack.WriteChunkCoords(write_coords); + pack.WriteBlockCount(write_count); + pack.WriteIndex(write_index, 1); + pack.WriteBlock(write_block, 1); + pack.WriteIndex(write_index, 0); + pack.WriteBlock(write_block, 0); + pack.WriteIndex(write_index, 2); + pack.WriteBlock(write_block, 2); + + glm::ivec3 read_coords; + uint32_t read_count; + uint16_t read_index; + Block read_block; + + pack.ReadChunkCoords(read_coords); + pack.ReadBlockCount(read_count); + pack.ReadIndex(read_index, 1); + pack.ReadBlock(read_block, 1); + + AssertEqual( + "chunk coordinates not correctly transported in BlockUpdate packet", + write_coords, read_coords + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "block count not correctly transported in BlockUpdate packet", + write_count, read_count + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "block index not correctly transported in BlockUpdate packet", + write_index, read_index + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "block type not correctly transported in BlockUpdate packet", + write_block.type, read_block.type + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "block face not correctly transported in BlockUpdate packet", + write_block.GetFace(), read_block.GetFace() + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "block turn not correctly transported in BlockUpdate packet", + write_block.GetTurn(), read_block.GetTurn() + ); +} + +void PacketTest::testMessage() { + auto pack = Packet::Make(udp_pack); + AssertPacket("Message", 12, 6, 455, pack); + + const uint8_t write_type = 1; + const uint32_t write_ref = 6433235; + const string write_msg("hello, world"); + + pack.length = Packet::Message::GetSize(write_msg); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "length not correctly set in BlockUpdate packet", + size_t(5 + write_msg.size() + 1), pack.length + ); + + pack.WriteType(write_type); + pack.WriteReferral(write_ref); + pack.WriteMessage(write_msg); + + uint8_t read_type = 5; + uint32_t read_ref = 884373; + string read_msg; + + pack.ReadType(read_type); + pack.ReadReferral(read_ref); + pack.ReadMessage(read_msg); + + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "type not correctly transported in Message packet", + write_type, read_type + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "referral not correctly transported in Message packet", + write_ref, read_ref + ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "message not correctly transported in Message packet", + write_msg, read_msg + ); +} + void PacketTest::AssertPacket( const string &name,