From: Daniel Karbach Date: Tue, 22 Sep 2015 06:53:53 +0000 (+0200) Subject: unit test for EntityUpdate packet X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=76e18c781bce6ac14768f0d63dee33c3268f1e9b;p=blank.git unit test for EntityUpdate packet wow, this one actually helped. what happened? --- diff --git a/tst/net/PacketTest.cpp b/tst/net/PacketTest.cpp index a95090a..4789402 100644 --- a/tst/net/PacketTest.cpp +++ b/tst/net/PacketTest.cpp @@ -235,6 +235,50 @@ void PacketTest::testDespawnEntity() { ); } +void PacketTest::testEntityUpdate() { + auto pack = Packet::Make(udp_pack); + AssertPacket("EntityUpdate", 7, 4, 452, pack); + + pack.length = Packet::EntityUpdate::GetSize(3); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "length not correctly set in DespawnEntity packet", + size_t(4 + 3 * 68), pack.length + ); + + uint32_t write_count = 3; + uint32_t read_count; + pack.WriteEntityCount(write_count); + pack.ReadEntityCount(read_count); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "entity count not correctly transported in EntityUpdate packet", + write_count, read_count + ); + + Entity write_entity; + write_entity.ID(8567234); + write_entity.GetState().chunk_pos = { 7, 2, -3 }; + write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f }; + write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f }; + write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f }; + write_entity.GetState().ang_vel = { 0.01f, 0.00302f, 0.0985f }; + pack.WriteEntity(write_entity, 1); + pack.WriteEntity(write_entity, 0); + pack.WriteEntity(write_entity, 2); + + uint32_t read_id; + EntityState read_state; + pack.ReadEntityID(read_id, 1); + pack.ReadEntityState(read_state, 1); + CPPUNIT_ASSERT_EQUAL_MESSAGE( + "entity ID not correctly transported in EntityUpdate packet", + write_entity.ID(), read_id + ); + AssertEqual( + "entity state not correctly transported in EntityUpdate packet", + write_entity.GetState(), read_state + ); +} + void PacketTest::AssertPacket( const string &name, diff --git a/tst/net/PacketTest.hpp b/tst/net/PacketTest.hpp index 618df1e..4942a2a 100644 --- a/tst/net/PacketTest.hpp +++ b/tst/net/PacketTest.hpp @@ -28,6 +28,7 @@ CPPUNIT_TEST(testPart); CPPUNIT_TEST(testPlayerUpdate); CPPUNIT_TEST(testSpawnEntity); CPPUNIT_TEST(testDespawnEntity); +CPPUNIT_TEST(testEntityUpdate); CPPUNIT_TEST_SUITE_END(); @@ -43,6 +44,7 @@ public: void testPlayerUpdate(); void testSpawnEntity(); void testDespawnEntity(); + void testEntityUpdate(); private: static void AssertPacket(