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