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"
27 #include "connection.h"
29 #include "serialization.h"
33 #include "content_mapnode.h"
34 #include "mapsector.h"
37 Asserts that the exception occurs
39 #define EXCEPTION_CHECK(EType, code)\
41 bool exception_thrown = false;\
43 catch(EType &e) { exception_thrown = true; }\
44 assert(exception_thrown);\
51 /*dstream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
52 dstream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
53 dstream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
54 assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
55 assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
56 assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
57 assert(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
58 assert(lowercase("Foo bAR") == "foo bar");
59 assert(is_yes("YeS") == true);
60 assert(is_yes("") == false);
61 assert(is_yes("FAlse") == false);
71 SharedBuffer<u8> fromdata(4);
77 std::ostringstream os(std::ios_base::binary);
78 compress(fromdata, os, 0);
80 std::string str_out = os.str();
82 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
83 dstream<<"TestCompress: 1,5,5,1 -> ";
84 for(u32 i=0; i<str_out.size(); i++)
86 dstream<<(u32)str_out[i]<<",";
90 assert(str_out.size() == 10);
92 assert(str_out[0] == 0);
93 assert(str_out[1] == 0);
94 assert(str_out[2] == 0);
95 assert(str_out[3] == 4);
96 assert(str_out[4] == 0);
97 assert(str_out[5] == 1);
98 assert(str_out[6] == 1);
99 assert(str_out[7] == 5);
100 assert(str_out[8] == 0);
101 assert(str_out[9] == 1);
103 std::istringstream is(str_out, std::ios_base::binary);
104 std::ostringstream os2(std::ios_base::binary);
106 decompress(is, os2, 0);
107 std::string str_out2 = os2.str();
109 dstream<<"decompress: ";
110 for(u32 i=0; i<str_out2.size(); i++)
112 dstream<<(u32)str_out2[i]<<",";
116 assert(str_out2.size() == fromdata.getSize());
118 for(u32 i=0; i<str_out2.size(); i++)
120 assert(str_out2[i] == fromdata[i]);
127 SharedBuffer<u8> fromdata(4);
133 std::ostringstream os(std::ios_base::binary);
134 compress(fromdata, os, SER_FMT_VER_HIGHEST);
136 std::string str_out = os.str();
138 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
139 dstream<<"TestCompress: 1,5,5,1 -> ";
140 for(u32 i=0; i<str_out.size(); i++)
142 dstream<<(u32)str_out[i]<<",";
146 /*assert(str_out.size() == 10);
148 assert(str_out[0] == 0);
149 assert(str_out[1] == 0);
150 assert(str_out[2] == 0);
151 assert(str_out[3] == 4);
152 assert(str_out[4] == 0);
153 assert(str_out[5] == 1);
154 assert(str_out[6] == 1);
155 assert(str_out[7] == 5);
156 assert(str_out[8] == 0);
157 assert(str_out[9] == 1);*/
159 std::istringstream is(str_out, std::ios_base::binary);
160 std::ostringstream os2(std::ios_base::binary);
162 decompress(is, os2, SER_FMT_VER_HIGHEST);
163 std::string str_out2 = os2.str();
165 dstream<<"decompress: ";
166 for(u32 i=0; i<str_out2.size(); i++)
168 dstream<<(u32)str_out2[i]<<",";
172 assert(str_out2.size() == fromdata.getSize());
174 for(u32 i=0; i<str_out2.size(); i++)
176 assert(str_out2[i] == fromdata[i]);
190 assert(n.d == CONTENT_AIR);
191 assert(n.getLight(LIGHTBANK_DAY) == 0);
192 assert(n.getLight(LIGHTBANK_NIGHT) == 0);
196 assert(n.light_propagates() == true);
198 assert(n.light_propagates() == false);
202 struct TestVoxelManipulator
210 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
211 assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
212 assert(a.index(-1,-1,-1) == 0);
214 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
215 // An area that is 1 bigger in x+ and z-
216 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
218 core::list<VoxelArea> aa;
222 core::array<VoxelArea> results;
223 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
224 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
226 assert(aa.size() == results.size());
228 dstream<<"Result of diff:"<<std::endl;
229 for(core::list<VoxelArea>::Iterator
230 i = aa.begin(); i != aa.end(); i++)
235 s32 j = results.linear_search(*i);
249 dstream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
251 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
255 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
257 dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
259 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
263 dstream<<"*** Adding area ***"<<std::endl;
269 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
270 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
279 const char *content =
291 v3s16 size(12, 4, 2);
292 VoxelArea area(v3s16(0,0,0), size-v3s16(1,1,1));
294 const char *p = content;
295 for(s16 z=0; z<size.Z; z++)
296 for(s16 y=size.Y-1; y>=0; y--)
297 for(s16 x=0; x<size.X; x++)
300 //n.pressure = size.Y - y;
309 v.setNode(v3s16(x,y,z), n);
313 v.print(dstream, VOXELPRINT_WATERPRESSURE);
315 core::map<v3s16, u8> active_nodes;
316 v.updateAreaWaterPressure(area, active_nodes);
318 v.print(dstream, VOXELPRINT_WATERPRESSURE);
320 //s16 highest_y = -32768;
322 NOTE: These are commented out because this behaviour is changed
325 //assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == -1);
326 //assert(highest_y == 3);
327 /*assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == 3);
328 //assert(highest_y == 3);*/
330 active_nodes.clear();
331 active_nodes[v3s16(9,1,0)] = 1;
332 //v.flowWater(active_nodes, 0, true, 1000);
333 v.flowWater(active_nodes, 0, false, 1000);
335 dstream<<"Final result of flowWater:"<<std::endl;
336 v.print(dstream, VOXELPRINT_WATERPRESSURE);
344 NOTE: These tests became non-working then NodeContainer was removed.
345 These should be redone, utilizing some kind of a virtual
346 interface for Map (IMap would be fine).
351 class TC : public NodeContainer
357 core::list<v3s16> validity_exceptions;
361 position_valid = true;
364 virtual bool isValidPosition(v3s16 p)
366 //return position_valid ^ (p==position_valid_exception);
367 bool exception = false;
368 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
369 i != validity_exceptions.end(); i++)
377 return exception ? !position_valid : position_valid;
380 virtual MapNode getNode(v3s16 p)
382 if(isValidPosition(p) == false)
383 throw InvalidPositionException();
387 virtual void setNode(v3s16 p, MapNode & n)
389 if(isValidPosition(p) == false)
390 throw InvalidPositionException();
393 virtual u16 nodeContainerId() const
403 MapBlock b(&parent, v3s16(1,1,1));
404 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
406 assert(b.getPosRelative() == relpos);
408 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
409 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
410 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
411 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
412 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
413 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
415 assert(b.isValidPosition(v3s16(0,0,0)) == true);
416 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
417 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
418 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
419 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
420 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
423 TODO: this method should probably be removed
424 if the block size isn't going to be set variable
426 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
427 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
429 // Changed flag should be initially set
430 assert(b.getChangedFlag() == true);
431 b.resetChangedFlag();
432 assert(b.getChangedFlag() == false);
434 // All nodes should have been set to
435 // .d=CONTENT_IGNORE and .getLight() = 0
436 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
437 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
438 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
440 //assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
441 assert(b.getNode(v3s16(x,y,z)).d == CONTENT_IGNORE);
442 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
443 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
447 MapNode n(CONTENT_AIR);
448 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
449 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
450 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
452 b.setNode(v3s16(x,y,z), n);
457 Parent fetch functions
459 parent.position_valid = false;
464 // Positions in the block should still be valid
465 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
466 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
467 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
468 assert(n.d == CONTENT_AIR);
470 // ...but outside the block they should be invalid
471 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
472 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
473 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
476 bool exception_thrown = false;
478 // This should throw an exception
479 MapNode n = b.getNodeParent(v3s16(0,0,-1));
481 catch(InvalidPositionException &e)
483 exception_thrown = true;
485 assert(exception_thrown);
488 parent.position_valid = true;
489 // Now the positions outside should be valid
490 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
491 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
492 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
493 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
502 assert(b.getNode(p).d == 4);
503 //TODO: Update to new system
504 /*assert(b.getNodeTile(p) == 4);
505 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
510 // Set lighting of all nodes to 0
511 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
512 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
513 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
514 MapNode n = b.getNode(v3s16(x,y,z));
515 n.setLight(LIGHTBANK_DAY, 0);
516 n.setLight(LIGHTBANK_NIGHT, 0);
517 b.setNode(v3s16(x,y,z), n);
523 Check how the block handles being a lonely sky block
525 parent.position_valid = true;
526 b.setIsUnderground(false);
527 parent.node.d = CONTENT_AIR;
528 parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
529 parent.node.setLight(LIGHTBANK_NIGHT, 0);
530 core::map<v3s16, bool> light_sources;
531 // The bottom block is invalid, because we have a shadowing node
532 assert(b.propagateSunlight(light_sources) == false);
533 assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
534 assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
535 assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
536 assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
537 assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
538 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
539 assert(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
540 assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
541 assert(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
542 // According to MapBlock::getFaceLight,
543 // The face on the z+ side should have double-diminished light
544 //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
545 // The face on the z+ side should have diminished light
546 assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
549 Check how the block handles being in between blocks with some non-sunlight
550 while being underground
553 // Make neighbours to exist and set some non-sunlight to them
554 parent.position_valid = true;
555 b.setIsUnderground(true);
556 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
557 core::map<v3s16, bool> light_sources;
558 // The block below should be valid because there shouldn't be
559 // sunlight in there either
560 assert(b.propagateSunlight(light_sources, true) == true);
561 // Should not touch nodes that are not affected (that is, all of them)
562 //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
563 // Should set light of non-sunlighted blocks to 0.
564 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
567 Set up a situation where:
568 - There is only air in this block
569 - There is a valid non-sunlighted block at the bottom, and
570 - Invalid blocks elsewhere.
571 - the block is not underground.
573 This should result in bottom block invalidity
576 b.setIsUnderground(false);
578 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
579 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
580 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
583 n.setLight(LIGHTBANK_DAY, 0);
584 b.setNode(v3s16(x,y,z), n);
588 // Make neighbours invalid
589 parent.position_valid = false;
590 // Add exceptions to the top of the bottom block
591 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
592 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
594 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
596 // Lighting value for the valid nodes
597 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
598 core::map<v3s16, bool> light_sources;
599 // Bottom block is not valid
600 assert(b.propagateSunlight(light_sources) == false);
607 class TC : public NodeContainer
616 position_valid = true;
619 virtual bool isValidPosition(v3s16 p)
621 return position_valid;
624 virtual MapNode getNode(v3s16 p)
626 if(position_valid == false)
627 throw InvalidPositionException();
631 virtual void setNode(v3s16 p, MapNode & n)
633 if(position_valid == false)
634 throw InvalidPositionException();
637 virtual u16 nodeContainerId() const
646 parent.position_valid = false;
648 // Create one with no heightmaps
649 ServerMapSector sector(&parent, v2s16(1,1));
651 assert(sector.getBlockNoCreateNoEx(0) == 0);
652 assert(sector.getBlockNoCreateNoEx(1) == 0);
654 MapBlock * bref = sector.createBlankBlock(-2);
656 assert(sector.getBlockNoCreateNoEx(0) == 0);
657 assert(sector.getBlockNoCreateNoEx(-2) == bref);
659 //TODO: Check for AlreadyExistsException
661 /*bool exception_thrown = false;
665 catch(InvalidPositionException &e){
666 exception_thrown = true;
668 assert(exception_thrown);*/
678 const int port = 30003;
682 const char sendbuffer[] = "hello world!";
683 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
688 memset(rcvbuffer, 0, sizeof(rcvbuffer));
692 int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
696 //FIXME: This fails on some systems
697 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
698 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
702 struct TestConnection
707 Test helper functions
710 // Some constants for testing
711 u32 proto_id = 0x12345678;
714 SharedBuffer<u8> data1(1);
716 Address a(127,0,0,1, 10);
719 con::BufferedPacket p1 = con::makePacket(a, data1,
720 proto_id, peer_id, channel);
722 We should now have a packet with this data:
725 [4] u16 sender_peer_id
730 assert(readU32(&p1.data[0]) == proto_id);
731 assert(readU16(&p1.data[4]) == peer_id);
732 assert(readU8(&p1.data[6]) == channel);
733 assert(readU8(&p1.data[7]) == data1[0]);
735 //dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
737 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
739 /*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
740 <<data1.getSize()<<std::endl;
741 dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
742 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
743 dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
745 assert(p2.getSize() == 3 + data1.getSize());
746 assert(readU8(&p2[0]) == TYPE_RELIABLE);
747 assert(readU16(&p2[1]) == seqnum);
748 assert(readU8(&p2[3]) == data1[0]);
751 struct Handler : public con::PeerHandler
753 Handler(const char *a_name)
759 void peerAdded(con::Peer *peer)
761 dstream<<"Handler("<<name<<")::peerAdded(): "
762 "id="<<peer->id<<std::endl;
766 void deletingPeer(con::Peer *peer, bool timeout)
768 dstream<<"Handler("<<name<<")::deletingPeer(): "
770 <<", timeout="<<timeout<<std::endl;
782 DSTACK("TestConnection::Run");
787 Test some real connections
789 u32 proto_id = 0xad26846a;
791 Handler hand_server("server");
792 Handler hand_client("client");
794 dstream<<"** Creating server Connection"<<std::endl;
795 con::Connection server(proto_id, 512, 5.0, &hand_server);
798 dstream<<"** Creating client Connection"<<std::endl;
799 con::Connection client(proto_id, 512, 5.0, &hand_client);
801 assert(hand_server.count == 0);
802 assert(hand_client.count == 0);
806 Address server_address(127,0,0,1, 30001);
807 dstream<<"** running client.Connect()"<<std::endl;
808 client.Connect(server_address);
812 // Client should have added server now
813 assert(hand_client.count == 1);
814 assert(hand_client.last_id == 1);
815 // But server should not have added client
816 assert(hand_server.count == 0);
822 dstream<<"** running server.Receive()"<<std::endl;
823 u32 size = server.Receive(peer_id, data, 100);
824 dstream<<"** Server received: peer_id="<<peer_id
828 catch(con::NoIncomingDataException &e)
830 // No actual data received, but the client has
831 // probably been connected
834 // Client should be the same
835 assert(hand_client.count == 1);
836 assert(hand_client.last_id == 1);
837 // Server should have the client
838 assert(hand_server.count == 1);
839 assert(hand_server.last_id == 2);
843 while(client.Connected() == false)
849 dstream<<"** running client.Receive()"<<std::endl;
850 u32 size = client.Receive(peer_id, data, 100);
851 dstream<<"** Client received: peer_id="<<peer_id
855 catch(con::NoIncomingDataException &e)
867 dstream<<"** running server.Receive()"<<std::endl;
868 u32 size = server.Receive(peer_id, data, 100);
869 dstream<<"** Server received: peer_id="<<peer_id
873 catch(con::NoIncomingDataException &e)
878 /*u8 data[] = "Hello World!";
879 u32 datasize = sizeof(data);*/
880 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
882 dstream<<"** running client.Send()"<<std::endl;
883 client.Send(PEER_ID_SERVER, 0, data, true);
889 dstream<<"** running server.Receive()"<<std::endl;
890 u32 size = server.Receive(peer_id, recvdata, 100);
891 dstream<<"** Server received: peer_id="<<peer_id
895 assert(memcmp(*data, recvdata, data.getSize()) == 0);
898 u16 peer_id_client = 2;
902 Send consequent packets in different order
904 //u8 data1[] = "hello1";
905 //u8 data2[] = "hello2";
906 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
907 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
909 Address client_address =
910 server.GetPeer(peer_id_client)->address;
912 dstream<<"*** Sending packets in wrong order (2,1,2)"
916 con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
917 u16 sn = ch->next_outgoing_seqnum;
918 ch->next_outgoing_seqnum = sn+1;
919 server.Send(peer_id_client, chn, data2, true);
920 ch->next_outgoing_seqnum = sn;
921 server.Send(peer_id_client, chn, data1, true);
922 ch->next_outgoing_seqnum = sn+1;
923 server.Send(peer_id_client, chn, data2, true);
927 dstream<<"*** Receiving the packets"<<std::endl;
933 dstream<<"** running client.Receive()"<<std::endl;
935 size = client.Receive(peer_id, recvdata, 20);
936 dstream<<"** Client received: peer_id="<<peer_id
938 <<", data="<<recvdata
940 assert(size == data1.getSize());
941 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
942 assert(peer_id == PEER_ID_SERVER);
944 dstream<<"** running client.Receive()"<<std::endl;
946 size = client.Receive(peer_id, recvdata, 20);
947 dstream<<"** Client received: peer_id="<<peer_id
949 <<", data="<<recvdata
951 assert(size == data2.getSize());
952 assert(memcmp(*data2, recvdata, data2.getSize()) == 0);
953 assert(peer_id == PEER_ID_SERVER);
955 bool got_exception = false;
958 dstream<<"** running client.Receive()"<<std::endl;
960 size = client.Receive(peer_id, recvdata, 20);
961 dstream<<"** Client received: peer_id="<<peer_id
963 <<", data="<<recvdata
966 catch(con::NoIncomingDataException &e)
968 dstream<<"** No incoming data for client"<<std::endl;
969 got_exception = true;
971 assert(got_exception);
974 const int datasize = 30000;
975 SharedBuffer<u8> data1(datasize);
976 for(u16 i=0; i<datasize; i++){
980 dstream<<"Sending data (size="<<datasize<<"):";
981 for(int i=0; i<datasize && i<20; i++){
982 if(i%2==0) DEBUGPRINT(" ");
983 DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
989 server.Send(peer_id_client, 0, data1, true);
993 u8 recvdata[datasize + 1000];
994 dstream<<"** running client.Receive()"<<std::endl;
996 u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
997 dstream<<"** Client received: peer_id="<<peer_id
1001 dstream<<"Received data (size="<<size<<"):";
1002 for(int i=0; i<size && i<20; i++){
1003 if(i%2==0) DEBUGPRINT(" ");
1004 DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
1010 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
1011 assert(peer_id == PEER_ID_SERVER);
1014 // Check peer handlers
1015 assert(hand_client.count == 1);
1016 assert(hand_client.last_id == 1);
1017 assert(hand_server.count == 1);
1018 assert(hand_server.last_id == 2);
1027 dstream<<"Running " #X <<std::endl;\
1033 DSTACK(__FUNCTION_NAME);
1034 dstream<<"run_tests() started"<<std::endl;
1035 TEST(TestUtilities);
1038 TEST(TestVoxelManipulator);
1039 //TEST(TestMapBlock);
1040 //TEST(TestMapSector);
1041 if(INTERNET_SIMULATOR == false){
1043 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1044 TEST(TestConnection);
1045 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1047 dstream<<"run_tests() passed"<<std::endl;