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);
345 class TC : public NodeContainer
351 core::list<v3s16> validity_exceptions;
355 position_valid = true;
358 virtual bool isValidPosition(v3s16 p)
360 //return position_valid ^ (p==position_valid_exception);
361 bool exception = false;
362 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
363 i != validity_exceptions.end(); i++)
371 return exception ? !position_valid : position_valid;
374 virtual MapNode getNode(v3s16 p)
376 if(isValidPosition(p) == false)
377 throw InvalidPositionException();
381 virtual void setNode(v3s16 p, MapNode & n)
383 if(isValidPosition(p) == false)
384 throw InvalidPositionException();
387 virtual u16 nodeContainerId() const
397 MapBlock b(&parent, v3s16(1,1,1));
398 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
400 assert(b.getPosRelative() == relpos);
402 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
403 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
404 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
405 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
406 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
407 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
409 assert(b.isValidPosition(v3s16(0,0,0)) == true);
410 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
411 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
412 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
413 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
414 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
417 TODO: this method should probably be removed
418 if the block size isn't going to be set variable
420 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
421 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
423 // Changed flag should be initially set
424 assert(b.getChangedFlag() == true);
425 b.resetChangedFlag();
426 assert(b.getChangedFlag() == false);
428 // All nodes should have been set to
429 // .d=CONTENT_IGNORE and .getLight() = 0
430 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
431 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
432 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
434 //assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
435 assert(b.getNode(v3s16(x,y,z)).d == CONTENT_IGNORE);
436 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
437 assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
441 MapNode n(CONTENT_AIR);
442 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
443 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
444 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
446 b.setNode(v3s16(x,y,z), n);
451 Parent fetch functions
453 parent.position_valid = false;
458 // Positions in the block should still be valid
459 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
460 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
461 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
462 assert(n.d == CONTENT_AIR);
464 // ...but outside the block they should be invalid
465 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
466 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
467 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
470 bool exception_thrown = false;
472 // This should throw an exception
473 MapNode n = b.getNodeParent(v3s16(0,0,-1));
475 catch(InvalidPositionException &e)
477 exception_thrown = true;
479 assert(exception_thrown);
482 parent.position_valid = true;
483 // Now the positions outside should be valid
484 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
485 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
486 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
487 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
496 assert(b.getNode(p).d == 4);
497 //TODO: Update to new system
498 /*assert(b.getNodeTile(p) == 4);
499 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
504 // Set lighting of all nodes to 0
505 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
506 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
507 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
508 MapNode n = b.getNode(v3s16(x,y,z));
509 n.setLight(LIGHTBANK_DAY, 0);
510 n.setLight(LIGHTBANK_NIGHT, 0);
511 b.setNode(v3s16(x,y,z), n);
517 Check how the block handles being a lonely sky block
519 parent.position_valid = true;
520 b.setIsUnderground(false);
521 parent.node.d = CONTENT_AIR;
522 parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
523 parent.node.setLight(LIGHTBANK_NIGHT, 0);
524 core::map<v3s16, bool> light_sources;
525 // The bottom block is invalid, because we have a shadowing node
526 assert(b.propagateSunlight(light_sources) == false);
527 assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
528 assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
529 assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
530 assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
531 assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
532 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
533 assert(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
534 assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
535 assert(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
536 // According to MapBlock::getFaceLight,
537 // The face on the z+ side should have double-diminished light
538 //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
539 // The face on the z+ side should have diminished light
540 assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
543 Check how the block handles being in between blocks with some non-sunlight
544 while being underground
547 // Make neighbours to exist and set some non-sunlight to them
548 parent.position_valid = true;
549 b.setIsUnderground(true);
550 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
551 core::map<v3s16, bool> light_sources;
552 // The block below should be valid because there shouldn't be
553 // sunlight in there either
554 assert(b.propagateSunlight(light_sources, true) == true);
555 // Should not touch nodes that are not affected (that is, all of them)
556 //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
557 // Should set light of non-sunlighted blocks to 0.
558 assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
561 Set up a situation where:
562 - There is only air in this block
563 - There is a valid non-sunlighted block at the bottom, and
564 - Invalid blocks elsewhere.
565 - the block is not underground.
567 This should result in bottom block invalidity
570 b.setIsUnderground(false);
572 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
573 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
574 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
577 n.setLight(LIGHTBANK_DAY, 0);
578 b.setNode(v3s16(x,y,z), n);
582 // Make neighbours invalid
583 parent.position_valid = false;
584 // Add exceptions to the top of the bottom block
585 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
586 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
588 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
590 // Lighting value for the valid nodes
591 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
592 core::map<v3s16, bool> light_sources;
593 // Bottom block is not valid
594 assert(b.propagateSunlight(light_sources) == false);
601 class TC : public NodeContainer
610 position_valid = true;
613 virtual bool isValidPosition(v3s16 p)
615 return position_valid;
618 virtual MapNode getNode(v3s16 p)
620 if(position_valid == false)
621 throw InvalidPositionException();
625 virtual void setNode(v3s16 p, MapNode & n)
627 if(position_valid == false)
628 throw InvalidPositionException();
631 virtual u16 nodeContainerId() const
640 parent.position_valid = false;
642 // Create one with no heightmaps
643 ServerMapSector sector(&parent, v2s16(1,1));
645 assert(sector.getBlockNoCreateNoEx(0) == 0);
646 assert(sector.getBlockNoCreateNoEx(1) == 0);
648 MapBlock * bref = sector.createBlankBlock(-2);
650 assert(sector.getBlockNoCreateNoEx(0) == 0);
651 assert(sector.getBlockNoCreateNoEx(-2) == bref);
653 //TODO: Check for AlreadyExistsException
655 /*bool exception_thrown = false;
659 catch(InvalidPositionException &e){
660 exception_thrown = true;
662 assert(exception_thrown);*/
671 const int port = 30003;
675 const char sendbuffer[] = "hello world!";
676 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
681 memset(rcvbuffer, 0, sizeof(rcvbuffer));
685 int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
689 //FIXME: This fails on some systems
690 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
691 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
695 struct TestConnection
700 Test helper functions
703 // Some constants for testing
704 u32 proto_id = 0x12345678;
707 SharedBuffer<u8> data1(1);
709 Address a(127,0,0,1, 10);
712 con::BufferedPacket p1 = con::makePacket(a, data1,
713 proto_id, peer_id, channel);
715 We should now have a packet with this data:
718 [4] u16 sender_peer_id
723 assert(readU32(&p1.data[0]) == proto_id);
724 assert(readU16(&p1.data[4]) == peer_id);
725 assert(readU8(&p1.data[6]) == channel);
726 assert(readU8(&p1.data[7]) == data1[0]);
728 //dstream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
730 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
732 /*dstream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
733 <<data1.getSize()<<std::endl;
734 dstream<<"readU8(&p2[3])="<<readU8(&p2[3])
735 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
736 dstream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
738 assert(p2.getSize() == 3 + data1.getSize());
739 assert(readU8(&p2[0]) == TYPE_RELIABLE);
740 assert(readU16(&p2[1]) == seqnum);
741 assert(readU8(&p2[3]) == data1[0]);
744 struct Handler : public con::PeerHandler
746 Handler(const char *a_name)
752 void peerAdded(con::Peer *peer)
754 dstream<<"Handler("<<name<<")::peerAdded(): "
755 "id="<<peer->id<<std::endl;
759 void deletingPeer(con::Peer *peer, bool timeout)
761 dstream<<"Handler("<<name<<")::deletingPeer(): "
763 <<", timeout="<<timeout<<std::endl;
775 DSTACK("TestConnection::Run");
780 Test some real connections
782 u32 proto_id = 0xad26846a;
784 Handler hand_server("server");
785 Handler hand_client("client");
787 dstream<<"** Creating server Connection"<<std::endl;
788 con::Connection server(proto_id, 512, 5.0, &hand_server);
791 dstream<<"** Creating client Connection"<<std::endl;
792 con::Connection client(proto_id, 512, 5.0, &hand_client);
794 assert(hand_server.count == 0);
795 assert(hand_client.count == 0);
799 Address server_address(127,0,0,1, 30001);
800 dstream<<"** running client.Connect()"<<std::endl;
801 client.Connect(server_address);
805 // Client should have added server now
806 assert(hand_client.count == 1);
807 assert(hand_client.last_id == 1);
808 // But server should not have added client
809 assert(hand_server.count == 0);
815 dstream<<"** running server.Receive()"<<std::endl;
816 u32 size = server.Receive(peer_id, data, 100);
817 dstream<<"** Server received: peer_id="<<peer_id
821 catch(con::NoIncomingDataException &e)
823 // No actual data received, but the client has
824 // probably been connected
827 // Client should be the same
828 assert(hand_client.count == 1);
829 assert(hand_client.last_id == 1);
830 // Server should have the client
831 assert(hand_server.count == 1);
832 assert(hand_server.last_id == 2);
836 while(client.Connected() == false)
842 dstream<<"** running client.Receive()"<<std::endl;
843 u32 size = client.Receive(peer_id, data, 100);
844 dstream<<"** Client received: peer_id="<<peer_id
848 catch(con::NoIncomingDataException &e)
860 dstream<<"** running server.Receive()"<<std::endl;
861 u32 size = server.Receive(peer_id, data, 100);
862 dstream<<"** Server received: peer_id="<<peer_id
866 catch(con::NoIncomingDataException &e)
871 /*u8 data[] = "Hello World!";
872 u32 datasize = sizeof(data);*/
873 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
875 dstream<<"** running client.Send()"<<std::endl;
876 client.Send(PEER_ID_SERVER, 0, data, true);
882 dstream<<"** running server.Receive()"<<std::endl;
883 u32 size = server.Receive(peer_id, recvdata, 100);
884 dstream<<"** Server received: peer_id="<<peer_id
888 assert(memcmp(*data, recvdata, data.getSize()) == 0);
891 u16 peer_id_client = 2;
895 Send consequent packets in different order
897 //u8 data1[] = "hello1";
898 //u8 data2[] = "hello2";
899 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
900 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
902 Address client_address =
903 server.GetPeer(peer_id_client)->address;
905 dstream<<"*** Sending packets in wrong order (2,1,2)"
909 con::Channel *ch = &server.GetPeer(peer_id_client)->channels[chn];
910 u16 sn = ch->next_outgoing_seqnum;
911 ch->next_outgoing_seqnum = sn+1;
912 server.Send(peer_id_client, chn, data2, true);
913 ch->next_outgoing_seqnum = sn;
914 server.Send(peer_id_client, chn, data1, true);
915 ch->next_outgoing_seqnum = sn+1;
916 server.Send(peer_id_client, chn, data2, true);
920 dstream<<"*** Receiving the packets"<<std::endl;
926 dstream<<"** running client.Receive()"<<std::endl;
928 size = client.Receive(peer_id, recvdata, 20);
929 dstream<<"** Client received: peer_id="<<peer_id
931 <<", data="<<recvdata
933 assert(size == data1.getSize());
934 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
935 assert(peer_id == PEER_ID_SERVER);
937 dstream<<"** running client.Receive()"<<std::endl;
939 size = client.Receive(peer_id, recvdata, 20);
940 dstream<<"** Client received: peer_id="<<peer_id
942 <<", data="<<recvdata
944 assert(size == data2.getSize());
945 assert(memcmp(*data2, recvdata, data2.getSize()) == 0);
946 assert(peer_id == PEER_ID_SERVER);
948 bool got_exception = false;
951 dstream<<"** running client.Receive()"<<std::endl;
953 size = client.Receive(peer_id, recvdata, 20);
954 dstream<<"** Client received: peer_id="<<peer_id
956 <<", data="<<recvdata
959 catch(con::NoIncomingDataException &e)
961 dstream<<"** No incoming data for client"<<std::endl;
962 got_exception = true;
964 assert(got_exception);
967 const int datasize = 30000;
968 SharedBuffer<u8> data1(datasize);
969 for(u16 i=0; i<datasize; i++){
973 dstream<<"Sending data (size="<<datasize<<"):";
974 for(int i=0; i<datasize && i<20; i++){
975 if(i%2==0) DEBUGPRINT(" ");
976 DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
982 server.Send(peer_id_client, 0, data1, true);
986 u8 recvdata[datasize + 1000];
987 dstream<<"** running client.Receive()"<<std::endl;
989 u16 size = client.Receive(peer_id, recvdata, datasize + 1000);
990 dstream<<"** Client received: peer_id="<<peer_id
994 dstream<<"Received data (size="<<size<<"):";
995 for(int i=0; i<size && i<20; i++){
996 if(i%2==0) DEBUGPRINT(" ");
997 DEBUGPRINT("%.2X", ((int)((const char*)recvdata)[i])&0xff);
1003 assert(memcmp(*data1, recvdata, data1.getSize()) == 0);
1004 assert(peer_id == PEER_ID_SERVER);
1007 // Check peer handlers
1008 assert(hand_client.count == 1);
1009 assert(hand_client.last_id == 1);
1010 assert(hand_server.count == 1);
1011 assert(hand_server.last_id == 2);
1020 dstream<<"Running " #X <<std::endl;\
1026 DSTACK(__FUNCTION_NAME);
1027 dstream<<"run_tests() started"<<std::endl;
1028 TEST(TestUtilities);
1031 TEST(TestVoxelManipulator);
1033 TEST(TestMapSector);
1034 if(INTERNET_SIMULATOR == false){
1036 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1037 TEST(TestConnection);
1038 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1040 dstream<<"run_tests() passed"<<std::endl;