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