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