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