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"
36 Asserts that the exception occurs
38 #define EXCEPTION_CHECK(EType, code)\
40 bool exception_thrown = false;\
42 catch(EType &e) { exception_thrown = true; }\
43 assert(exception_thrown);\
50 /*dstream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
51 dstream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
52 dstream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
53 assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
54 assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
55 assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
56 assert(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
57 assert(lowercase("Foo bAR") == "foo bar");
58 assert(is_yes("YeS") == true);
59 assert(is_yes("") == false);
60 assert(is_yes("FAlse") == false);
70 SharedBuffer<u8> fromdata(4);
76 std::ostringstream os(std::ios_base::binary);
77 compress(fromdata, os, 0);
79 std::string str_out = os.str();
81 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
82 dstream<<"TestCompress: 1,5,5,1 -> ";
83 for(u32 i=0; i<str_out.size(); i++)
85 dstream<<(u32)str_out[i]<<",";
89 assert(str_out.size() == 10);
91 assert(str_out[0] == 0);
92 assert(str_out[1] == 0);
93 assert(str_out[2] == 0);
94 assert(str_out[3] == 4);
95 assert(str_out[4] == 0);
96 assert(str_out[5] == 1);
97 assert(str_out[6] == 1);
98 assert(str_out[7] == 5);
99 assert(str_out[8] == 0);
100 assert(str_out[9] == 1);
102 std::istringstream is(str_out, std::ios_base::binary);
103 std::ostringstream os2(std::ios_base::binary);
105 decompress(is, os2, 0);
106 std::string str_out2 = os2.str();
108 dstream<<"decompress: ";
109 for(u32 i=0; i<str_out2.size(); i++)
111 dstream<<(u32)str_out2[i]<<",";
115 assert(str_out2.size() == fromdata.getSize());
117 for(u32 i=0; i<str_out2.size(); i++)
119 assert(str_out2[i] == fromdata[i]);
126 SharedBuffer<u8> fromdata(4);
132 std::ostringstream os(std::ios_base::binary);
133 compress(fromdata, os, SER_FMT_VER_HIGHEST);
135 std::string str_out = os.str();
137 dstream<<"str_out.size()="<<str_out.size()<<std::endl;
138 dstream<<"TestCompress: 1,5,5,1 -> ";
139 for(u32 i=0; i<str_out.size(); i++)
141 dstream<<(u32)str_out[i]<<",";
145 /*assert(str_out.size() == 10);
147 assert(str_out[0] == 0);
148 assert(str_out[1] == 0);
149 assert(str_out[2] == 0);
150 assert(str_out[3] == 4);
151 assert(str_out[4] == 0);
152 assert(str_out[5] == 1);
153 assert(str_out[6] == 1);
154 assert(str_out[7] == 5);
155 assert(str_out[8] == 0);
156 assert(str_out[9] == 1);*/
158 std::istringstream is(str_out, std::ios_base::binary);
159 std::ostringstream os2(std::ios_base::binary);
161 decompress(is, os2, SER_FMT_VER_HIGHEST);
162 std::string str_out2 = os2.str();
164 dstream<<"decompress: ";
165 for(u32 i=0; i<str_out2.size(); i++)
167 dstream<<(u32)str_out2[i]<<",";
171 assert(str_out2.size() == fromdata.getSize());
173 for(u32 i=0; i<str_out2.size(); i++)
175 assert(str_out2[i] == fromdata[i]);
189 assert(n.d == CONTENT_AIR);
190 assert(n.getLight(LIGHTBANK_DAY) == 0);
191 assert(n.getLight(LIGHTBANK_NIGHT) == 0);
195 assert(n.light_propagates() == true);
197 assert(n.light_propagates() == false);
201 struct TestVoxelManipulator
209 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
210 assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
211 assert(a.index(-1,-1,-1) == 0);
213 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
214 // An area that is 1 bigger in x+ and z-
215 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
217 core::list<VoxelArea> aa;
221 core::array<VoxelArea> results;
222 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
223 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
225 assert(aa.size() == results.size());
227 dstream<<"Result of diff:"<<std::endl;
228 for(core::list<VoxelArea>::Iterator
229 i = aa.begin(); i != aa.end(); i++)
234 s32 j = results.linear_search(*i);
248 dstream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
250 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(2));
254 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
256 dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
258 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
262 dstream<<"*** Adding area ***"<<std::endl;
268 assert(v.getNode(v3s16(-1,0,-1)).d == 2);
269 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
278 const char *content =
290 v3s16 size(12, 4, 2);
291 VoxelArea area(v3s16(0,0,0), size-v3s16(1,1,1));
293 const char *p = content;
294 for(s16 z=0; z<size.Z; z++)
295 for(s16 y=size.Y-1; y>=0; y--)
296 for(s16 x=0; x<size.X; x++)
299 //n.pressure = size.Y - y;
308 v.setNode(v3s16(x,y,z), n);
312 v.print(dstream, VOXELPRINT_WATERPRESSURE);
314 core::map<v3s16, u8> active_nodes;
315 v.updateAreaWaterPressure(area, active_nodes);
317 v.print(dstream, VOXELPRINT_WATERPRESSURE);
319 //s16 highest_y = -32768;
321 NOTE: These are commented out because this behaviour is changed
324 //assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == -1);
325 //assert(highest_y == 3);
326 /*assert(v.getWaterPressure(v3s16(7, 1, 1), highest_y, 0) == 3);
327 //assert(highest_y == 3);*/
329 active_nodes.clear();
330 active_nodes[v3s16(9,1,0)] = 1;
331 //v.flowWater(active_nodes, 0, true, 1000);
332 v.flowWater(active_nodes, 0, false, 1000);
334 dstream<<"Final result of flowWater:"<<std::endl;
335 v.print(dstream, VOXELPRINT_WATERPRESSURE);
344 class TC : public NodeContainer
350 core::list<v3s16> validity_exceptions;
354 position_valid = true;
357 virtual bool isValidPosition(v3s16 p)
359 //return position_valid ^ (p==position_valid_exception);
360 bool exception = false;
361 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
362 i != validity_exceptions.end(); i++)
370 return exception ? !position_valid : position_valid;
373 virtual MapNode getNode(v3s16 p)
375 if(isValidPosition(p) == false)
376 throw InvalidPositionException();
380 virtual void setNode(v3s16 p, MapNode & n)
382 if(isValidPosition(p) == false)
383 throw InvalidPositionException();
386 virtual u16 nodeContainerId() const
396 MapBlock b(&parent, v3s16(1,1,1));
397 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
399 assert(b.getPosRelative() == relpos);
401 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
402 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
403 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
404 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
405 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
406 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
408 assert(b.isValidPosition(v3s16(0,0,0)) == true);
409 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
410 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
411 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
412 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
413 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
416 TODO: this method should probably be removed
417 if the block size isn't going to be set variable
419 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
420 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
422 // Changed flag should be initially set
423 assert(b.getChangedFlag() == true);
424 b.resetChangedFlag();
425 assert(b.getChangedFlag() == false);
427 // All nodes should have been set to
428 // .d=CONTENT_AIR and .getLight() = 0
429 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
430 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
431 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
433 assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
434 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
435 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
439 Parent fetch functions
441 parent.position_valid = false;
446 // Positions in the block should still be valid
447 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
448 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
449 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
450 assert(n.d == CONTENT_AIR);
452 // ...but outside the block they should be invalid
453 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
454 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
455 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
458 bool exception_thrown = false;
460 // This should throw an exception
461 MapNode n = b.getNodeParent(v3s16(0,0,-1));
463 catch(InvalidPositionException &e)
465 exception_thrown = true;
467 assert(exception_thrown);
470 parent.position_valid = true;
471 // Now the positions outside should be valid
472 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
473 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
474 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
475 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
484 assert(b.getNode(p).d == 4);
485 //TODO: Update to new system
486 /*assert(b.getNodeTile(p) == 4);
487 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
492 // Set lighting of all nodes to 0
493 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
494 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
495 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
496 MapNode n = b.getNode(v3s16(x,y,z));
497 n.setLight(LIGHTBANK_DAY, 0);
498 n.setLight(LIGHTBANK_NIGHT, 0);
499 b.setNode(v3s16(x,y,z), n);
505 Check how the block handles being a lonely sky block
507 parent.position_valid = true;
508 b.setIsUnderground(false);
509 parent.node.d = CONTENT_AIR;
510 parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
511 parent.node.setLight(LIGHTBANK_NIGHT, 0);
512 core::map<v3s16, bool> light_sources;
513 // The bottom block is invalid, because we have a shadowing node
514 assert(b.propagateSunlight(light_sources) == false);
515 assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
516 assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
517 assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
518 assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
519 assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
520 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
521 assert(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
522 assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
523 assert(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
524 // According to MapBlock::getFaceLight,
525 // The face on the z+ side should have double-diminished light
526 //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
527 // The face on the z+ side should have diminished light
528 assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
531 Check how the block handles being in between blocks with some non-sunlight
532 while being underground
535 // Make neighbours to exist and set some non-sunlight to them
536 parent.position_valid = true;
537 b.setIsUnderground(true);
538 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
539 core::map<v3s16, bool> light_sources;
540 // The block below should be valid because there shouldn't be
541 // sunlight in there either
542 assert(b.propagateSunlight(light_sources, true) == true);
543 // Should not touch nodes that are not affected (that is, all of them)
544 //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
545 // Should set light of non-sunlighted blocks to 0.
546 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
549 Set up a situation where:
550 - There is only air in this block
551 - There is a valid non-sunlighted block at the bottom, and
552 - Invalid blocks elsewhere.
553 - the block is not underground.
555 This should result in bottom block invalidity
558 b.setIsUnderground(false);
560 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
561 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
562 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
565 n.setLight(LIGHTBANK_DAY, 0);
566 b.setNode(v3s16(x,y,z), n);
570 // Make neighbours invalid
571 parent.position_valid = false;
572 // Add exceptions to the top of the bottom block
573 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
574 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
576 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
578 // Lighting value for the valid nodes
579 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
580 core::map<v3s16, bool> light_sources;
581 // Bottom block is not valid
582 assert(b.propagateSunlight(light_sources) == false);
589 class TC : public NodeContainer
598 position_valid = true;
601 virtual bool isValidPosition(v3s16 p)
603 return position_valid;
606 virtual MapNode getNode(v3s16 p)
608 if(position_valid == false)
609 throw InvalidPositionException();
613 virtual void setNode(v3s16 p, MapNode & n)
615 if(position_valid == false)
616 throw InvalidPositionException();
619 virtual u16 nodeContainerId() const
628 parent.position_valid = false;
630 // Create one with no heightmaps
631 ServerMapSector sector(&parent, v2s16(1,1));
633 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
634 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1));
636 MapBlock * bref = sector.createBlankBlock(-2);
638 EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
639 assert(sector.getBlockNoCreate(-2) == bref);
641 //TODO: Check for AlreadyExistsException
643 /*bool exception_thrown = false;
647 catch(InvalidPositionException &e){
648 exception_thrown = true;
650 assert(exception_thrown);*/
659 const int port = 30003;
663 const char sendbuffer[] = "hello world!";
664 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
669 memset(rcvbuffer, 0, sizeof(rcvbuffer));
673 int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
677 //FIXME: This fails on some systems
678 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
679 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
683 struct TestConnection
688 Test helper functions
691 // Some constants for testing
692 u32 proto_id = 0x12345678;
695 SharedBuffer<u8> data1(1);
697 Address a(127,0,0,1, 10);
700 con::BufferedPacket p1 = con::makePacket(a, data1,
701 proto_id, peer_id, channel);
703 We should now have a packet with this data:
706 [4] u16 sender_peer_id
711 assert(readU32(&p1.data[0]) == proto_id);
712 assert(readU16(&p1.data[4]) == peer_id);
713 assert(readU8(&p1.data[6]) == channel);
714 assert(readU8(&p1.data[7]) == data1[0]);
716 //dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
718 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
720 /*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
721 <<data1.getSize()<<std::endl;
722 dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
723 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
724 dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
726 assert(p2.getSize() == 3 + data1.getSize());
727 assert(readU8(&p2[0]) == TYPE_RELIABLE);
728 assert(readU16(&p2[1]) == seqnum);
729 assert(readU8(&p2[3]) == data1[0]);
732 struct Handler : public con::PeerHandler
734 Handler(const char *a_name)
740 void peerAdded(con::Peer *peer)
742 dstream<<"Handler("<<name<<")::peerAdded(): "
743 "id="<<peer->id<<std::endl;
747 void deletingPeer(con::Peer *peer, bool timeout)
749 dstream<<"Handler("<<name<<")::deletingPeer(): "
751 <<", timeout="<<timeout<<std::endl;
763 DSTACK("TestConnection::Run");
768 Test some real connections
770 u32 proto_id = 0xad26846a;
772 Handler hand_server("server");
773 Handler hand_client("client");
775 dstream<<"** Creating server Connection"<<std::endl;
776 con::Connection server(proto_id, 512, 5.0, &hand_server);
779 dstream<<"** Creating client Connection"<<std::endl;
780 con::Connection client(proto_id, 512, 5.0, &hand_client);
782 assert(hand_server.count == 0);
783 assert(hand_client.count == 0);
787 Address server_address(127,0,0,1, 30001);
788 dstream<<"** running client.Connect()"<<std::endl;
789 client.Connect(server_address);
793 // Client should have added server now
794 assert(hand_client.count == 1);
795 assert(hand_client.last_id == 1);
796 // But server should not have added client
797 assert(hand_server.count == 0);
803 dstream<<"** running server.Receive()"<<std::endl;
804 u32 size = server.Receive(peer_id, data, 100);
805 dstream<<"** Server received: peer_id="<<peer_id
809 catch(con::NoIncomingDataException &e)
811 // No actual data received, but the client has
812 // probably been connected
815 // Client should be the same
816 assert(hand_client.count == 1);
817 assert(hand_client.last_id == 1);
818 // Server should have the client
819 assert(hand_server.count == 1);
820 assert(hand_server.last_id == 2);
824 while(client.Connected() == false)
830 dstream<<"** running client.Receive()"<<std::endl;
831 u32 size = client.Receive(peer_id, data, 100);
832 dstream<<"** Client received: peer_id="<<peer_id
836 catch(con::NoIncomingDataException &e)
848 dstream<<"** running server.Receive()"<<std::endl;
849 u32 size = server.Receive(peer_id, data, 100);
850 dstream<<"** Server received: peer_id="<<peer_id
854 catch(con::NoIncomingDataException &e)
859 /*u8 data[] = "Hello World!";
860 u32 datasize = sizeof(data);*/
861 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
863 dstream<<"** running client.Send()"<<std::endl;
864 client.Send(PEER_ID_SERVER, 0, data, true);
870 dstream<<"** running server.Receive()"<<std::endl;
871 u32 size = server.Receive(peer_id, recvdata, 100);
872 dstream<<"** Server received: peer_id="<<peer_id
876 assert(memcmp(*data, recvdata, data.getSize()) == 0);
879 u16 peer_id_client = 2;
883 Send consequent packets in different order
885 //u8 data1[] = "hello1";
886 //u8 data2[] = "hello2";
887 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
888 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
890 Address client_address =
891 server.GetPeer(peer_id_client)->address;
893 dstream<<"*** Sending packets in wrong order (2,1,2)"
897 con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
898 u16 sn = ch->next_outgoing_seqnum;
899 ch->next_outgoing_seqnum = sn+1;
900 server.Send(peer_id_client, chn, data2, true);
901 ch->next_outgoing_seqnum = sn;
902 server.Send(peer_id_client, chn, data1, true);
903 ch->next_outgoing_seqnum = sn+1;
904 server.Send(peer_id_client, chn, data2, true);
908 dstream<<"*** Receiving the packets"<<std::endl;
914 dstream<<"** running client.Receive()"<<std::endl;
916 size = client.Receive(peer_id, recvdata, 20);
917 dstream<<"** Client received: peer_id="<<peer_id
919 <<", data="<<recvdata
921 assert(size == data1.getSize());
922 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
923 assert(peer_id == PEER_ID_SERVER);
925 dstream<<"** running client.Receive()"<<std::endl;
927 size = client.Receive(peer_id, recvdata, 20);
928 dstream<<"** Client received: peer_id="<<peer_id
930 <<", data="<<recvdata
932 assert(size == data2.getSize());
933 assert(memcmp(*data2, recvdata, data2.getSize()) == 0);
934 assert(peer_id == PEER_ID_SERVER);
936 bool got_exception = false;
939 dstream<<"** running client.Receive()"<<std::endl;
941 size = client.Receive(peer_id, recvdata, 20);
942 dstream<<"** Client received: peer_id="<<peer_id
944 <<", data="<<recvdata
947 catch(con::NoIncomingDataException &e)
949 dstream<<"** No incoming data for client"<<std::endl;
950 got_exception = true;
952 assert(got_exception);
955 const int datasize = 30000;
956 SharedBuffer<u8> data1(datasize);
957 for(u16 i=0; i<datasize; i++){
961 dstream<<"Sending data (size="<<datasize<<"):";
962 for(int i=0; i<datasize && i<20; i++){
963 if(i%2==0) DEBUGPRINT(" ");
964 DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
970 server.Send(peer_id_client, 0, data1, true);
974 u8 recvdata[datasize + 1000];
975 dstream<<"** running client.Receive()"<<std::endl;
977 u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
978 dstream<<"** Client received: peer_id="<<peer_id
982 dstream<<"Received data (size="<<size<<"):";
983 for(int i=0; i<size && i<20; i++){
984 if(i%2==0) DEBUGPRINT(" ");
985 DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
991 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
992 assert(peer_id == PEER_ID_SERVER);
995 // Check peer handlers
996 assert(hand_client.count == 1);
997 assert(hand_client.last_id == 1);
998 assert(hand_server.count == 1);
999 assert(hand_server.last_id == 2);
1008 dstream<<"Running " #X <<std::endl;\
1014 DSTACK(__FUNCTION_NAME);
1015 dstream<<"run_tests() started"<<std::endl;
1016 TEST(TestUtilities);
1019 TEST(TestVoxelManipulator);
1021 TEST(TestMapSector);
1022 if(INTERNET_SIMULATOR == false){
1024 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1025 TEST(TestConnection);
1026 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1028 dstream<<"run_tests() passed"<<std::endl;