3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "common_irrlicht.h"
26 #include "heightmap.h"
28 #include "connection.h"
30 #include "serialization.h"
36 #define sleep_ms(x) Sleep(x)
39 #define sleep_ms(x) usleep(x*1000)
43 Asserts that the exception occurs
45 #define EXCEPTION_CHECK(EType, code)\
47 bool exception_thrown = false;\
49 catch(EType &e) { exception_thrown = true; }\
50 assert(exception_thrown);\
57 /*dstream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
58 dstream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
59 dstream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
60 assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
61 assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
62 assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
63 assert(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
64 assert(lowercase("Foo bAR") == "foo bar");
65 assert(is_yes("YeS") == true);
66 assert(is_yes("") == false);
67 assert(is_yes("FAlse") == false);
75 SharedBuffer<u8> fromdata(4);
81 std::ostringstream os(std::ios_base::binary);
82 compress(fromdata, os, 0);
84 std::string str_out = os.str();
86 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
87 dstream<<"TestCompress: 1,5,5,1 -> ";
88 for(u32 i=0; i<str_out.size(); i++)
90 dstream<<(u32)str_out[i]<<",";
94 assert(str_out.size() == 10);
96 assert(str_out[0] == 0);
97 assert(str_out[1] == 0);
98 assert(str_out[2] == 0);
99 assert(str_out[3] == 4);
100 assert(str_out[4] == 0);
101 assert(str_out[5] == 1);
102 assert(str_out[6] == 1);
103 assert(str_out[7] == 5);
104 assert(str_out[8] == 0);
105 assert(str_out[9] == 1);
107 std::istringstream is(str_out, std::ios_base::binary);
108 std::ostringstream os2(std::ios_base::binary);
110 decompress(is, os2, 0);
111 std::string str_out2 = os2.str();
113 dstream<<"decompress: ";
114 for(u32 i=0; i<str_out2.size(); i++)
116 dstream<<(u32)str_out2[i]<<",";
120 assert(str_out2.size() == fromdata.getSize());
122 for(u32 i=0; i<str_out2.size(); i++)
124 assert(str_out2[i] == fromdata[i]);
136 assert(n.d == CONTENT_AIR);
137 assert(n.getLight() == 0);
141 assert(n.light_propagates() == true);
143 assert(n.light_propagates() == false);
147 struct TestVoxelManipulator
155 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
156 assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
157 assert(a.index(-1,-1,-1) == 0);
159 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
160 // An area that is 1 bigger in x+ and z-
161 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
163 core::list<VoxelArea> aa;
167 core::array<VoxelArea> results;
168 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
169 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
171 assert(aa.size() == results.size());
173 dstream<<"Result of diff:"<<std::endl;
174 for(core::list<VoxelArea>::Iterator
175 i = aa.begin(); i != aa.end(); i++)
180 s32 j = results.linear_search(*i);
194 dstream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
196 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
200 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
202 dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
204 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
208 dstream<<"*** Adding area ***"<<std::endl;
214 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
215 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
223 const char *content =
235 v3s16 size(12, 4, 2);
236 VoxelArea area(v3s16(0,0,0), size-v3s16(1,1,1));
238 const char *p = content;
239 for(s16 z=0; z<size.Z; z++)
240 for(s16 y=size.Y-1; y>=0; y--)
241 for(s16 x=0; x<size.X; x++)
244 //n.pressure = size.Y - y;
253 v.setNode(v3s16(x,y,z), n);
257 v.print(dstream, VOXELPRINT_WATERPRESSURE);
259 core::map<v3s16, u8> active_nodes;
260 v.updateAreaWaterPressure(area, active_nodes);
262 v.print(dstream, VOXELPRINT_WATERPRESSURE);
264 s16 highest_y = -32768;
266 NOTE: These are commented out because this behaviour is changed
269 //assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == -1);
270 //assert(highest_y == 3);
271 /*assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == 3);
272 //assert(highest_y == 3);*/
274 active_nodes.clear();
275 active_nodes[v3s16(9,1,0)] = 1;
276 //v.flowWater(active_nodes, 0, false);
277 v.flowWater(active_nodes, 0, true, 1000);
279 dstream<<"Final result of flowWater:"<<std::endl;
280 v.print(dstream, VOXELPRINT_WATERPRESSURE);
288 class TC : public NodeContainer
294 core::list<v3s16> validity_exceptions;
298 position_valid = true;
301 virtual bool isValidPosition(v3s16 p)
303 //return position_valid ^ (p==position_valid_exception);
304 bool exception = false;
305 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
306 i != validity_exceptions.end(); i++)
314 return exception ? !position_valid : position_valid;
317 virtual MapNode getNode(v3s16 p)
319 if(isValidPosition(p) == false)
320 throw InvalidPositionException();
324 virtual void setNode(v3s16 p, MapNode & n)
326 if(isValidPosition(p) == false)
327 throw InvalidPositionException();
330 virtual u16 nodeContainerId() const
340 MapBlock b(&parent, v3s16(1,1,1));
341 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
343 assert(b.getPosRelative() == relpos);
345 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
346 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
347 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
348 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
349 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
350 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
352 assert(b.isValidPosition(v3s16(0,0,0)) == true);
353 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
354 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
355 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
356 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
357 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
360 TODO: this method should probably be removed
361 if the block size isn't going to be set variable
363 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
364 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
366 // Changed flag should be initially set
367 assert(b.getChangedFlag() == true);
368 b.resetChangedFlag();
369 assert(b.getChangedFlag() == false);
371 // All nodes should have been set to
372 // .d=CONTENT_AIR and .getLight() = 0
373 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
374 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
375 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
376 assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
377 assert(b.getNode(v3s16(x,y,z)).getLight() == 0);
381 Parent fetch functions
383 parent.position_valid = false;
388 // Positions in the block should still be valid
389 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
390 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
391 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
392 assert(n.d == CONTENT_AIR);
394 // ...but outside the block they should be invalid
395 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
396 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
397 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
400 bool exception_thrown = false;
402 // This should throw an exception
403 MapNode n = b.getNodeParent(v3s16(0,0,-1));
405 catch(InvalidPositionException &e)
407 exception_thrown = true;
409 assert(exception_thrown);
412 parent.position_valid = true;
413 // Now the positions outside should be valid
414 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
415 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
416 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
417 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
426 assert(b.getNode(p).d == 4);
427 assert(b.getNodeTile(p) == 4);
428 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);
433 // Set lighting of all nodes to 0
434 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
435 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
436 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
437 MapNode n = b.getNode(v3s16(x,y,z));
439 b.setNode(v3s16(x,y,z), n);
445 Check how the block handles being a lonely sky block
447 parent.position_valid = true;
448 b.setIsUnderground(false);
449 parent.node.d = CONTENT_AIR;
450 parent.node.setLight(LIGHT_SUN);
451 core::map<v3s16, bool> light_sources;
452 // The bottom block is invalid, because we have a shadowing node
453 assert(b.propagateSunlight(light_sources) == false);
454 assert(b.getNode(v3s16(1,4,0)).getLight() == LIGHT_SUN);
455 assert(b.getNode(v3s16(1,3,0)).getLight() == LIGHT_SUN);
456 assert(b.getNode(v3s16(1,2,0)).getLight() == 0);
457 assert(b.getNode(v3s16(1,1,0)).getLight() == 0);
458 assert(b.getNode(v3s16(1,0,0)).getLight() == 0);
459 assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
460 assert(b.getFaceLight(p, v3s16(0,1,0)) == LIGHT_SUN);
461 assert(b.getFaceLight(p, v3s16(0,-1,0)) == 0);
462 // According to MapBlock::getFaceLight,
463 // The face on the z+ side should have double-diminished light
464 //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
465 assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
468 Check how the block handles being in between blocks with some non-sunlight
469 while being underground
472 // Make neighbours to exist and set some non-sunlight to them
473 parent.position_valid = true;
474 b.setIsUnderground(true);
475 parent.node.setLight(LIGHT_MAX/2);
476 core::map<v3s16, bool> light_sources;
477 // The block below should be valid because there shouldn't be
478 // sunlight in there either
479 assert(b.propagateSunlight(light_sources) == true);
480 // Should not touch nodes that are not affected (that is, all of them)
481 //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
482 // Should set light of non-sunlighted blocks to 0.
483 assert(b.getNode(v3s16(1,2,3)).getLight() == 0);
486 Set up a situation where:
487 - There is only air in this block
488 - There is a valid non-sunlighted block at the bottom, and
489 - Invalid blocks elsewhere.
490 - the block is not underground.
492 This should result in bottom block invalidity
495 b.setIsUnderground(false);
497 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
498 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
499 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
503 b.setNode(v3s16(x,y,z), n);
507 // Make neighbours invalid
508 parent.position_valid = false;
509 // Add exceptions to the top of the bottom block
510 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
511 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
513 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
515 // Lighting value for the valid nodes
516 parent.node.setLight(LIGHT_MAX/2);
517 core::map<v3s16, bool> light_sources;
518 // Bottom block is not valid
519 assert(b.propagateSunlight(light_sources) == false);
526 class TC : public NodeContainer
535 position_valid = true;
538 virtual bool isValidPosition(v3s16 p)
540 return position_valid;
543 virtual MapNode getNode(v3s16 p)
545 if(position_valid == false)
546 throw InvalidPositionException();
550 virtual void setNode(v3s16 p, MapNode & n)
552 if(position_valid == false)
553 throw InvalidPositionException();
556 virtual u16 nodeContainerId() const
565 parent.position_valid = false;
567 // Create one with no heightmaps
568 ServerMapSector sector(&parent, v2s16(1,1), 0);
569 //ConstantGenerator *dummyheightmap = new ConstantGenerator();
570 //sector->setHeightmap(dummyheightmap);
572 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
573 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1));
575 MapBlock * bref = sector.createBlankBlock(-2);
577 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
578 assert(sector.getBlockNoCreate(-2) == bref);
580 //TODO: Check for AlreadyExistsException
582 /*bool exception_thrown = false;
586 catch(InvalidPositionException &e){
587 exception_thrown = true;
589 assert(exception_thrown);*/
596 void TestSingleFixed()
599 OneChildHeightmap hm1(BS1);
601 // Test that it is filled with < GROUNDHEIGHT_VALID_MINVALUE
602 for(s16 y=0; y<=BS1; y++){
603 for(s16 x=0; x<=BS1; x++){
605 assert(hm1.m_child.getGroundHeight(p)
606 < GROUNDHEIGHT_VALID_MINVALUE);
610 hm1.m_child.setGroundHeight(v2s16(1,0), 2.0);
611 //hm1.m_child.print();
612 assert(fabs(hm1.getGroundHeight(v2s16(1,0))-2.0)<0.001);
613 hm1.setGroundHeight(v2s16(0,1), 3.0);
614 assert(fabs(hm1.m_child.getGroundHeight(v2s16(0,1))-3.0)<0.001);
617 for(s16 y=0; y<=BS1; y++){
618 for(s16 x=0; x<=BS1; x++){
620 hm1.m_child.setGroundHeight(p, -1.0);
624 f32 corners[] = {0.0, 0.0, 1.0, 1.0};
625 hm1.m_child.generateContinued(0.0, 0.0, corners);
628 assert(fabs(hm1.m_child.getGroundHeight(v2s16(1,0))-0.2)<0.05);
629 assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,3))-0.7)<0.05);
630 assert(fabs(hm1.m_child.getGroundHeight(v2s16(4,4))-1.0)<0.05);
635 //g_heightmap_debugprint = true;
637 UnlimitedHeightmap hm1(BS1,
638 new ConstantGenerator(0.0),
639 new ConstantGenerator(0.0),
640 new ConstantGenerator(5.0));
641 // Go through it so it generates itself
642 for(s16 y=0; y<=BS1; y++){
643 for(s16 x=0; x<=BS1; x++){
645 hm1.getGroundHeight(p);
649 dstream<<"UnlimitedHeightmap hm1:"<<std::endl;
652 dstream<<"testing UnlimitedHeightmap set/get"<<std::endl;
655 // Get first heightmap and try setGroundHeight
656 FixedHeightmap * href = hm1.getHeightmap(v2s16(0,0));
657 href->setGroundHeight(p1, v1);
658 // Read from UnlimitedHeightmap
659 assert(fabs(hm1.getGroundHeight(p1)-v1)<0.001);
664 dstream<<"Running random code (get a human to check this)"<<std::endl;
665 dstream<<"rand() values: ";
666 for(u16 i=0; i<5; i++)
667 dstream<<(u16)rand()<<" ";
671 UnlimitedHeightmap hm1(BS1,
672 new ConstantGenerator(10.0),
673 new ConstantGenerator(0.3),
674 new ConstantGenerator(0.0));
676 // Force hm1 to generate a some heightmap
677 hm1.getGroundHeight(v2s16(0,0));
678 hm1.getGroundHeight(v2s16(0,BS1));
679 /*hm1.getGroundHeight(v2s16(BS1,-1));
680 hm1.getGroundHeight(v2s16(BS1-1,-1));*/
683 // Get the (0,0) and (1,0) heightmaps
684 /*FixedHeightmap * hr00 = hm1.getHeightmap(v2s16(0,0));
685 FixedHeightmap * hr01 = hm1.getHeightmap(v2s16(1,0));
686 f32 corners[] = {1.0, 1.0, 1.0, 1.0};
687 hr00->generateContinued(0.0, 0.0, corners);
695 //srand(7); // Get constant random
696 srand(time(0)); // Get better random
708 const int port = 30003;
712 const char sendbuffer[] = "hello world!";
713 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
718 memset(rcvbuffer, 0, sizeof(rcvbuffer));
722 int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
726 //FIXME: This fails on some systems
727 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
728 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
732 struct TestConnection
737 Test helper functions
740 // Some constants for testing
741 u32 proto_id = 0x12345678;
744 SharedBuffer<u8> data1(1);
746 Address a(127,0,0,1, 10);
749 con::BufferedPacket p1 = con::makePacket(a, data1,
750 proto_id, peer_id, channel);
752 We should now have a packet with this data:
755 [4] u16 sender_peer_id
760 assert(readU32(&p1.data[0]) == proto_id);
761 assert(readU16(&p1.data[4]) == peer_id);
762 assert(readU8(&p1.data[6]) == channel);
763 assert(readU8(&p1.data[7]) == data1[0]);
765 //dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
767 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
769 /*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
770 <<data1.getSize()<<std::endl;
771 dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
772 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
773 dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
775 assert(p2.getSize() == 3 + data1.getSize());
776 assert(readU8(&p2[0]) == TYPE_RELIABLE);
777 assert(readU16(&p2[1]) == seqnum);
778 assert(readU8(&p2[3]) == data1[0]);
781 struct Handler : public con::PeerHandler
783 Handler(const char *a_name)
789 void peerAdded(con::Peer *peer)
791 dstream<<"Handler("<<name<<")::peerAdded(): "
792 "id="<<peer->id<<std::endl;
796 void deletingPeer(con::Peer *peer, bool timeout)
798 dstream<<"Handler("<<name<<")::deletingPeer(): "
800 <<", timeout="<<timeout<<std::endl;
812 DSTACK("TestConnection::Run");
817 Test some real connections
819 u32 proto_id = 0xad26846a;
821 Handler hand_server("server");
822 Handler hand_client("client");
824 dstream<<"** Creating server Connection"<<std::endl;
825 con::Connection server(proto_id, 512, 5.0, &hand_server);
828 dstream<<"** Creating client Connection"<<std::endl;
829 con::Connection client(proto_id, 512, 5.0, &hand_client);
831 assert(hand_server.count == 0);
832 assert(hand_client.count == 0);
836 Address server_address(127,0,0,1, 30001);
837 dstream<<"** running client.Connect()"<<std::endl;
838 client.Connect(server_address);
842 // Client should have added server now
843 assert(hand_client.count == 1);
844 assert(hand_client.last_id == 1);
845 // But server should not have added client
846 assert(hand_server.count == 0);
852 dstream<<"** running server.Receive()"<<std::endl;
853 u32 size = server.Receive(peer_id, data, 100);
854 dstream<<"** Server received: peer_id="<<peer_id
858 catch(con::NoIncomingDataException &e)
860 // No actual data received, but the client has
861 // probably been connected
864 // Client should be the same
865 assert(hand_client.count == 1);
866 assert(hand_client.last_id == 1);
867 // Server should have the client
868 assert(hand_server.count == 1);
869 assert(hand_server.last_id == 2);
873 while(client.Connected() == false)
879 dstream<<"** running client.Receive()"<<std::endl;
880 u32 size = client.Receive(peer_id, data, 100);
881 dstream<<"** Client received: peer_id="<<peer_id
885 catch(con::NoIncomingDataException &e)
897 dstream<<"** running server.Receive()"<<std::endl;
898 u32 size = server.Receive(peer_id, data, 100);
899 dstream<<"** Server received: peer_id="<<peer_id
903 catch(con::NoIncomingDataException &e)
908 /*u8 data[] = "Hello World!";
909 u32 datasize = sizeof(data);*/
910 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
912 dstream<<"** running client.Send()"<<std::endl;
913 client.Send(PEER_ID_SERVER, 0, data, true);
919 dstream<<"** running server.Receive()"<<std::endl;
920 u32 size = server.Receive(peer_id, recvdata, 100);
921 dstream<<"** Server received: peer_id="<<peer_id
925 assert(memcmp(*data, recvdata, data.getSize()) == 0);
928 u16 peer_id_client = 2;
932 Send consequent packets in different order
934 //u8 data1[] = "hello1";
935 //u8 data2[] = "hello2";
936 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
937 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
939 Address client_address =
940 server.GetPeer(peer_id_client)->address;
942 dstream<<"*** Sending packets in wrong order (2,1,2)"
946 con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
947 u16 sn = ch->next_outgoing_seqnum;
948 ch->next_outgoing_seqnum = sn+1;
949 server.Send(peer_id_client, chn, data2, true);
950 ch->next_outgoing_seqnum = sn;
951 server.Send(peer_id_client, chn, data1, true);
952 ch->next_outgoing_seqnum = sn+1;
953 server.Send(peer_id_client, chn, data2, true);
957 dstream<<"*** Receiving the packets"<<std::endl;
963 dstream<<"** running client.Receive()"<<std::endl;
965 size = client.Receive(peer_id, recvdata, 20);
966 dstream<<"** Client received: peer_id="<<peer_id
968 <<", data="<<recvdata
970 assert(size == data1.getSize());
971 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
972 assert(peer_id == PEER_ID_SERVER);
974 dstream<<"** running client.Receive()"<<std::endl;
976 size = client.Receive(peer_id, recvdata, 20);
977 dstream<<"** Client received: peer_id="<<peer_id
979 <<", data="<<recvdata
981 assert(size == data2.getSize());
982 assert(memcmp(*data2, recvdata, data2.getSize()) == 0);
983 assert(peer_id == PEER_ID_SERVER);
985 bool got_exception = false;
988 dstream<<"** running client.Receive()"<<std::endl;
990 size = client.Receive(peer_id, recvdata, 20);
991 dstream<<"** Client received: peer_id="<<peer_id
993 <<", data="<<recvdata
996 catch(con::NoIncomingDataException &e)
998 dstream<<"** No incoming data for client"<<std::endl;
999 got_exception = true;
1001 assert(got_exception);
1005 SharedBuffer<u8> data1(1100);
1006 for(u16 i=0; i<1100; i++){
1010 dstream<<"Sending data (size="<<1100<<"):";
1011 for(int i=0; i<1100 && i<20; i++){
1012 if(i%2==0) printf(" ");
1013 printf("%.2X", ((int)((const char*)*data1)[i])&0xff);
1019 server.Send(peer_id_client, 0, data1, true);
1024 dstream<<"** running client.Receive()"<<std::endl;
1026 u16 size = client.Receive(peer_id, recvdata, 2000);
1027 dstream<<"** Client received: peer_id="<<peer_id
1031 dstream<<"Received data (size="<<size<<"):";
1032 for(int i=0; i<size && i<20; i++){
1033 if(i%2==0) printf(" ");
1034 printf("%.2X", ((int)((const char*)recvdata)[i])&0xff);
1040 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
1041 assert(peer_id == PEER_ID_SERVER);
1044 // Check peer handlers
1045 assert(hand_client.count == 1);
1046 assert(hand_client.last_id == 1);
1047 assert(hand_server.count == 1);
1048 assert(hand_server.last_id == 2);
1057 dstream<<"Running " #X <<std::endl;\
1063 DSTACK(__FUNCTION_NAME);
1064 dstream<<"run_tests() started"<<std::endl;
1065 TEST(TestUtilities);
1068 TEST(TestVoxelManipulator);
1070 TEST(TestMapSector);
1071 TEST(TestHeightmap);
1072 if(INTERNET_SIMULATOR == false){
1074 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1075 TEST(TestConnection);
1076 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1078 dstream<<"run_tests() passed"<<std::endl;