]> git.localhorst.tv Git - blank.git/commitdiff
unit test for EntityUpdate packet
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 22 Sep 2015 06:53:53 +0000 (08:53 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 22 Sep 2015 06:53:53 +0000 (08:53 +0200)
wow, this one actually helped. what happened?

tst/net/PacketTest.cpp
tst/net/PacketTest.hpp

index a95090a87978cbe86a21627148eb20fed5b68c0b..478940249ef6d602bc9408aca2585891ddcf3305 100644 (file)
@@ -235,6 +235,50 @@ void PacketTest::testDespawnEntity() {
        );
 }
 
+void PacketTest::testEntityUpdate() {
+       auto pack = Packet::Make<Packet::EntityUpdate>(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,
index 618df1e68d9d75fe3eb8b6377a71473b188ec55a..4942a2a228b59908b8ab8d2c82a4315ecfc601d6 100644 (file)
@@ -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(