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"
35 Asserts that the exception occurs
37 #define EXCEPTION_CHECK(EType, code)\
39 bool exception_thrown = false;\
41 catch(EType &e) { exception_thrown = true; }\
42 assert(exception_thrown);\
49 /*dstream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
50 dstream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
51 dstream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
52 assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
53 assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
54 assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
55 assert(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
56 assert(lowercase("Foo bAR") == "foo bar");
57 assert(is_yes("YeS") == true);
58 assert(is_yes("") == false);
59 assert(is_yes("FAlse") == false);
69 SharedBuffer<u8> fromdata(4);
75 std::ostringstream os(std::ios_base::binary);
76 compress(fromdata, os, 0);
78 std::string str_out = os.str();
80 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
81 dstream<<"TestCompress: 1,5,5,1 -> ";
82 for(u32 i=0; i<str_out.size(); i++)
84 dstream<<(u32)str_out[i]<<",";
88 assert(str_out.size() == 10);
90 assert(str_out[0] == 0);
91 assert(str_out[1] == 0);
92 assert(str_out[2] == 0);
93 assert(str_out[3] == 4);
94 assert(str_out[4] == 0);
95 assert(str_out[5] == 1);
96 assert(str_out[6] == 1);
97 assert(str_out[7] == 5);
98 assert(str_out[8] == 0);
99 assert(str_out[9] == 1);
101 std::istringstream is(str_out, std::ios_base::binary);
102 std::ostringstream os2(std::ios_base::binary);
104 decompress(is, os2, 0);
105 std::string str_out2 = os2.str();
107 dstream<<"decompress: ";
108 for(u32 i=0; i<str_out2.size(); i++)
110 dstream<<(u32)str_out2[i]<<",";
114 assert(str_out2.size() == fromdata.getSize());
116 for(u32 i=0; i<str_out2.size(); i++)
118 assert(str_out2[i] == fromdata[i]);
125 SharedBuffer<u8> fromdata(4);
131 std::ostringstream os(std::ios_base::binary);
132 compress(fromdata, os, SER_FMT_VER_HIGHEST);
134 std::string str_out = os.str();
136 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
137 dstream<<"TestCompress: 1,5,5,1 -> ";
138 for(u32 i=0; i<str_out.size(); i++)
140 dstream<<(u32)str_out[i]<<",";
144 /*assert(str_out.size() == 10);
146 assert(str_out[0] == 0);
147 assert(str_out[1] == 0);
148 assert(str_out[2] == 0);
149 assert(str_out[3] == 4);
150 assert(str_out[4] == 0);
151 assert(str_out[5] == 1);
152 assert(str_out[6] == 1);
153 assert(str_out[7] == 5);
154 assert(str_out[8] == 0);
155 assert(str_out[9] == 1);*/
157 std::istringstream is(str_out, std::ios_base::binary);
158 std::ostringstream os2(std::ios_base::binary);
160 decompress(is, os2, SER_FMT_VER_HIGHEST);
161 std::string str_out2 = os2.str();
163 dstream<<"decompress: ";
164 for(u32 i=0; i<str_out2.size(); i++)
166 dstream<<(u32)str_out2[i]<<",";
170 assert(str_out2.size() == fromdata.getSize());
172 for(u32 i=0; i<str_out2.size(); i++)
174 assert(str_out2[i] == fromdata[i]);
188 assert(n.d == CONTENT_AIR);
189 assert(n.getLight(LIGHTBANK_DAY) == 0);
190 assert(n.getLight(LIGHTBANK_NIGHT) == 0);
194 assert(n.light_propagates() == true);
196 assert(n.light_propagates() == false);
200 struct TestVoxelManipulator
208 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
209 assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
210 assert(a.index(-1,-1,-1) == 0);
212 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
213 // An area that is 1 bigger in x+ and z-
214 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
216 core::list<VoxelArea> aa;
220 core::array<VoxelArea> results;
221 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
222 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
224 assert(aa.size() == results.size());
226 dstream<<"Result of diff:"<<std::endl;
227 for(core::list<VoxelArea>::Iterator
228 i = aa.begin(); i != aa.end(); i++)
233 s32 j = results.linear_search(*i);
247 dstream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
249 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
253 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
255 dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
257 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
261 dstream<<"*** Adding area ***"<<std::endl;
267 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
268 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
277 const char *content =
289 v3s16 size(12, 4, 2);
290 VoxelArea area(v3s16(0,0,0), size-v3s16(1,1,1));
292 const char *p = content;
293 for(s16 z=0; z<size.Z; z++)
294 for(s16 y=size.Y-1; y>=0; y--)
295 for(s16 x=0; x<size.X; x++)
298 //n.pressure = size.Y - y;
307 v.setNode(v3s16(x,y,z), n);
311 v.print(dstream, VOXELPRINT_WATERPRESSURE);
313 core::map<v3s16, u8> active_nodes;
314 v.updateAreaWaterPressure(area, active_nodes);
316 v.print(dstream, VOXELPRINT_WATERPRESSURE);
318 //s16 highest_y = -32768;
320 NOTE: These are commented out because this behaviour is changed
323 //assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == -1);
324 //assert(highest_y == 3);
325 /*assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == 3);
326 //assert(highest_y == 3);*/
328 active_nodes.clear();
329 active_nodes[v3s16(9,1,0)] = 1;
330 //v.flowWater(active_nodes, 0, true, 1000);
331 v.flowWater(active_nodes, 0, false, 1000);
333 dstream<<"Final result of flowWater:"<<std::endl;
334 v.print(dstream, VOXELPRINT_WATERPRESSURE);
343 class TC : public NodeContainer
349 core::list<v3s16> validity_exceptions;
353 position_valid = true;
356 virtual bool isValidPosition(v3s16 p)
358 //return position_valid ^ (p==position_valid_exception);
359 bool exception = false;
360 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
361 i != validity_exceptions.end(); i++)
369 return exception ? !position_valid : position_valid;
372 virtual MapNode getNode(v3s16 p)
374 if(isValidPosition(p) == false)
375 throw InvalidPositionException();
379 virtual void setNode(v3s16 p, MapNode & n)
381 if(isValidPosition(p) == false)
382 throw InvalidPositionException();
385 virtual u16 nodeContainerId() const
395 MapBlock b(&parent, v3s16(1,1,1));
396 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
398 assert(b.getPosRelative() == relpos);
400 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
401 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
402 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
403 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
404 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
405 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
407 assert(b.isValidPosition(v3s16(0,0,0)) == true);
408 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
409 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
410 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
411 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
412 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
415 TODO: this method should probably be removed
416 if the block size isn't going to be set variable
418 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
419 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
421 // Changed flag should be initially set
422 assert(b.getChangedFlag() == true);
423 b.resetChangedFlag();
424 assert(b.getChangedFlag() == false);
426 // All nodes should have been set to
427 // .d=CONTENT_AIR and .getLight() = 0
428 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
429 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
430 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
432 assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
433 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
434 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
438 Parent fetch functions
440 parent.position_valid = false;
445 // Positions in the block should still be valid
446 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
447 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
448 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
449 assert(n.d == CONTENT_AIR);
451 // ...but outside the block they should be invalid
452 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
453 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
454 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
457 bool exception_thrown = false;
459 // This should throw an exception
460 MapNode n = b.getNodeParent(v3s16(0,0,-1));
462 catch(InvalidPositionException &e)
464 exception_thrown = true;
466 assert(exception_thrown);
469 parent.position_valid = true;
470 // Now the positions outside should be valid
471 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
472 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
473 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
474 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
483 assert(b.getNode(p).d == 4);
484 //TODO: Update to new system
485 /*assert(b.getNodeTile(p) == 4);
486 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
491 // Set lighting of all nodes to 0
492 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
493 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
494 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
495 MapNode n = b.getNode(v3s16(x,y,z));
496 n.setLight(LIGHTBANK_DAY, 0);
497 n.setLight(LIGHTBANK_NIGHT, 0);
498 b.setNode(v3s16(x,y,z), n);
504 Check how the block handles being a lonely sky block
506 parent.position_valid = true;
507 b.setIsUnderground(false);
508 parent.node.d = CONTENT_AIR;
509 parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
510 parent.node.setLight(LIGHTBANK_NIGHT, 0);
511 core::map<v3s16, bool> light_sources;
512 // The bottom block is invalid, because we have a shadowing node
513 assert(b.propagateSunlight(light_sources) == false);
514 assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
515 assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
516 assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
517 assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
518 assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
519 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
520 assert(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
521 assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
522 assert(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
523 // According to MapBlock::getFaceLight,
524 // The face on the z+ side should have double-diminished light
525 //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
526 // The face on the z+ side should have diminished light
527 assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
530 Check how the block handles being in between blocks with some non-sunlight
531 while being underground
534 // Make neighbours to exist and set some non-sunlight to them
535 parent.position_valid = true;
536 b.setIsUnderground(true);
537 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
538 core::map<v3s16, bool> light_sources;
539 // The block below should be valid because there shouldn't be
540 // sunlight in there either
541 assert(b.propagateSunlight(light_sources, true) == true);
542 // Should not touch nodes that are not affected (that is, all of them)
543 //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
544 // Should set light of non-sunlighted blocks to 0.
545 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
548 Set up a situation where:
549 - There is only air in this block
550 - There is a valid non-sunlighted block at the bottom, and
551 - Invalid blocks elsewhere.
552 - the block is not underground.
554 This should result in bottom block invalidity
557 b.setIsUnderground(false);
559 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
560 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
561 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
564 n.setLight(LIGHTBANK_DAY, 0);
565 b.setNode(v3s16(x,y,z), n);
569 // Make neighbours invalid
570 parent.position_valid = false;
571 // Add exceptions to the top of the bottom block
572 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
573 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
575 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
577 // Lighting value for the valid nodes
578 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
579 core::map<v3s16, bool> light_sources;
580 // Bottom block is not valid
581 assert(b.propagateSunlight(light_sources) == false);
588 class TC : public NodeContainer
597 position_valid = true;
600 virtual bool isValidPosition(v3s16 p)
602 return position_valid;
605 virtual MapNode getNode(v3s16 p)
607 if(position_valid == false)
608 throw InvalidPositionException();
612 virtual void setNode(v3s16 p, MapNode & n)
614 if(position_valid == false)
615 throw InvalidPositionException();
618 virtual u16 nodeContainerId() const
627 parent.position_valid = false;
629 // Create one with no heightmaps
630 ServerMapSector sector(&parent, v2s16(1,1));
632 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
633 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1));
635 MapBlock * bref = sector.createBlankBlock(-2);
637 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
638 assert(sector.getBlockNoCreate(-2) == bref);
640 //TODO: Check for AlreadyExistsException
642 /*bool exception_thrown = false;
646 catch(InvalidPositionException &e){
647 exception_thrown = true;
649 assert(exception_thrown);*/
658 const int port = 30003;
662 const char sendbuffer[] = "hello world!";
663 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
668 memset(rcvbuffer, 0, sizeof(rcvbuffer));
672 int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
676 //FIXME: This fails on some systems
677 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
678 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
682 struct TestConnection
687 Test helper functions
690 // Some constants for testing
691 u32 proto_id = 0x12345678;
694 SharedBuffer<u8> data1(1);
696 Address a(127,0,0,1, 10);
699 con::BufferedPacket p1 = con::makePacket(a, data1,
700 proto_id, peer_id, channel);
702 We should now have a packet with this data:
705 [4] u16 sender_peer_id
710 assert(readU32(&p1.data[0]) == proto_id);
711 assert(readU16(&p1.data[4]) == peer_id);
712 assert(readU8(&p1.data[6]) == channel);
713 assert(readU8(&p1.data[7]) == data1[0]);
715 //dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
717 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
719 /*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
720 <<data1.getSize()<<std::endl;
721 dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
722 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
723 dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
725 assert(p2.getSize() == 3 + data1.getSize());
726 assert(readU8(&p2[0]) == TYPE_RELIABLE);
727 assert(readU16(&p2[1]) == seqnum);
728 assert(readU8(&p2[3]) == data1[0]);
731 struct Handler : public con::PeerHandler
733 Handler(const char *a_name)
739 void peerAdded(con::Peer *peer)
741 dstream<<"Handler("<<name<<")::peerAdded(): "
742 "id="<<peer->id<<std::endl;
746 void deletingPeer(con::Peer *peer, bool timeout)
748 dstream<<"Handler("<<name<<")::deletingPeer(): "
750 <<", timeout="<<timeout<<std::endl;
762 DSTACK("TestConnection::Run");
767 Test some real connections
769 u32 proto_id = 0xad26846a;
771 Handler hand_server("server");
772 Handler hand_client("client");
774 dstream<<"** Creating server Connection"<<std::endl;
775 con::Connection server(proto_id, 512, 5.0, &hand_server);
778 dstream<<"** Creating client Connection"<<std::endl;
779 con::Connection client(proto_id, 512, 5.0, &hand_client);
781 assert(hand_server.count == 0);
782 assert(hand_client.count == 0);
786 Address server_address(127,0,0,1, 30001);
787 dstream<<"** running client.Connect()"<<std::endl;
788 client.Connect(server_address);
792 // Client should have added server now
793 assert(hand_client.count == 1);
794 assert(hand_client.last_id == 1);
795 // But server should not have added client
796 assert(hand_server.count == 0);
802 dstream<<"** running server.Receive()"<<std::endl;
803 u32 size = server.Receive(peer_id, data, 100);
804 dstream<<"** Server received: peer_id="<<peer_id
808 catch(con::NoIncomingDataException &e)
810 // No actual data received, but the client has
811 // probably been connected
814 // Client should be the same
815 assert(hand_client.count == 1);
816 assert(hand_client.last_id == 1);
817 // Server should have the client
818 assert(hand_server.count == 1);
819 assert(hand_server.last_id == 2);
823 while(client.Connected() == false)
829 dstream<<"** running client.Receive()"<<std::endl;
830 u32 size = client.Receive(peer_id, data, 100);
831 dstream<<"** Client received: peer_id="<<peer_id
835 catch(con::NoIncomingDataException &e)
847 dstream<<"** running server.Receive()"<<std::endl;
848 u32 size = server.Receive(peer_id, data, 100);
849 dstream<<"** Server received: peer_id="<<peer_id
853 catch(con::NoIncomingDataException &e)
858 /*u8 data[] = "Hello World!";
859 u32 datasize = sizeof(data);*/
860 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
862 dstream<<"** running client.Send()"<<std::endl;
863 client.Send(PEER_ID_SERVER, 0, data, true);
869 dstream<<"** running server.Receive()"<<std::endl;
870 u32 size = server.Receive(peer_id, recvdata, 100);
871 dstream<<"** Server received: peer_id="<<peer_id
875 assert(memcmp(*data, recvdata, data.getSize()) == 0);
878 u16 peer_id_client = 2;
882 Send consequent packets in different order
884 //u8 data1[] = "hello1";
885 //u8 data2[] = "hello2";
886 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
887 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
889 Address client_address =
890 server.GetPeer(peer_id_client)->address;
892 dstream<<"*** Sending packets in wrong order (2,1,2)"
896 con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
897 u16 sn = ch->next_outgoing_seqnum;
898 ch->next_outgoing_seqnum = sn+1;
899 server.Send(peer_id_client, chn, data2, true);
900 ch->next_outgoing_seqnum = sn;
901 server.Send(peer_id_client, chn, data1, true);
902 ch->next_outgoing_seqnum = sn+1;
903 server.Send(peer_id_client, chn, data2, true);
907 dstream<<"*** Receiving the packets"<<std::endl;
913 dstream<<"** running client.Receive()"<<std::endl;
915 size = client.Receive(peer_id, recvdata, 20);
916 dstream<<"** Client received: peer_id="<<peer_id
918 <<", data="<<recvdata
920 assert(size == data1.getSize());
921 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
922 assert(peer_id == PEER_ID_SERVER);
924 dstream<<"** running client.Receive()"<<std::endl;
926 size = client.Receive(peer_id, recvdata, 20);
927 dstream<<"** Client received: peer_id="<<peer_id
929 <<", data="<<recvdata
931 assert(size == data2.getSize());
932 assert(memcmp(*data2, recvdata, data2.getSize()) == 0);
933 assert(peer_id == PEER_ID_SERVER);
935 bool got_exception = false;
938 dstream<<"** running client.Receive()"<<std::endl;
940 size = client.Receive(peer_id, recvdata, 20);
941 dstream<<"** Client received: peer_id="<<peer_id
943 <<", data="<<recvdata
946 catch(con::NoIncomingDataException &e)
948 dstream<<"** No incoming data for client"<<std::endl;
949 got_exception = true;
951 assert(got_exception);
955 SharedBuffer<u8> data1(1100);
956 for(u16 i=0; i<1100; i++){
960 dstream<<"Sending data (size="<<1100<<"):";
961 for(int i=0; i<1100 && i<20; i++){
962 if(i%2==0) DEBUGPRINT(" ");
963 DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
969 server.Send(peer_id_client, 0, data1, true);
974 dstream<<"** running client.Receive()"<<std::endl;
976 u16 size = client.Receive(peer_id, recvdata, 2000);
977 dstream<<"** Client received: peer_id="<<peer_id
981 dstream<<"Received data (size="<<size<<"):";
982 for(int i=0; i<size && i<20; i++){
983 if(i%2==0) DEBUGPRINT(" ");
984 DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
990 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
991 assert(peer_id == PEER_ID_SERVER);
994 // Check peer handlers
995 assert(hand_client.count == 1);
996 assert(hand_client.last_id == 1);
997 assert(hand_server.count == 1);
998 assert(hand_server.last_id == 2);
1007 dstream<<"Running " #X <<std::endl;\
1013 DSTACK(__FUNCTION_NAME);
1014 dstream<<"run_tests() started"<<std::endl;
1015 TEST(TestUtilities);
1018 TEST(TestVoxelManipulator);
1020 TEST(TestMapSector);
1021 if(INTERNET_SIMULATOR == false){
1023 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1024 TEST(TestConnection);
1025 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1027 dstream<<"run_tests() passed"<<std::endl;