]> git.localhorst.tv Git - blank.git/blob - tst/net/PacketTest.cpp
treat head pitch and yaw as entity state
[blank.git] / tst / net / PacketTest.cpp
1 #include "PacketTest.hpp"
2
3 #include "model/Model.hpp"
4 #include "world/Entity.hpp"
5
6 CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::PacketTest);
7
8 using namespace std;
9
10 namespace blank {
11 namespace test {
12
13 void PacketTest::setUp() {
14         udp_pack.data = new Uint8[sizeof(Packet)];
15         udp_pack.maxlen = sizeof(Packet);
16 }
17
18 void PacketTest::tearDown() {
19         delete[] udp_pack.data;
20 }
21
22 namespace {
23
24 static constexpr uint32_t TEST_TAG = 0xFB1AB1AF;
25
26 }
27
28 void PacketTest::testSizes() {
29         CPPUNIT_ASSERT_EQUAL_MESSAGE(
30                 "unexpected size of vec3",
31                 size_t(12), sizeof(glm::vec3)
32         );
33         CPPUNIT_ASSERT_EQUAL_MESSAGE(
34                 "unexpected size of vec3i",
35                 size_t(12), sizeof(glm::ivec3)
36         );
37 }
38
39 void PacketTest::testControl() {
40         Packet::TControl ctrl{ 0, 10, 0 };
41
42         CPPUNIT_ASSERT_MESSAGE(
43                 "TControl should ack the packet in the ack field",
44                 ctrl.Acks(10)
45         );
46         CPPUNIT_ASSERT_MESSAGE(
47                 "TControl should ack the packet in the future",
48                 !ctrl.Acks(11)
49         );
50         CPPUNIT_ASSERT_MESSAGE(
51                 "TControl should not ack a packet in the distant past",
52                 !ctrl.Acks(-30)
53         );
54         CPPUNIT_ASSERT_MESSAGE(
55                 "TControl should not ack the previous packet if the bitfield is 0",
56                 !ctrl.Acks(9)
57         );
58         CPPUNIT_ASSERT_EQUAL_MESSAGE(
59                 "TControl's acks should begin at the packet in the ack field",
60                 uint16_t(10), ctrl.AckBegin()
61         );
62         CPPUNIT_ASSERT_EQUAL_MESSAGE(
63                 "TControl's acks should end 33 packets before the one in the ack field",
64                 uint16_t(-23), ctrl.AckEnd()
65         );
66         ctrl.hist = 1;
67         CPPUNIT_ASSERT_MESSAGE(
68                 "TControl should ack the previous packet if the bitfield is 1",
69                 ctrl.Acks(9)
70         );
71         ctrl.hist = 2;
72         CPPUNIT_ASSERT_MESSAGE(
73                 "TControl should not ack the previous packet if the bitfield is 2",
74                 !ctrl.Acks(9)
75         );
76         CPPUNIT_ASSERT_MESSAGE(
77                 "TControl should ack the packet before the previous one if the bitfield is 2",
78                 ctrl.Acks(8)
79         );
80 }
81
82 void PacketTest::testPing() {
83         auto pack = Packet::Make<Packet::Ping>(udp_pack);
84         AssertPacket("Ping", 0, 0, pack);
85 }
86
87 void PacketTest::testLogin() {
88         auto pack = Packet::Make<Packet::Login>(udp_pack);
89         AssertPacket("Login", 1, 0, 32, pack);
90
91         string write_name = "test";
92         string read_name;
93         pack.WritePlayerName(write_name);
94         pack.ReadPlayerName(read_name);
95         CPPUNIT_ASSERT_EQUAL_MESSAGE(
96                 "player name not correctly transported in Login packet",
97                 write_name, read_name
98         );
99
100         write_name = "0123456789012345678901234567890123456789";
101         pack.WritePlayerName(write_name);
102         pack.ReadPlayerName(read_name);
103         CPPUNIT_ASSERT_EQUAL_MESSAGE(
104                 "player name not correctly truncated in Login packet",
105                 write_name.substr(0, 32), read_name
106         );
107 }
108
109 void PacketTest::testJoin() {
110         auto pack = Packet::Make<Packet::Join>(udp_pack);
111         AssertPacket("Join", 2, 47, 78, pack);
112
113         Entity write_entity;
114         write_entity.ID(534574);
115         write_entity.GetState().chunk_pos = { 7, 2, -3 };
116         write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f };
117         write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f };
118         write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f };
119         write_entity.GetState().pitch = 0.3f;
120         write_entity.GetState().yaw = -2.3f;
121         uint32_t read_id = 0;
122         EntityState read_state;
123         pack.WritePlayer(write_entity);
124
125         pack.ReadPlayerID(read_id);
126         CPPUNIT_ASSERT_EQUAL_MESSAGE(
127                 "player entity ID not correctly transported in Join packet",
128                 write_entity.ID(), read_id
129         );
130         pack.ReadPlayerState(read_state);
131         AssertEqual(
132                 "player entity state not correctly transported in Join packet",
133                 write_entity.GetState(), read_state
134         );
135
136         string write_name = "test";
137         string read_name;
138         pack.WriteWorldName(write_name);
139         pack.ReadWorldName(read_name);
140         CPPUNIT_ASSERT_EQUAL_MESSAGE(
141                 "world name not correctly transported in Join packet",
142                 write_name, read_name
143         );
144
145         write_name = "0123456789012345678901234567890123456789";
146         pack.WriteWorldName(write_name);
147         pack.ReadWorldName(read_name);
148         CPPUNIT_ASSERT_EQUAL_MESSAGE(
149                 "world name not correctly truncated in Join packet",
150                 write_name.substr(0, 32), read_name
151         );
152 }
153
154 void PacketTest::testPart() {
155         auto pack = Packet::Make<Packet::Part>(udp_pack);
156         AssertPacket("Part", 3, 0, pack);
157 }
158
159 void PacketTest::testPlayerUpdate() {
160         auto pack = Packet::Make<Packet::PlayerUpdate>(udp_pack);
161         AssertPacket("PlayerUpdate", 4, 50, pack);
162
163         EntityState write_state;
164         write_state.chunk_pos = { 7, 2, -3 };
165         write_state.block_pos = { 1.5f, 0.9f, 12.0f };
166         write_state.velocity = { 0.025f, 0.001f, 0.0f };
167         write_state.orient = { 1.0f, 0.0f, 0.0f, 0.0f };
168         glm::vec3 write_movement(0.5f, -1.0f, 1.0f);
169         uint8_t write_actions = 0x05;
170         uint8_t write_slot = 3;
171         pack.WritePredictedState(write_state);
172         pack.WriteMovement(write_movement);
173         pack.WriteActions(write_actions);
174         pack.WriteSlot(write_slot);
175
176         EntityState read_state;
177         glm::vec3 read_movement;
178         uint8_t read_actions;
179         uint8_t read_slot;
180         pack.ReadPredictedState(read_state);
181         pack.ReadMovement(read_movement);
182         pack.ReadActions(read_actions);
183         pack.ReadSlot(read_slot);
184         AssertEqual(
185                 "player predicted entity state not correctly transported in PlayerUpdate packet",
186                 write_state, read_state
187         );
188         AssertEqual(
189                 "player movement input not correctly transported in PlayerUpdate packet",
190                 write_movement, read_movement, 0.0001f
191         );
192         CPPUNIT_ASSERT_EQUAL_MESSAGE(
193                 "player actions not correctly transported in PlayerUpdate packet",
194                 int(write_actions), int(read_actions)
195         );
196         CPPUNIT_ASSERT_EQUAL_MESSAGE(
197                 "player inventory slot not correctly transported in PlayerUpdate packet",
198                 int(write_slot), int(read_slot)
199         );
200 }
201
202 void PacketTest::testSpawnEntity() {
203         auto pack = Packet::Make<Packet::SpawnEntity>(udp_pack);
204         AssertPacket("SpawnEntity", 5, 79, 110, pack);
205
206         Entity write_entity;
207         write_entity.ID(534574);
208         Model model;
209         model.ID(23);
210         model.Instantiate(write_entity.GetModel());
211         write_entity.GetState().chunk_pos = { 7, 2, -3 };
212         write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f };
213         write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f };
214         write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f };
215         write_entity.GetState().pitch = 0.3f;
216         write_entity.GetState().yaw = -2.3f;
217         write_entity.Bounds({{ -1, -1, -1 }, { 1, 1, 1 }});
218         write_entity.WorldCollidable(true);
219         write_entity.Name("blah");
220         pack.WriteEntity(write_entity);
221
222         uint32_t entity_id;
223         uint32_t model_id;
224         Entity read_entity;
225         pack.ReadEntityID(entity_id);
226         pack.ReadModelID(model_id);
227         pack.ReadEntity(read_entity);
228
229         CPPUNIT_ASSERT_EQUAL_MESSAGE(
230                 "entity ID not correctly transported in SpawnEntity packet",
231                 write_entity.ID(), entity_id
232         );
233         CPPUNIT_ASSERT_EQUAL_MESSAGE(
234                 "model ID not correctly transported in SpawnEntity packet",
235                 write_entity.GetModel().GetModel().ID(), model_id
236         );
237         AssertEqual(
238                 "entity state not correctly transported in PlayerUpdate packet",
239                 write_entity.GetState(), read_entity.GetState()
240         );
241         AssertEqual(
242                 "entity bounds not correctly transported in PlayerUpdate packet",
243                 write_entity.Bounds(), read_entity.Bounds()
244         );
245         CPPUNIT_ASSERT_MESSAGE(
246                 "entity flags not correctly transported in SpawnEntity packet",
247                 read_entity.WorldCollidable()
248         );
249         CPPUNIT_ASSERT_EQUAL_MESSAGE(
250                 "entity name not correctly transported in SpawnEntity packet",
251                 write_entity.Name(), read_entity.Name()
252         );
253 }
254
255 void PacketTest::testDespawnEntity() {
256         auto pack = Packet::Make<Packet::DespawnEntity>(udp_pack);
257         AssertPacket("DespawnEntity", 6, 4, pack);
258
259         uint32_t write_id = 5437;
260         uint32_t read_id;
261         pack.WriteEntityID(write_id);
262         pack.ReadEntityID(read_id);
263
264         CPPUNIT_ASSERT_EQUAL_MESSAGE(
265                 "entity ID not correctly transported in DespawnEntity packet",
266                 write_id, read_id
267         );
268 }
269
270 void PacketTest::testEntityUpdate() {
271         auto pack = Packet::Make<Packet::EntityUpdate>(udp_pack);
272         AssertPacket("EntityUpdate", 7, 16, 460, pack);
273
274         pack.length = Packet::EntityUpdate::GetSize(3);
275         CPPUNIT_ASSERT_EQUAL_MESSAGE(
276                 "length not correctly set in EntityUpdate packet",
277                 size_t(16 + 3 * 37), pack.length
278         );
279
280         uint32_t write_count = 3;
281         glm::ivec3 write_base(8, -15, 1);
282         pack.WriteEntityCount(write_count);
283         pack.WriteChunkBase(write_base);
284
285         uint32_t read_count;
286         glm::ivec3 read_base;
287         pack.ReadEntityCount(read_count);
288         pack.ReadChunkBase(read_base);
289
290         CPPUNIT_ASSERT_EQUAL_MESSAGE(
291                 "entity count not correctly transported in EntityUpdate packet",
292                 write_count, read_count
293         );
294         AssertEqual(
295                 "chunk base not correctly transported in EntityUpdate packet",
296                 write_base, read_base
297         );
298
299         Entity write_entity;
300         write_entity.ID(8567234);
301         write_entity.GetState().chunk_pos = { 7, 2, -3 };
302         write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f };
303         write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f };
304         write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f };
305         write_entity.GetState().pitch = 0.3f;
306         write_entity.GetState().yaw = -2.3f;
307         pack.WriteEntity(write_entity, write_base, 1);
308         pack.WriteEntity(write_entity, write_base, 0);
309         pack.WriteEntity(write_entity, write_base, 2);
310
311         uint32_t read_id;
312         EntityState read_state;
313         pack.ReadEntityID(read_id, 1);
314         pack.ReadEntityState(read_state, write_base, 1);
315         CPPUNIT_ASSERT_EQUAL_MESSAGE(
316                 "entity ID not correctly transported in EntityUpdate packet",
317                 write_entity.ID(), read_id
318         );
319         AssertEqual(
320                 "entity state not correctly transported in EntityUpdate packet",
321                 write_entity.GetState(), read_state
322         );
323 }
324
325 void PacketTest::testPlayerCorrection() {
326         auto pack = Packet::Make<Packet::PlayerCorrection>(udp_pack);
327         AssertPacket("PlayerCorrection", 8, 44, pack);
328
329         uint16_t write_seq = 50050;
330         uint16_t read_seq;
331         pack.WritePacketSeq(write_seq);
332         pack.ReadPacketSeq(read_seq);
333         CPPUNIT_ASSERT_EQUAL_MESSAGE(
334                 "packet sequence not correctly transported in PlayerCorrection packet",
335                 write_seq, read_seq
336         );
337
338         Entity write_entity;
339         write_entity.GetState().chunk_pos = { 7, 2, -3 };
340         write_entity.GetState().block_pos = { 1.5f, 0.9f, 12.0f };
341         write_entity.GetState().velocity = { 0.025f, 0.001f, 0.0f };
342         write_entity.GetState().orient = { 1.0f, 0.0f, 0.0f, 0.0f };
343         write_entity.GetState().pitch = 0.3f;
344         write_entity.GetState().yaw = -2.3f;
345         pack.WritePlayer(write_entity);
346
347         EntityState read_state;
348         pack.ReadPlayerState(read_state);
349         AssertEqual(
350                 "entity state not correctly transported in PlayerCorrection packet",
351                 write_entity.GetState(), read_state
352         );
353 }
354
355 void PacketTest::testChunkBegin() {
356         auto pack = Packet::Make<Packet::ChunkBegin>(udp_pack);
357         AssertPacket("ChunkBegin", 9, 24, pack);
358
359         uint32_t write_id = 532;
360         uint32_t write_flags = 9864328;
361         glm::ivec3 write_pos = { -6, 15, 38 };
362         uint32_t write_size = 4097;
363
364         pack.WriteTransmissionId(write_id);
365         pack.WriteFlags(write_flags);
366         pack.WriteChunkCoords(write_pos);
367         pack.WriteDataSize(write_size);
368
369         uint32_t read_id;
370         uint32_t read_flags;
371         glm::ivec3 read_pos;
372         uint32_t read_size;
373
374         pack.ReadTransmissionId(read_id);
375         pack.ReadFlags(read_flags);
376         pack.ReadChunkCoords(read_pos);
377         pack.ReadDataSize(read_size);
378
379         CPPUNIT_ASSERT_EQUAL_MESSAGE(
380                 "transmission ID not correctly transported in ChunkBegin packet",
381                 write_id, read_id
382         );
383         CPPUNIT_ASSERT_EQUAL_MESSAGE(
384                 "flags not correctly transported in ChunkBegin packet",
385                 write_flags, read_flags
386         );
387         AssertEqual(
388                 "chunk coordinates not correctly transported in ChunkBegin packet",
389                 write_pos, read_pos
390         );
391         CPPUNIT_ASSERT_EQUAL_MESSAGE(
392                 "data size not correctly transported in ChunkBegin packet",
393                 write_size, read_size
394         );
395 }
396
397 void PacketTest::testChunkData() {
398         auto pack = Packet::Make<Packet::ChunkData>(udp_pack);
399         AssertPacket("ChunkData", 10, 12, 484, pack);
400
401         constexpr size_t block_size = 97;
402
403         uint32_t write_id = 6743124;
404         uint32_t write_offset = 8583;
405         uint32_t write_size = block_size;
406         uint8_t write_data[block_size];
407         memset(write_data, 'X', block_size);
408
409         pack.WriteTransmissionId(write_id);
410         pack.WriteDataOffset(write_offset);
411         pack.WriteDataSize(write_size);
412         pack.WriteData(write_data, write_size);
413
414         uint32_t read_id;
415         uint32_t read_offset;
416         uint32_t read_size;
417         uint8_t read_data[block_size];
418
419         pack.ReadTransmissionId(read_id);
420         pack.ReadDataOffset(read_offset);
421         pack.ReadDataSize(read_size);
422         pack.ReadData(read_data, read_size);
423
424         CPPUNIT_ASSERT_EQUAL_MESSAGE(
425                 "transmission ID not correctly transported in ChunkData packet",
426                 write_id, read_id
427         );
428         CPPUNIT_ASSERT_EQUAL_MESSAGE(
429                 "data offset not correctly transported in ChunkData packet",
430                 write_offset, read_offset
431         );
432         CPPUNIT_ASSERT_EQUAL_MESSAGE(
433                 "data size not correctly transported in ChunkData packet",
434                 write_size, read_size
435         );
436         CPPUNIT_ASSERT_EQUAL_MESSAGE(
437                 "raw data not correctly transported in ChunkData packet",
438                 string(write_data, write_data + write_size), string(read_data, read_data + read_size)
439         );
440 }
441
442 void PacketTest::testBlockUpdate() {
443         auto pack = Packet::Make<Packet::BlockUpdate>(udp_pack);
444         AssertPacket("BlockUpdate", 11, 16, 484, pack);
445
446         pack.length = Packet::BlockUpdate::GetSize(3);
447         CPPUNIT_ASSERT_EQUAL_MESSAGE(
448                 "length not correctly set in BlockUpdate packet",
449                 size_t(16 + 3 * 6), pack.length
450         );
451
452         glm::ivec3 write_coords(432, -325, 99998);
453         uint32_t write_count = 3;
454         uint16_t write_index = 432;
455         Block write_block(324, Block::FACE_DOWN, Block::TURN_AROUND);
456
457         pack.WriteChunkCoords(write_coords);
458         pack.WriteBlockCount(write_count);
459         pack.WriteIndex(write_index, 1);
460         pack.WriteBlock(write_block, 1);
461         pack.WriteIndex(write_index, 0);
462         pack.WriteBlock(write_block, 0);
463         pack.WriteIndex(write_index, 2);
464         pack.WriteBlock(write_block, 2);
465
466         glm::ivec3 read_coords;
467         uint32_t read_count;
468         uint16_t read_index;
469         Block read_block;
470
471         pack.ReadChunkCoords(read_coords);
472         pack.ReadBlockCount(read_count);
473         pack.ReadIndex(read_index, 1);
474         pack.ReadBlock(read_block, 1);
475
476         AssertEqual(
477                 "chunk coordinates not correctly transported in BlockUpdate packet",
478                 write_coords, read_coords
479         );
480         CPPUNIT_ASSERT_EQUAL_MESSAGE(
481                 "block count not correctly transported in BlockUpdate packet",
482                 write_count, read_count
483         );
484         CPPUNIT_ASSERT_EQUAL_MESSAGE(
485                 "block index not correctly transported in BlockUpdate packet",
486                 write_index, read_index
487         );
488         CPPUNIT_ASSERT_EQUAL_MESSAGE(
489                 "block type not correctly transported in BlockUpdate packet",
490                 write_block.type, read_block.type
491         );
492         CPPUNIT_ASSERT_EQUAL_MESSAGE(
493                 "block face not correctly transported in BlockUpdate packet",
494                 write_block.GetFace(), read_block.GetFace()
495         );
496         CPPUNIT_ASSERT_EQUAL_MESSAGE(
497                 "block turn not correctly transported in BlockUpdate packet",
498                 write_block.GetTurn(), read_block.GetTurn()
499         );
500 }
501
502 void PacketTest::testMessage() {
503         auto pack = Packet::Make<Packet::Message>(udp_pack);
504         AssertPacket("Message", 12, 6, 455, pack);
505
506         const uint8_t write_type = 1;
507         const uint32_t write_ref = 6433235;
508         const string write_msg("hello, world");
509
510         pack.length = Packet::Message::GetSize(write_msg);
511         CPPUNIT_ASSERT_EQUAL_MESSAGE(
512                 "length not correctly set in BlockUpdate packet",
513                 size_t(5 + write_msg.size() + 1), pack.length
514         );
515
516         pack.WriteType(write_type);
517         pack.WriteReferral(write_ref);
518         pack.WriteMessage(write_msg);
519
520         uint8_t read_type = 5;
521         uint32_t read_ref = 884373;
522         string read_msg;
523
524         pack.ReadType(read_type);
525         pack.ReadReferral(read_ref);
526         pack.ReadMessage(read_msg);
527
528         CPPUNIT_ASSERT_EQUAL_MESSAGE(
529                 "type not correctly transported in Message packet",
530                 write_type, read_type
531         );
532         CPPUNIT_ASSERT_EQUAL_MESSAGE(
533                 "referral not correctly transported in Message packet",
534                 write_ref, read_ref
535         );
536         CPPUNIT_ASSERT_EQUAL_MESSAGE(
537                 "message not correctly transported in Message packet",
538                 write_msg, read_msg
539         );
540 }
541
542
543 void PacketTest::AssertPacket(
544         const string &name,
545         uint8_t expected_type,
546         size_t expected_length,
547         const Packet::Payload &actual
548 ) {
549         CPPUNIT_ASSERT_EQUAL_MESSAGE(
550                 name + " packet not correctly tagged",
551                 TEST_TAG, actual.GetHeader().tag
552         );
553         CPPUNIT_ASSERT_EQUAL_MESSAGE(
554                 "wrong type code for " + name + " packet",
555                 int(expected_type), int(actual.GetHeader().type)
556         );
557         CPPUNIT_ASSERT_EQUAL_MESSAGE(
558                 "bad payload length for " + name + " packet",
559                 expected_length, actual.length
560         );
561 }
562
563 void PacketTest::AssertPacket(
564         const string &name,
565         uint8_t expected_type,
566         size_t min_length,
567         size_t max_length,
568         const Packet::Payload &actual
569 ) {
570         CPPUNIT_ASSERT_EQUAL_MESSAGE(
571                 name + " packet not correctly tagged",
572                 TEST_TAG, actual.GetHeader().tag
573         );
574         CPPUNIT_ASSERT_EQUAL_MESSAGE(
575                 "wrong type code for " + name + " packet",
576                 expected_type, actual.GetHeader().type
577         );
578         CPPUNIT_ASSERT_MESSAGE(
579                 "bad payload length for " + name + " packet",
580                 actual.length >= min_length && actual.length <= max_length
581         );
582 }
583
584 void PacketTest::AssertEqual(
585         const string &message,
586         const EntityState &expected,
587         const EntityState &actual
588 ) {
589         AssertEqual(
590                 message + ": bad chunk position",
591                 expected.chunk_pos, actual.chunk_pos
592         );
593         AssertEqual(
594                 message + ": bad block position",
595                 expected.block_pos, actual.block_pos, 16.0f/65535.0f // that's about the max accuracy that packing's going to give us
596         );
597         AssertEqual(
598                 message + ": bad velocity",
599                 expected.velocity, actual.velocity
600         );
601         AssertEqual(
602                 message + ": bad orientation",
603                 expected.orient, actual.orient
604         );
605         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
606                 message + ": bad pitch",
607                 expected.pitch, actual.pitch, PI/65534.0f
608         );
609         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
610                 message + ": bad yaw",
611                 expected.yaw, actual.yaw, PI/32767.0f
612         );
613 }
614
615 void PacketTest::AssertEqual(
616         const string &message,
617         const AABB &expected,
618         const AABB &actual
619 ) {
620         AssertEqual(
621                 message + ": bad lower bound",
622                 expected.min, actual.min
623         );
624         AssertEqual(
625                 message + ": bad upper bound",
626                 expected.max, actual.max
627         );
628 }
629
630 void PacketTest::AssertEqual(
631         const string &message,
632         const glm::ivec3 &expected,
633         const glm::ivec3 &actual
634 ) {
635         CPPUNIT_ASSERT_EQUAL_MESSAGE(
636                 message + " (X component)",
637                 expected.x, actual.x
638         );
639         CPPUNIT_ASSERT_EQUAL_MESSAGE(
640                 message + " (Y component)",
641                 expected.y, actual.y
642         );
643         CPPUNIT_ASSERT_EQUAL_MESSAGE(
644                 message + " (Z component)",
645                 expected.z, actual.z
646         );
647 }
648
649 void PacketTest::AssertEqual(
650         const string &message,
651         const glm::vec3 &expected,
652         const glm::vec3 &actual,
653         float epsilon
654 ) {
655         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
656                 message + " (X component)",
657                 expected.x, actual.x, epsilon
658         );
659         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
660                 message + " (Y component)",
661                 expected.y, actual.y, epsilon
662         );
663         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
664                 message + " (Z component)",
665                 expected.z, actual.z, epsilon
666         );
667 }
668
669 void PacketTest::AssertEqual(
670         const string &message,
671         const glm::quat &expected,
672         const glm::quat &actual
673 ) {
674         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
675                 message + " (W component)",
676                 expected.w, actual.w, numeric_limits<float>::epsilon()
677         );
678         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
679                 message + " (X component)",
680                 expected.x, actual.x, numeric_limits<float>::epsilon()
681         );
682         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
683                 message + " (Y component)",
684                 expected.y, actual.y, numeric_limits<float>::epsilon()
685         );
686         CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
687                 message + " (Z component)",
688                 expected.z, actual.z, numeric_limits<float>::epsilon()
689         );
690 }
691
692 }
693 }