caf31d1af9d2e823372e18852b0b583f2ce928ed
[oweals/minetest.git] / src / test.cpp
1 /*
2 Minetest-c55
3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
4
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.
9
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.
14
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.
18 */
19
20 #include "test.h"
21 #include "common_irrlicht.h"
22 #include "debug.h"
23 #include "map.h"
24 #include "player.h"
25 #include "main.h"
26 #include "socket.h"
27 #include "connection.h"
28 #include "utility.h"
29 #include "serialization.h"
30 #include "voxel.h"
31 #include <sstream>
32 #include "porting.h"
33 #include "content_mapnode.h"
34 #include "nodedef.h"
35 #include "mapsector.h"
36 #include "settings.h"
37 #include "log.h"
38
39 /*
40         Asserts that the exception occurs
41 */
42 #define EXCEPTION_CHECK(EType, code)\
43 {\
44         bool exception_thrown = false;\
45         try{ code; }\
46         catch(EType &e) { exception_thrown = true; }\
47         assert(exception_thrown);\
48 }
49
50 /*
51         A few item and node definitions for those tests that need them
52 */
53
54 #define CONTENT_STONE 0
55 #define CONTENT_GRASS 0x800
56
57 void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *ndef)
58 {
59         content_t i;
60         ItemDefinition itemdef;
61         ContentFeatures f;
62
63         /*
64                 Stone
65         */
66         i = CONTENT_STONE;
67         itemdef = ItemDefinition();
68         itemdef.type = ITEM_NODE;
69         itemdef.name = "default:stone";
70         itemdef.description = "Stone";
71         itemdef.inventory_image = "[inventorycube"
72                 "{default_stone.png"
73                 "{default_stone.png"
74                 "{default_stone.png";
75         f = ContentFeatures();
76         f.name = itemdef.name;
77         for(int i = 0; i < 6; i++)
78                 f.tname_tiles[i] = "default_stone.png";
79         f.param_type = CPT_MINERAL;
80         f.is_ground_content = true;
81         f.dug_item = itemdef.name;
82         f.material.diggability = DIGGABLE_NORMAL;
83         f.material.weight = 5.0;
84         f.material.crackiness = 1.0;
85         f.material.crumbliness = -0.1;
86         f.material.cuttability = -0.2;
87         idef->registerItem(itemdef);
88         ndef->set(i, f);
89
90         /*
91                 Grass
92         */
93         i = CONTENT_GRASS;
94         itemdef = ItemDefinition();
95         itemdef.type = ITEM_NODE;
96         itemdef.name = "default:dirt_with_grass";
97         itemdef.description = "Dirt with grass";
98         itemdef.inventory_image = "[inventorycube"
99                 "{default_grass.png"
100                 "{default_dirt.png&default_grass_side.png"
101                 "{default_dirt.png&default_grass_side.png";
102         f = ContentFeatures();
103         f.name = itemdef.name;
104         f.tname_tiles[0] = "default_grass.png";
105         f.tname_tiles[1] = "default_dirt.png";
106         for(int i = 2; i < 6; i++)
107                 f.tname_tiles[i] = "default_dirt.png^default_grass_side.png";
108         f.is_ground_content = true;
109         f.dug_item = itemdef.name;
110         f.material.diggability = DIGGABLE_NORMAL;
111         f.material.weight = 1.2;
112         f.material.crackiness = 0.0;
113         f.material.crumbliness = 1.2;
114         f.material.cuttability = -0.4;
115         idef->registerItem(itemdef);
116         ndef->set(i, f);
117 }
118
119 struct TestUtilities
120 {
121         void Run()
122         {
123                 /*infostream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
124                 infostream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
125                 infostream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
126                 assert(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
127                 assert(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
128                 assert(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
129                 assert(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
130                 assert(lowercase("Foo bAR") == "foo bar");
131                 assert(is_yes("YeS") == true);
132                 assert(is_yes("") == false);
133                 assert(is_yes("FAlse") == false);
134         }
135 };
136
137 struct TestSettings
138 {
139         void Run()
140         {
141                 Settings s;
142                 // Test reading of settings
143                 s.parseConfigLine("leet = 1337");
144                 s.parseConfigLine("leetleet = 13371337");
145                 s.parseConfigLine("leetleet_neg = -13371337");
146                 s.parseConfigLine("floaty_thing = 1.1");
147                 s.parseConfigLine("stringy_thing = asd /( ¤%&(/\" BLÖÄRP");
148                 s.parseConfigLine("coord = (1, 2, 4.5)");
149                 assert(s.getS32("leet") == 1337);
150                 assert(s.getS16("leetleet") == 32767);
151                 assert(s.getS16("leetleet_neg") == -32768);
152                 // Not sure if 1.1 is an exact value as a float, but doesn't matter
153                 assert(fabs(s.getFloat("floaty_thing") - 1.1) < 0.001);
154                 assert(s.get("stringy_thing") == "asd /( ¤%&(/\" BLÖÄRP");
155                 assert(fabs(s.getV3F("coord").X - 1.0) < 0.001);
156                 assert(fabs(s.getV3F("coord").Y - 2.0) < 0.001);
157                 assert(fabs(s.getV3F("coord").Z - 4.5) < 0.001);
158                 // Test the setting of settings too
159                 s.setFloat("floaty_thing_2", 1.2);
160                 s.setV3F("coord2", v3f(1, 2, 3.3));
161                 assert(s.get("floaty_thing_2").substr(0,3) == "1.2");
162                 assert(fabs(s.getFloat("floaty_thing_2") - 1.2) < 0.001);
163                 assert(fabs(s.getV3F("coord2").X - 1.0) < 0.001);
164                 assert(fabs(s.getV3F("coord2").Y - 2.0) < 0.001);
165                 assert(fabs(s.getV3F("coord2").Z - 3.3) < 0.001);
166         }
167 };
168
169 struct TestSerialization
170 {
171         // To be used like this:
172         //   mkstr("Some\0string\0with\0embedded\0nuls")
173         // since std::string("...") doesn't work as expected in that case.
174         template<size_t N> std::string mkstr(const char (&s)[N])
175         {
176                 return std::string(s, N - 1);
177         }
178
179         void Run()
180         {
181                 // Tests some serialization primitives
182
183                 assert(serializeString("") == mkstr("\0\0"));
184                 assert(serializeWideString(L"") == mkstr("\0\0"));
185                 assert(serializeLongString("") == mkstr("\0\0\0\0"));
186                 assert(serializeJsonString("") == "\"\"");
187                 
188                 std::string teststring = "Hello world!";
189                 assert(serializeString(teststring) ==
190                         mkstr("\0\14Hello world!"));
191                 assert(serializeWideString(narrow_to_wide(teststring)) ==
192                         mkstr("\0\14\0H\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0!"));
193                 assert(serializeLongString(teststring) ==
194                         mkstr("\0\0\0\14Hello world!"));
195                 assert(serializeJsonString(teststring) ==
196                         "\"Hello world!\"");
197
198                 std::string teststring2;
199                 std::wstring teststring2_w;
200                 std::string teststring2_w_encoded;
201                 {
202                         std::ostringstream tmp_os;
203                         std::wostringstream tmp_os_w;
204                         std::ostringstream tmp_os_w_encoded;
205                         for(int i = 0; i < 256; i++)
206                         {
207                                 tmp_os<<(char)i;
208                                 tmp_os_w<<(wchar_t)i;
209                                 tmp_os_w_encoded<<(char)0<<(char)i;
210                         }
211                         teststring2 = tmp_os.str();
212                         teststring2_w = tmp_os_w.str();
213                         teststring2_w_encoded = tmp_os_w_encoded.str();
214                 }
215                 assert(serializeString(teststring2) ==
216                         mkstr("\1\0") + teststring2);
217                 assert(serializeWideString(teststring2_w) ==
218                         mkstr("\1\0") + teststring2_w_encoded);
219                 assert(serializeLongString(teststring2) ==
220                         mkstr("\0\0\1\0") + teststring2);
221                 assert(serializeJsonString(teststring2) ==
222                         mkstr("\"") +
223                         "\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007" +
224                         "\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f" +
225                         "\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017" +
226                         "\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f" +
227                         " !\\\"" + teststring2.substr(0x23, 0x2f-0x23) +
228                         "\\/" + teststring2.substr(0x30, 0x5c-0x30) +
229                         "\\\\" + teststring2.substr(0x5d, 0x7f-0x5d) + "\\u007f" +
230                         "\\u0080\\u0081\\u0082\\u0083\\u0084\\u0085\\u0086\\u0087" +
231                         "\\u0088\\u0089\\u008a\\u008b\\u008c\\u008d\\u008e\\u008f" +
232                         "\\u0090\\u0091\\u0092\\u0093\\u0094\\u0095\\u0096\\u0097" +
233                         "\\u0098\\u0099\\u009a\\u009b\\u009c\\u009d\\u009e\\u009f" +
234                         "\\u00a0\\u00a1\\u00a2\\u00a3\\u00a4\\u00a5\\u00a6\\u00a7" +
235                         "\\u00a8\\u00a9\\u00aa\\u00ab\\u00ac\\u00ad\\u00ae\\u00af" +
236                         "\\u00b0\\u00b1\\u00b2\\u00b3\\u00b4\\u00b5\\u00b6\\u00b7" +
237                         "\\u00b8\\u00b9\\u00ba\\u00bb\\u00bc\\u00bd\\u00be\\u00bf" +
238                         "\\u00c0\\u00c1\\u00c2\\u00c3\\u00c4\\u00c5\\u00c6\\u00c7" +
239                         "\\u00c8\\u00c9\\u00ca\\u00cb\\u00cc\\u00cd\\u00ce\\u00cf" +
240                         "\\u00d0\\u00d1\\u00d2\\u00d3\\u00d4\\u00d5\\u00d6\\u00d7" +
241                         "\\u00d8\\u00d9\\u00da\\u00db\\u00dc\\u00dd\\u00de\\u00df" +
242                         "\\u00e0\\u00e1\\u00e2\\u00e3\\u00e4\\u00e5\\u00e6\\u00e7" +
243                         "\\u00e8\\u00e9\\u00ea\\u00eb\\u00ec\\u00ed\\u00ee\\u00ef" +
244                         "\\u00f0\\u00f1\\u00f2\\u00f3\\u00f4\\u00f5\\u00f6\\u00f7" +
245                         "\\u00f8\\u00f9\\u00fa\\u00fb\\u00fc\\u00fd\\u00fe\\u00ff" +
246                         "\"");
247
248                 {
249                         std::istringstream is(serializeString(teststring2), std::ios::binary);
250                         assert(deSerializeString(is) == teststring2);
251                         assert(!is.eof());
252                         is.get();
253                         assert(is.eof());
254                 }
255                 {
256                         std::istringstream is(serializeWideString(teststring2_w), std::ios::binary);
257                         assert(deSerializeWideString(is) == teststring2_w);
258                         assert(!is.eof());
259                         is.get();
260                         assert(is.eof());
261                 }
262                 {
263                         std::istringstream is(serializeLongString(teststring2), std::ios::binary);
264                         assert(deSerializeLongString(is) == teststring2);
265                         assert(!is.eof());
266                         is.get();
267                         assert(is.eof());
268                 }
269                 {
270                         std::istringstream is(serializeJsonString(teststring2), std::ios::binary);
271                         //dstream<<serializeJsonString(deSerializeJsonString(is));
272                         assert(deSerializeJsonString(is) == teststring2);
273                         assert(!is.eof());
274                         is.get();
275                         assert(is.eof());
276                 }
277         }
278 };
279
280 struct TestCompress
281 {
282         void Run()
283         {
284                 { // ver 0
285
286                 SharedBuffer<u8> fromdata(4);
287                 fromdata[0]=1;
288                 fromdata[1]=5;
289                 fromdata[2]=5;
290                 fromdata[3]=1;
291                 
292                 std::ostringstream os(std::ios_base::binary);
293                 compress(fromdata, os, 0);
294
295                 std::string str_out = os.str();
296                 
297                 infostream<<"str_out.size()="<<str_out.size()<<std::endl;
298                 infostream<<"TestCompress: 1,5,5,1 -> ";
299                 for(u32 i=0; i<str_out.size(); i++)
300                 {
301                         infostream<<(u32)str_out[i]<<",";
302                 }
303                 infostream<<std::endl;
304
305                 assert(str_out.size() == 10);
306
307                 assert(str_out[0] == 0);
308                 assert(str_out[1] == 0);
309                 assert(str_out[2] == 0);
310                 assert(str_out[3] == 4);
311                 assert(str_out[4] == 0);
312                 assert(str_out[5] == 1);
313                 assert(str_out[6] == 1);
314                 assert(str_out[7] == 5);
315                 assert(str_out[8] == 0);
316                 assert(str_out[9] == 1);
317
318                 std::istringstream is(str_out, std::ios_base::binary);
319                 std::ostringstream os2(std::ios_base::binary);
320
321                 decompress(is, os2, 0);
322                 std::string str_out2 = os2.str();
323
324                 infostream<<"decompress: ";
325                 for(u32 i=0; i<str_out2.size(); i++)
326                 {
327                         infostream<<(u32)str_out2[i]<<",";
328                 }
329                 infostream<<std::endl;
330
331                 assert(str_out2.size() == fromdata.getSize());
332
333                 for(u32 i=0; i<str_out2.size(); i++)
334                 {
335                         assert(str_out2[i] == fromdata[i]);
336                 }
337
338                 }
339
340                 { // ver HIGHEST
341
342                 SharedBuffer<u8> fromdata(4);
343                 fromdata[0]=1;
344                 fromdata[1]=5;
345                 fromdata[2]=5;
346                 fromdata[3]=1;
347                 
348                 std::ostringstream os(std::ios_base::binary);
349                 compress(fromdata, os, SER_FMT_VER_HIGHEST);
350
351                 std::string str_out = os.str();
352                 
353                 infostream<<"str_out.size()="<<str_out.size()<<std::endl;
354                 infostream<<"TestCompress: 1,5,5,1 -> ";
355                 for(u32 i=0; i<str_out.size(); i++)
356                 {
357                         infostream<<(u32)str_out[i]<<",";
358                 }
359                 infostream<<std::endl;
360
361                 /*assert(str_out.size() == 10);
362
363                 assert(str_out[0] == 0);
364                 assert(str_out[1] == 0);
365                 assert(str_out[2] == 0);
366                 assert(str_out[3] == 4);
367                 assert(str_out[4] == 0);
368                 assert(str_out[5] == 1);
369                 assert(str_out[6] == 1);
370                 assert(str_out[7] == 5);
371                 assert(str_out[8] == 0);
372                 assert(str_out[9] == 1);*/
373
374                 std::istringstream is(str_out, std::ios_base::binary);
375                 std::ostringstream os2(std::ios_base::binary);
376
377                 decompress(is, os2, SER_FMT_VER_HIGHEST);
378                 std::string str_out2 = os2.str();
379
380                 infostream<<"decompress: ";
381                 for(u32 i=0; i<str_out2.size(); i++)
382                 {
383                         infostream<<(u32)str_out2[i]<<",";
384                 }
385                 infostream<<std::endl;
386
387                 assert(str_out2.size() == fromdata.getSize());
388
389                 for(u32 i=0; i<str_out2.size(); i++)
390                 {
391                         assert(str_out2[i] == fromdata[i]);
392                 }
393
394                 }
395         }
396 };
397
398 struct TestMapNode
399 {
400         void Run(INodeDefManager *nodedef)
401         {
402                 MapNode n;
403
404                 // Default values
405                 assert(n.getContent() == CONTENT_AIR);
406                 assert(n.getLight(LIGHTBANK_DAY, nodedef) == 0);
407                 assert(n.getLight(LIGHTBANK_NIGHT, nodedef) == 0);
408                 
409                 // Transparency
410                 n.setContent(CONTENT_AIR);
411                 assert(nodedef->get(n).light_propagates == true);
412                 n.setContent(LEGN(nodedef, "CONTENT_STONE"));
413                 assert(nodedef->get(n).light_propagates == false);
414         }
415 };
416
417 struct TestVoxelManipulator
418 {
419         void Run(INodeDefManager *nodedef)
420         {
421                 /*
422                         VoxelArea
423                 */
424
425                 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
426                 assert(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
427                 assert(a.index(-1,-1,-1) == 0);
428                 
429                 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
430                 // An area that is 1 bigger in x+ and z-
431                 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
432                 
433                 core::list<VoxelArea> aa;
434                 d.diff(c, aa);
435                 
436                 // Correct results
437                 core::array<VoxelArea> results;
438                 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
439                 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
440
441                 assert(aa.size() == results.size());
442                 
443                 infostream<<"Result of diff:"<<std::endl;
444                 for(core::list<VoxelArea>::Iterator
445                                 i = aa.begin(); i != aa.end(); i++)
446                 {
447                         i->print(infostream);
448                         infostream<<std::endl;
449                         
450                         s32 j = results.linear_search(*i);
451                         assert(j != -1);
452                         results.erase(j, 1);
453                 }
454
455
456                 /*
457                         VoxelManipulator
458                 */
459                 
460                 VoxelManipulator v;
461
462                 v.print(infostream, nodedef);
463
464                 infostream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
465                 
466                 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(CONTENT_GRASS));
467
468                 v.print(infostream, nodedef);
469
470                 assert(v.getNode(v3s16(-1,0,-1)).getContent() == CONTENT_GRASS);
471
472                 infostream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
473
474                 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
475
476                 v.print(infostream, nodedef);
477
478                 infostream<<"*** Adding area ***"<<std::endl;
479
480                 v.addArea(a);
481                 
482                 v.print(infostream, nodedef);
483
484                 assert(v.getNode(v3s16(-1,0,-1)).getContent() == CONTENT_GRASS);
485                 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
486         }
487 };
488
489 /*
490         NOTE: These tests became non-working then NodeContainer was removed.
491               These should be redone, utilizing some kind of a virtual
492                   interface for Map (IMap would be fine).
493 */
494 #if 0
495 struct TestMapBlock
496 {
497         class TC : public NodeContainer
498         {
499         public:
500
501                 MapNode node;
502                 bool position_valid;
503                 core::list<v3s16> validity_exceptions;
504
505                 TC()
506                 {
507                         position_valid = true;
508                 }
509
510                 virtual bool isValidPosition(v3s16 p)
511                 {
512                         //return position_valid ^ (p==position_valid_exception);
513                         bool exception = false;
514                         for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
515                                         i != validity_exceptions.end(); i++)
516                         {
517                                 if(p == *i)
518                                 {
519                                         exception = true;
520                                         break;
521                                 }
522                         }
523                         return exception ? !position_valid : position_valid;
524                 }
525
526                 virtual MapNode getNode(v3s16 p)
527                 {
528                         if(isValidPosition(p) == false)
529                                 throw InvalidPositionException();
530                         return node;
531                 }
532
533                 virtual void setNode(v3s16 p, MapNode & n)
534                 {
535                         if(isValidPosition(p) == false)
536                                 throw InvalidPositionException();
537                 };
538
539                 virtual u16 nodeContainerId() const
540                 {
541                         return 666;
542                 }
543         };
544
545         void Run()
546         {
547                 TC parent;
548                 
549                 MapBlock b(&parent, v3s16(1,1,1));
550                 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
551
552                 assert(b.getPosRelative() == relpos);
553
554                 assert(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
555                 assert(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
556                 assert(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
557                 assert(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
558                 assert(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
559                 assert(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
560                 
561                 assert(b.isValidPosition(v3s16(0,0,0)) == true);
562                 assert(b.isValidPosition(v3s16(-1,0,0)) == false);
563                 assert(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
564                 assert(b.isValidPosition(v3s16(-124,142,2341)) == false);
565                 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
566                 assert(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
567
568                 /*
569                         TODO: this method should probably be removed
570                         if the block size isn't going to be set variable
571                 */
572                 /*assert(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
573                                 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
574                 
575                 // Changed flag should be initially set
576                 assert(b.getModified() == MOD_STATE_WRITE_NEEDED);
577                 b.resetModified();
578                 assert(b.getModified() == MOD_STATE_CLEAN);
579
580                 // All nodes should have been set to
581                 // .d=CONTENT_IGNORE and .getLight() = 0
582                 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
583                 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
584                 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
585                 {
586                         //assert(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_AIR);
587                         assert(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_IGNORE);
588                         assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
589                         assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
590                 }
591                 
592                 {
593                         MapNode n(CONTENT_AIR);
594                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
595                         for(u16 y=0; y<MAP_BLOCKSIZE; y++)
596                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
597                         {
598                                 b.setNode(v3s16(x,y,z), n);
599                         }
600                 }
601                         
602                 /*
603                         Parent fetch functions
604                 */
605                 parent.position_valid = false;
606                 parent.node.setContent(5);
607
608                 MapNode n;
609                 
610                 // Positions in the block should still be valid
611                 assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
612                 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
613                 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
614                 assert(n.getContent() == CONTENT_AIR);
615
616                 // ...but outside the block they should be invalid
617                 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
618                 assert(b.isValidPositionParent(v3s16(-1,0,0)) == false);
619                 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
620                 
621                 {
622                         bool exception_thrown = false;
623                         try{
624                                 // This should throw an exception
625                                 MapNode n = b.getNodeParent(v3s16(0,0,-1));
626                         }
627                         catch(InvalidPositionException &e)
628                         {
629                                 exception_thrown = true;
630                         }
631                         assert(exception_thrown);
632                 }
633
634                 parent.position_valid = true;
635                 // Now the positions outside should be valid
636                 assert(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
637                 assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
638                 assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
639                 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
640                 assert(n.getContent() == 5);
641
642                 /*
643                         Set a node
644                 */
645                 v3s16 p(1,2,0);
646                 n.setContent(4);
647                 b.setNode(p, n);
648                 assert(b.getNode(p).getContent() == 4);
649                 //TODO: Update to new system
650                 /*assert(b.getNodeTile(p) == 4);
651                 assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
652                 
653                 /*
654                         propagateSunlight()
655                 */
656                 // Set lighting of all nodes to 0
657                 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
658                         for(u16 y=0; y<MAP_BLOCKSIZE; y++){
659                                 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
660                                         MapNode n = b.getNode(v3s16(x,y,z));
661                                         n.setLight(LIGHTBANK_DAY, 0);
662                                         n.setLight(LIGHTBANK_NIGHT, 0);
663                                         b.setNode(v3s16(x,y,z), n);
664                                 }
665                         }
666                 }
667                 {
668                         /*
669                                 Check how the block handles being a lonely sky block
670                         */
671                         parent.position_valid = true;
672                         b.setIsUnderground(false);
673                         parent.node.setContent(CONTENT_AIR);
674                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
675                         parent.node.setLight(LIGHTBANK_NIGHT, 0);
676                         core::map<v3s16, bool> light_sources;
677                         // The bottom block is invalid, because we have a shadowing node
678                         assert(b.propagateSunlight(light_sources) == false);
679                         assert(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
680                         assert(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
681                         assert(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
682                         assert(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
683                         assert(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
684                         assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
685                         assert(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
686                         assert(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
687                         assert(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
688                         // According to MapBlock::getFaceLight,
689                         // The face on the z+ side should have double-diminished light
690                         //assert(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
691                         // The face on the z+ side should have diminished light
692                         assert(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
693                 }
694                 /*
695                         Check how the block handles being in between blocks with some non-sunlight
696                         while being underground
697                 */
698                 {
699                         // Make neighbours to exist and set some non-sunlight to them
700                         parent.position_valid = true;
701                         b.setIsUnderground(true);
702                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
703                         core::map<v3s16, bool> light_sources;
704                         // The block below should be valid because there shouldn't be
705                         // sunlight in there either
706                         assert(b.propagateSunlight(light_sources, true) == true);
707                         // Should not touch nodes that are not affected (that is, all of them)
708                         //assert(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
709                         // Should set light of non-sunlighted blocks to 0.
710                         assert(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
711                 }
712                 /*
713                         Set up a situation where:
714                         - There is only air in this block
715                         - There is a valid non-sunlighted block at the bottom, and
716                         - Invalid blocks elsewhere.
717                         - the block is not underground.
718
719                         This should result in bottom block invalidity
720                 */
721                 {
722                         b.setIsUnderground(false);
723                         // Clear block
724                         for(u16 z=0; z<MAP_BLOCKSIZE; z++){
725                                 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
726                                         for(u16 x=0; x<MAP_BLOCKSIZE; x++){
727                                                 MapNode n;
728                                                 n.setContent(CONTENT_AIR);
729                                                 n.setLight(LIGHTBANK_DAY, 0);
730                                                 b.setNode(v3s16(x,y,z), n);
731                                         }
732                                 }
733                         }
734                         // Make neighbours invalid
735                         parent.position_valid = false;
736                         // Add exceptions to the top of the bottom block
737                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
738                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
739                         {
740                                 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
741                         }
742                         // Lighting value for the valid nodes
743                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
744                         core::map<v3s16, bool> light_sources;
745                         // Bottom block is not valid
746                         assert(b.propagateSunlight(light_sources) == false);
747                 }
748         }
749 };
750
751 struct TestMapSector
752 {
753         class TC : public NodeContainer
754         {
755         public:
756
757                 MapNode node;
758                 bool position_valid;
759
760                 TC()
761                 {
762                         position_valid = true;
763                 }
764
765                 virtual bool isValidPosition(v3s16 p)
766                 {
767                         return position_valid;
768                 }
769
770                 virtual MapNode getNode(v3s16 p)
771                 {
772                         if(position_valid == false)
773                                 throw InvalidPositionException();
774                         return node;
775                 }
776
777                 virtual void setNode(v3s16 p, MapNode & n)
778                 {
779                         if(position_valid == false)
780                                 throw InvalidPositionException();
781                 };
782                 
783                 virtual u16 nodeContainerId() const
784                 {
785                         return 666;
786                 }
787         };
788         
789         void Run()
790         {
791                 TC parent;
792                 parent.position_valid = false;
793                 
794                 // Create one with no heightmaps
795                 ServerMapSector sector(&parent, v2s16(1,1));
796                 
797                 assert(sector.getBlockNoCreateNoEx(0) == 0);
798                 assert(sector.getBlockNoCreateNoEx(1) == 0);
799
800                 MapBlock * bref = sector.createBlankBlock(-2);
801                 
802                 assert(sector.getBlockNoCreateNoEx(0) == 0);
803                 assert(sector.getBlockNoCreateNoEx(-2) == bref);
804                 
805                 //TODO: Check for AlreadyExistsException
806
807                 /*bool exception_thrown = false;
808                 try{
809                         sector.getBlock(0);
810                 }
811                 catch(InvalidPositionException &e){
812                         exception_thrown = true;
813                 }
814                 assert(exception_thrown);*/
815
816         }
817 };
818 #endif
819
820 struct TestSocket
821 {
822         void Run()
823         {
824                 const int port = 30003;
825                 UDPSocket socket;
826                 socket.Bind(port);
827
828                 const char sendbuffer[] = "hello world!";
829                 socket.Send(Address(127,0,0,1,port), sendbuffer, sizeof(sendbuffer));
830
831                 sleep_ms(50);
832
833                 char rcvbuffer[256];
834                 memset(rcvbuffer, 0, sizeof(rcvbuffer));
835                 Address sender;
836                 for(;;)
837                 {
838                         int bytes_read = socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer));
839                         if(bytes_read < 0)
840                                 break;
841                 }
842                 //FIXME: This fails on some systems
843                 assert(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer))==0);
844                 assert(sender.getAddress() == Address(127,0,0,1, 0).getAddress());
845         }
846 };
847
848 struct TestConnection
849 {
850         void TestHelpers()
851         {
852                 /*
853                         Test helper functions
854                 */
855
856                 // Some constants for testing
857                 u32 proto_id = 0x12345678;
858                 u16 peer_id = 123;
859                 u8 channel = 2;
860                 SharedBuffer<u8> data1(1);
861                 data1[0] = 100;
862                 Address a(127,0,0,1, 10);
863                 u16 seqnum = 34352;
864
865                 con::BufferedPacket p1 = con::makePacket(a, data1,
866                                 proto_id, peer_id, channel);
867                 /*
868                         We should now have a packet with this data:
869                         Header:
870                                 [0] u32 protocol_id
871                                 [4] u16 sender_peer_id
872                                 [6] u8 channel
873                         Data:
874                                 [7] u8 data1[0]
875                 */
876                 assert(readU32(&p1.data[0]) == proto_id);
877                 assert(readU16(&p1.data[4]) == peer_id);
878                 assert(readU8(&p1.data[6]) == channel);
879                 assert(readU8(&p1.data[7]) == data1[0]);
880                 
881                 //infostream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
882
883                 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
884
885                 /*infostream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
886                                 <<data1.getSize()<<std::endl;
887                 infostream<<"readU8(&p2[3])="<<readU8(&p2[3])
888                                 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
889                 infostream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
890
891                 assert(p2.getSize() == 3 + data1.getSize());
892                 assert(readU8(&p2[0]) == TYPE_RELIABLE);
893                 assert(readU16(&p2[1]) == seqnum);
894                 assert(readU8(&p2[3]) == data1[0]);
895         }
896
897         struct Handler : public con::PeerHandler
898         {
899                 Handler(const char *a_name)
900                 {
901                         count = 0;
902                         last_id = 0;
903                         name = a_name;
904                 }
905                 void peerAdded(con::Peer *peer)
906                 {
907                         infostream<<"Handler("<<name<<")::peerAdded(): "
908                                         "id="<<peer->id<<std::endl;
909                         last_id = peer->id;
910                         count++;
911                 }
912                 void deletingPeer(con::Peer *peer, bool timeout)
913                 {
914                         infostream<<"Handler("<<name<<")::deletingPeer(): "
915                                         "id="<<peer->id
916                                         <<", timeout="<<timeout<<std::endl;
917                         last_id = peer->id;
918                         count--;
919                 }
920
921                 s32 count;
922                 u16 last_id;
923                 const char *name;
924         };
925
926         void Run()
927         {
928                 DSTACK("TestConnection::Run");
929
930                 TestHelpers();
931
932                 /*
933                         Test some real connections
934
935                         NOTE: This mostly tests the legacy interface.
936                 */
937
938                 u32 proto_id = 0xad26846a;
939
940                 Handler hand_server("server");
941                 Handler hand_client("client");
942                 
943                 infostream<<"** Creating server Connection"<<std::endl;
944                 con::Connection server(proto_id, 512, 5.0, &hand_server);
945                 server.Serve(30001);
946                 
947                 infostream<<"** Creating client Connection"<<std::endl;
948                 con::Connection client(proto_id, 512, 5.0, &hand_client);
949
950                 assert(hand_server.count == 0);
951                 assert(hand_client.count == 0);
952                 
953                 sleep_ms(50);
954                 
955                 Address server_address(127,0,0,1, 30001);
956                 infostream<<"** running client.Connect()"<<std::endl;
957                 client.Connect(server_address);
958
959                 sleep_ms(50);
960                 
961                 // Client should not have added client yet
962                 assert(hand_client.count == 0);
963                 
964                 try
965                 {
966                         u16 peer_id;
967                         SharedBuffer<u8> data;
968                         infostream<<"** running client.Receive()"<<std::endl;
969                         u32 size = client.Receive(peer_id, data);
970                         infostream<<"** Client received: peer_id="<<peer_id
971                                         <<", size="<<size
972                                         <<std::endl;
973                 }
974                 catch(con::NoIncomingDataException &e)
975                 {
976                 }
977
978                 // Client should have added server now
979                 assert(hand_client.count == 1);
980                 assert(hand_client.last_id == 1);
981                 // Server should not have added client yet
982                 assert(hand_server.count == 0);
983                 
984                 sleep_ms(50);
985
986                 try
987                 {
988                         u16 peer_id;
989                         SharedBuffer<u8> data;
990                         infostream<<"** running server.Receive()"<<std::endl;
991                         u32 size = server.Receive(peer_id, data);
992                         infostream<<"** Server received: peer_id="<<peer_id
993                                         <<", size="<<size
994                                         <<std::endl;
995                 }
996                 catch(con::NoIncomingDataException &e)
997                 {
998                         // No actual data received, but the client has
999                         // probably been connected
1000                 }
1001                 
1002                 // Client should be the same
1003                 assert(hand_client.count == 1);
1004                 assert(hand_client.last_id == 1);
1005                 // Server should have the client
1006                 assert(hand_server.count == 1);
1007                 assert(hand_server.last_id == 2);
1008                 
1009                 //sleep_ms(50);
1010
1011                 while(client.Connected() == false)
1012                 {
1013                         try
1014                         {
1015                                 u16 peer_id;
1016                                 SharedBuffer<u8> data;
1017                                 infostream<<"** running client.Receive()"<<std::endl;
1018                                 u32 size = client.Receive(peer_id, data);
1019                                 infostream<<"** Client received: peer_id="<<peer_id
1020                                                 <<", size="<<size
1021                                                 <<std::endl;
1022                         }
1023                         catch(con::NoIncomingDataException &e)
1024                         {
1025                         }
1026                         sleep_ms(50);
1027                 }
1028
1029                 sleep_ms(50);
1030                 
1031                 try
1032                 {
1033                         u16 peer_id;
1034                         SharedBuffer<u8> data;
1035                         infostream<<"** running server.Receive()"<<std::endl;
1036                         u32 size = server.Receive(peer_id, data);
1037                         infostream<<"** Server received: peer_id="<<peer_id
1038                                         <<", size="<<size
1039                                         <<std::endl;
1040                 }
1041                 catch(con::NoIncomingDataException &e)
1042                 {
1043                 }
1044 #if 1
1045                 /*
1046                         Simple send-receive test
1047                 */
1048                 {
1049                         /*u8 data[] = "Hello World!";
1050                         u32 datasize = sizeof(data);*/
1051                         SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
1052
1053                         infostream<<"** running client.Send()"<<std::endl;
1054                         client.Send(PEER_ID_SERVER, 0, data, true);
1055
1056                         sleep_ms(50);
1057
1058                         u16 peer_id;
1059                         SharedBuffer<u8> recvdata;
1060                         infostream<<"** running server.Receive()"<<std::endl;
1061                         u32 size = server.Receive(peer_id, recvdata);
1062                         infostream<<"** Server received: peer_id="<<peer_id
1063                                         <<", size="<<size
1064                                         <<", data="<<*data
1065                                         <<std::endl;
1066                         assert(memcmp(*data, *recvdata, data.getSize()) == 0);
1067                 }
1068 #endif
1069                 u16 peer_id_client = 2;
1070 #if 0
1071                 /*
1072                         Send consequent packets in different order
1073                         Not compatible with new Connection, thus commented out.
1074                 */
1075                 {
1076                         //u8 data1[] = "hello1";
1077                         //u8 data2[] = "hello2";
1078                         SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
1079                         SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
1080
1081                         Address client_address =
1082                                         server.GetPeerAddress(peer_id_client);
1083                         
1084                         infostream<<"*** Sending packets in wrong order (2,1,2)"
1085                                         <<std::endl;
1086                         
1087                         u8 chn = 0;
1088                         con::Channel *ch = &server.getPeer(peer_id_client)->channels[chn];
1089                         u16 sn = ch->next_outgoing_seqnum;
1090                         ch->next_outgoing_seqnum = sn+1;
1091                         server.Send(peer_id_client, chn, data2, true);
1092                         ch->next_outgoing_seqnum = sn;
1093                         server.Send(peer_id_client, chn, data1, true);
1094                         ch->next_outgoing_seqnum = sn+1;
1095                         server.Send(peer_id_client, chn, data2, true);
1096
1097                         sleep_ms(50);
1098
1099                         infostream<<"*** Receiving the packets"<<std::endl;
1100
1101                         u16 peer_id;
1102                         SharedBuffer<u8> recvdata;
1103                         u32 size;
1104
1105                         infostream<<"** running client.Receive()"<<std::endl;
1106                         peer_id = 132;
1107                         size = client.Receive(peer_id, recvdata);
1108                         infostream<<"** Client received: peer_id="<<peer_id
1109                                         <<", size="<<size
1110                                         <<", data="<<*recvdata
1111                                         <<std::endl;
1112                         assert(size == data1.getSize());
1113                         assert(memcmp(*data1, *recvdata, data1.getSize()) == 0);
1114                         assert(peer_id == PEER_ID_SERVER);
1115                         
1116                         infostream<<"** running client.Receive()"<<std::endl;
1117                         peer_id = 132;
1118                         size = client.Receive(peer_id, recvdata);
1119                         infostream<<"** Client received: peer_id="<<peer_id
1120                                         <<", size="<<size
1121                                         <<", data="<<*recvdata
1122                                         <<std::endl;
1123                         assert(size == data2.getSize());
1124                         assert(memcmp(*data2, *recvdata, data2.getSize()) == 0);
1125                         assert(peer_id == PEER_ID_SERVER);
1126                         
1127                         bool got_exception = false;
1128                         try
1129                         {
1130                                 infostream<<"** running client.Receive()"<<std::endl;
1131                                 peer_id = 132;
1132                                 size = client.Receive(peer_id, recvdata);
1133                                 infostream<<"** Client received: peer_id="<<peer_id
1134                                                 <<", size="<<size
1135                                                 <<", data="<<*recvdata
1136                                                 <<std::endl;
1137                         }
1138                         catch(con::NoIncomingDataException &e)
1139                         {
1140                                 infostream<<"** No incoming data for client"<<std::endl;
1141                                 got_exception = true;
1142                         }
1143                         assert(got_exception);
1144                 }
1145 #endif
1146 #if 0
1147                 /*
1148                         Send large amounts of packets (infinite test)
1149                         Commented out because of infinity.
1150                 */
1151                 {
1152                         infostream<<"Sending large amounts of packets (infinite test)"<<std::endl;
1153                         int sendcount = 0;
1154                         for(;;){
1155                                 int datasize = myrand_range(0,5)==0?myrand_range(100,10000):myrand_range(0,100);
1156                                 infostream<<"datasize="<<datasize<<std::endl;
1157                                 SharedBuffer<u8> data1(datasize);
1158                                 for(u16 i=0; i<datasize; i++)
1159                                         data1[i] = i/4;
1160                                 
1161                                 int sendtimes = myrand_range(1,10);
1162                                 for(int i=0; i<sendtimes; i++){
1163                                         server.Send(peer_id_client, 0, data1, true);
1164                                         sendcount++;
1165                                 }
1166                                 infostream<<"sendcount="<<sendcount<<std::endl;
1167                                 
1168                                 //int receivetimes = myrand_range(1,20);
1169                                 int receivetimes = 20;
1170                                 for(int i=0; i<receivetimes; i++){
1171                                         SharedBuffer<u8> recvdata;
1172                                         u16 peer_id = 132;
1173                                         u16 size = 0;
1174                                         bool received = false;
1175                                         try{
1176                                                 size = client.Receive(peer_id, recvdata);
1177                                                 received = true;
1178                                         }catch(con::NoIncomingDataException &e){
1179                                         }
1180                                 }
1181                         }
1182                 }
1183 #endif
1184                 /*
1185                         Send a large packet
1186                 */
1187                 {
1188                         const int datasize = 30000;
1189                         SharedBuffer<u8> data1(datasize);
1190                         for(u16 i=0; i<datasize; i++){
1191                                 data1[i] = i/4;
1192                         }
1193
1194                         infostream<<"Sending data (size="<<datasize<<"):";
1195                         for(int i=0; i<datasize && i<20; i++){
1196                                 if(i%2==0) DEBUGPRINT(" ");
1197                                 DEBUGPRINT("%.2X", ((int)((const char*)*data1)[i])&0xff);
1198                         }
1199                         if(datasize>20)
1200                                 infostream<<"...";
1201                         infostream<<std::endl;
1202                         
1203                         server.Send(peer_id_client, 0, data1, true);
1204
1205                         sleep_ms(3000);
1206                         
1207                         SharedBuffer<u8> recvdata;
1208                         infostream<<"** running client.Receive()"<<std::endl;
1209                         u16 peer_id = 132;
1210                         u16 size = 0;
1211                         bool received = false;
1212                         u32 timems0 = porting::getTimeMs();
1213                         for(;;){
1214                                 if(porting::getTimeMs() - timems0 > 5000)
1215                                         break;
1216                                 try{
1217                                         size = client.Receive(peer_id, recvdata);
1218                                         received = true;
1219                                 }catch(con::NoIncomingDataException &e){
1220                                 }
1221                                 sleep_ms(10);
1222                         }
1223                         assert(received);
1224                         infostream<<"** Client received: peer_id="<<peer_id
1225                                         <<", size="<<size
1226                                         <<std::endl;
1227
1228                         infostream<<"Received data (size="<<size<<"):";
1229                         for(int i=0; i<size && i<20; i++){
1230                                 if(i%2==0) DEBUGPRINT(" ");
1231                                 DEBUGPRINT("%.2X", ((int)(recvdata[i]))&0xff);
1232                         }
1233                         if(size>20)
1234                                 infostream<<"...";
1235                         infostream<<std::endl;
1236
1237                         assert(memcmp(*data1, *recvdata, data1.getSize()) == 0);
1238                         assert(peer_id == PEER_ID_SERVER);
1239                 }
1240                 
1241                 // Check peer handlers
1242                 assert(hand_client.count == 1);
1243                 assert(hand_client.last_id == 1);
1244                 assert(hand_server.count == 1);
1245                 assert(hand_server.last_id == 2);
1246                 
1247                 //assert(0);
1248         }
1249 };
1250
1251 #define TEST(X)\
1252 {\
1253         X x;\
1254         infostream<<"Running " #X <<std::endl;\
1255         x.Run();\
1256 }
1257
1258 #define TESTPARAMS(X, ...)\
1259 {\
1260         X x;\
1261         infostream<<"Running " #X <<std::endl;\
1262         x.Run(__VA_ARGS__);\
1263 }
1264
1265 void run_tests()
1266 {
1267         DSTACK(__FUNCTION_NAME);
1268         
1269         // Create item and node definitions
1270         IWritableItemDefManager *idef = createItemDefManager();
1271         IWritableNodeDefManager *ndef = createNodeDefManager();
1272         define_some_nodes(idef, ndef);
1273
1274         infostream<<"run_tests() started"<<std::endl;
1275         TEST(TestUtilities);
1276         TEST(TestSettings);
1277         TEST(TestCompress);
1278         TEST(TestSerialization);
1279         TESTPARAMS(TestMapNode, ndef);
1280         TESTPARAMS(TestVoxelManipulator, ndef);
1281         //TEST(TestMapBlock);
1282         //TEST(TestMapSector);
1283         if(INTERNET_SIMULATOR == false){
1284                 TEST(TestSocket);
1285                 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1286                 TEST(TestConnection);
1287                 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
1288         }
1289         infostream<<"run_tests() passed"<<std::endl;
1290 }
1291