3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "irrlichttypes_extrabloated.h"
27 #include "connection.h"
28 #include "serialization.h"
30 #include "collision.h"
33 #include "content_mapnode.h"
35 #include "mapsector.h"
38 #include "util/string.h"
40 #include "voxelalgorithms.h"
41 #include "inventory.h"
42 #include "util/numeric.h"
43 #include "util/serialize.h"
44 #include "noise.h" // PseudoRandom used for random data for compression
45 #include "network/networkprotocol.h" // LATEST_PROTOCOL_VERSION
49 Asserts that the exception occurs
51 #define EXCEPTION_CHECK(EType, code)\
53 bool exception_thrown = false;\
55 catch(EType &e) { exception_thrown = true; }\
56 UASSERT(exception_thrown);\
59 #define UTEST(x, fmt, ...)\
62 dstream << "Test (" #x ") failed: " fmt << std::endl; \
67 #define UASSERT(x) UTEST(x, "UASSERT")
70 A few item and node definitions for those tests that need them
73 static content_t CONTENT_STONE;
74 static content_t CONTENT_GRASS;
75 static content_t CONTENT_TORCH;
77 void define_some_nodes(IWritableItemDefManager *idef, IWritableNodeDefManager *ndef)
79 ItemDefinition itemdef;
85 itemdef = ItemDefinition();
86 itemdef.type = ITEM_NODE;
87 itemdef.name = "default:stone";
88 itemdef.description = "Stone";
89 itemdef.groups["cracky"] = 3;
90 itemdef.inventory_image = "[inventorycube"
94 f = ContentFeatures();
95 f.name = itemdef.name;
96 for(int i = 0; i < 6; i++)
97 f.tiledef[i].name = "default_stone.png";
98 f.is_ground_content = true;
99 idef->registerItem(itemdef);
100 CONTENT_STONE = ndef->set(f.name, f);
105 itemdef = ItemDefinition();
106 itemdef.type = ITEM_NODE;
107 itemdef.name = "default:dirt_with_grass";
108 itemdef.description = "Dirt with grass";
109 itemdef.groups["crumbly"] = 3;
110 itemdef.inventory_image = "[inventorycube"
112 "{default_dirt.png&default_grass_side.png"
113 "{default_dirt.png&default_grass_side.png";
114 f = ContentFeatures();
115 f.name = itemdef.name;
116 f.tiledef[0].name = "default_grass.png";
117 f.tiledef[1].name = "default_dirt.png";
118 for(int i = 2; i < 6; i++)
119 f.tiledef[i].name = "default_dirt.png^default_grass_side.png";
120 f.is_ground_content = true;
121 idef->registerItem(itemdef);
122 CONTENT_GRASS = ndef->set(f.name, f);
125 Torch (minimal definition for lighting tests)
127 itemdef = ItemDefinition();
128 itemdef.type = ITEM_NODE;
129 itemdef.name = "default:torch";
130 f = ContentFeatures();
131 f.name = itemdef.name;
132 f.param_type = CPT_LIGHT;
133 f.light_propagates = true;
134 f.sunlight_propagates = true;
135 f.light_source = LIGHT_MAX-1;
136 idef->registerItem(itemdef);
137 CONTENT_TORCH = ndef->set(f.name, f);
148 struct TestUtilities: public TestBase
152 /*infostream<<"wrapDegrees(100.0) = "<<wrapDegrees(100.0)<<std::endl;
153 infostream<<"wrapDegrees(720.5) = "<<wrapDegrees(720.5)<<std::endl;
154 infostream<<"wrapDegrees(-0.5) = "<<wrapDegrees(-0.5)<<std::endl;*/
155 UASSERT(fabs(wrapDegrees(100.0) - 100.0) < 0.001);
156 UASSERT(fabs(wrapDegrees(720.5) - 0.5) < 0.001);
157 UASSERT(fabs(wrapDegrees(-0.5) - (-0.5)) < 0.001);
158 UASSERT(fabs(wrapDegrees(-365.5) - (-5.5)) < 0.001);
159 UASSERT(lowercase("Foo bAR") == "foo bar");
160 UASSERT(trim("\n \t\r Foo bAR \r\n\t\t ") == "Foo bAR");
161 UASSERT(trim("\n \t\r \r\n\t\t ") == "");
162 UASSERT(is_yes("YeS") == true);
163 UASSERT(is_yes("") == false);
164 UASSERT(is_yes("FAlse") == false);
165 UASSERT(is_yes("-1") == true);
166 UASSERT(is_yes("0") == false);
167 UASSERT(is_yes("1") == true);
168 UASSERT(is_yes("2") == true);
169 const char *ends[] = {"abc", "c", "bc", "", NULL};
170 UASSERT(removeStringEnd("abc", ends) == "");
171 UASSERT(removeStringEnd("bc", ends) == "b");
172 UASSERT(removeStringEnd("12c", ends) == "12");
173 UASSERT(removeStringEnd("foo", ends) == "");
174 UASSERT(urlencode("\"Aardvarks lurk, OK?\"")
175 == "%22Aardvarks%20lurk%2C%20OK%3F%22");
176 UASSERT(urldecode("%22Aardvarks%20lurk%2C%20OK%3F%22")
177 == "\"Aardvarks lurk, OK?\"");
178 UASSERT(padStringRight("hello", 8) == "hello ");
179 UASSERT(str_equal(narrow_to_wide("abc"), narrow_to_wide("abc")));
180 UASSERT(str_equal(narrow_to_wide("ABC"), narrow_to_wide("abc"), true));
181 UASSERT(trim(" a") == "a");
182 UASSERT(trim(" a ") == "a");
183 UASSERT(trim("a ") == "a");
184 UASSERT(trim("") == "");
185 UASSERT(mystoi("123", 0, 1000) == 123);
186 UASSERT(mystoi("123", 0, 10) == 10);
187 std::string test_str;
188 test_str = "Hello there";
189 str_replace(test_str, "there", "world");
190 UASSERT(test_str == "Hello world");
191 test_str = "ThisAisAaAtest";
192 str_replace(test_str, 'A', ' ');
193 UASSERT(test_str == "This is a test");
194 UASSERT(string_allowed("hello", "abcdefghijklmno") == true);
195 UASSERT(string_allowed("123", "abcdefghijklmno") == false);
196 UASSERT(string_allowed_blacklist("hello", "123") == true);
197 UASSERT(string_allowed_blacklist("hello123", "123") == false);
198 UASSERT(wrap_rows("12345678",4) == "1234\n5678");
199 UASSERT(is_number("123") == true);
200 UASSERT(is_number("") == false);
201 UASSERT(is_number("123a") == false);
202 UASSERT(is_power_of_two(0) == false);
203 UASSERT(is_power_of_two(1) == true);
204 UASSERT(is_power_of_two(2) == true);
205 UASSERT(is_power_of_two(3) == false);
206 for (int exponent = 2; exponent <= 31; ++exponent) {
207 UASSERT(is_power_of_two((1 << exponent) - 1) == false);
208 UASSERT(is_power_of_two((1 << exponent)) == true);
209 UASSERT(is_power_of_two((1 << exponent) + 1) == false);
211 UASSERT(is_power_of_two((u32)-1) == false);
215 struct TestPath: public TestBase
217 // adjusts a POSIX path to system-specific conventions
218 // -> changes '/' to DIR_DELIM
219 // -> absolute paths start with "C:\\" on windows
220 std::string p(std::string path)
222 for(size_t i = 0; i < path.size(); ++i){
224 path.replace(i, 1, DIR_DELIM);
225 i += std::string(DIR_DELIM).size() - 1; // generally a no-op
239 std::string path, result, removed;
242 Test fs::IsDirDelimiter
244 UASSERT(fs::IsDirDelimiter('/') == true);
245 UASSERT(fs::IsDirDelimiter('A') == false);
246 UASSERT(fs::IsDirDelimiter(0) == false);
248 UASSERT(fs::IsDirDelimiter('\\') == true);
250 UASSERT(fs::IsDirDelimiter('\\') == false);
254 Test fs::PathStartsWith
257 const int numpaths = 12;
258 std::string paths[numpaths] = {
261 p("/home/user/minetest"),
262 p("/home/user/minetest/bin"),
263 p("/home/user/.minetest"),
269 p("/home/user2/minetest/worlds"),
270 p("/home/user2/minetest/world"),
273 expected fs::PathStartsWith results
276 2 = returns false on windows, true elsewhere
277 3 = returns true on windows, false elsewhere
278 4 = returns true if and only if
279 FILESYS_CASE_INSENSITIVE is true
281 int expected_results[numpaths][numpaths] = {
282 {1,2,0,0,0,0,0,0,0,0,0,0},
283 {1,1,0,0,0,0,0,0,0,0,0,0},
284 {1,1,1,0,0,0,0,0,0,0,0,0},
285 {1,1,1,1,0,0,0,0,0,0,0,0},
286 {1,1,0,0,1,0,0,0,0,0,0,0},
287 {1,1,0,0,0,1,0,0,1,1,0,0},
288 {1,1,0,0,0,0,1,4,1,0,0,0},
289 {1,1,0,0,0,0,4,1,4,0,0,0},
290 {1,1,0,0,0,0,0,0,1,0,0,0},
291 {1,1,0,0,0,0,0,0,1,1,0,0},
292 {1,1,0,0,0,0,0,0,0,0,1,0},
293 {1,1,0,0,0,0,0,0,0,0,0,1},
296 for (int i = 0; i < numpaths; i++)
297 for (int j = 0; j < numpaths; j++){
298 /*verbosestream<<"testing fs::PathStartsWith(\""
300 <<paths[j]<<"\")"<<std::endl;*/
301 bool starts = fs::PathStartsWith(paths[i], paths[j]);
302 int expected = expected_results[i][j];
304 UASSERT(starts == false);
306 else if(expected == 1){
307 UASSERT(starts == true);
310 else if(expected == 2){
311 UASSERT(starts == false);
313 else if(expected == 3){
314 UASSERT(starts == true);
317 else if(expected == 2){
318 UASSERT(starts == true);
320 else if(expected == 3){
321 UASSERT(starts == false);
324 else if(expected == 4){
325 UASSERT(starts == (bool)FILESYS_CASE_INSENSITIVE);
331 Test fs::RemoveLastPathComponent
333 UASSERT(fs::RemoveLastPathComponent("") == "");
334 path = p("/home/user/minetest/bin/..//worlds/world1");
335 result = fs::RemoveLastPathComponent(path, &removed, 0);
336 UASSERT(result == path);
337 UASSERT(removed == "");
338 result = fs::RemoveLastPathComponent(path, &removed, 1);
339 UASSERT(result == p("/home/user/minetest/bin/..//worlds"));
340 UASSERT(removed == p("world1"));
341 result = fs::RemoveLastPathComponent(path, &removed, 2);
342 UASSERT(result == p("/home/user/minetest/bin/.."));
343 UASSERT(removed == p("worlds/world1"));
344 result = fs::RemoveLastPathComponent(path, &removed, 3);
345 UASSERT(result == p("/home/user/minetest/bin"));
346 UASSERT(removed == p("../worlds/world1"));
347 result = fs::RemoveLastPathComponent(path, &removed, 4);
348 UASSERT(result == p("/home/user/minetest"));
349 UASSERT(removed == p("bin/../worlds/world1"));
350 result = fs::RemoveLastPathComponent(path, &removed, 5);
351 UASSERT(result == p("/home/user"));
352 UASSERT(removed == p("minetest/bin/../worlds/world1"));
353 result = fs::RemoveLastPathComponent(path, &removed, 6);
354 UASSERT(result == p("/home"));
355 UASSERT(removed == p("user/minetest/bin/../worlds/world1"));
356 result = fs::RemoveLastPathComponent(path, &removed, 7);
358 UASSERT(result == "C:");
360 UASSERT(result == "");
362 UASSERT(removed == p("home/user/minetest/bin/../worlds/world1"));
365 Now repeat the test with a trailing delimiter
367 path = p("/home/user/minetest/bin/..//worlds/world1/");
368 result = fs::RemoveLastPathComponent(path, &removed, 0);
369 UASSERT(result == path);
370 UASSERT(removed == "");
371 result = fs::RemoveLastPathComponent(path, &removed, 1);
372 UASSERT(result == p("/home/user/minetest/bin/..//worlds"));
373 UASSERT(removed == p("world1"));
374 result = fs::RemoveLastPathComponent(path, &removed, 2);
375 UASSERT(result == p("/home/user/minetest/bin/.."));
376 UASSERT(removed == p("worlds/world1"));
377 result = fs::RemoveLastPathComponent(path, &removed, 3);
378 UASSERT(result == p("/home/user/minetest/bin"));
379 UASSERT(removed == p("../worlds/world1"));
380 result = fs::RemoveLastPathComponent(path, &removed, 4);
381 UASSERT(result == p("/home/user/minetest"));
382 UASSERT(removed == p("bin/../worlds/world1"));
383 result = fs::RemoveLastPathComponent(path, &removed, 5);
384 UASSERT(result == p("/home/user"));
385 UASSERT(removed == p("minetest/bin/../worlds/world1"));
386 result = fs::RemoveLastPathComponent(path, &removed, 6);
387 UASSERT(result == p("/home"));
388 UASSERT(removed == p("user/minetest/bin/../worlds/world1"));
389 result = fs::RemoveLastPathComponent(path, &removed, 7);
391 UASSERT(result == "C:");
393 UASSERT(result == "");
395 UASSERT(removed == p("home/user/minetest/bin/../worlds/world1"));
398 Test fs::RemoveRelativePathComponent
400 path = p("/home/user/minetest/bin");
401 result = fs::RemoveRelativePathComponents(path);
402 UASSERT(result == path);
403 path = p("/home/user/minetest/bin/../worlds/world1");
404 result = fs::RemoveRelativePathComponents(path);
405 UASSERT(result == p("/home/user/minetest/worlds/world1"));
406 path = p("/home/user/minetest/bin/../worlds/world1/");
407 result = fs::RemoveRelativePathComponents(path);
408 UASSERT(result == p("/home/user/minetest/worlds/world1"));
410 result = fs::RemoveRelativePathComponents(path);
411 UASSERT(result == "");
412 path = p("./subdir/../..");
413 result = fs::RemoveRelativePathComponents(path);
414 UASSERT(result == "");
415 path = p("/a/b/c/.././../d/../e/f/g/../h/i/j/../../../..");
416 result = fs::RemoveRelativePathComponents(path);
417 UASSERT(result == p("/a/e"));
421 #define TEST_CONFIG_TEXT_BEFORE \
423 "leetleet = 13371337\n" \
424 "leetleet_neg = -13371337\n" \
425 "floaty_thing = 1.1\n" \
426 "stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n" \
427 "coord = (1, 2, 4.5)\n" \
428 " # this is just a comment\n" \
429 "this is an invalid line\n" \
439 "blarg = \"\"\" \n" \
440 "some multiline text\n" \
441 " with leading whitespace!\n" \
443 "np_terrain = 5, 40, (250, 250, 250), 12341, 5, 0.7, 2.4\n" \
446 #define TEST_CONFIG_TEXT_AFTER \
448 "leetleet = 13371337\n" \
449 "leetleet_neg = -13371337\n" \
450 "floaty_thing = 1.1\n" \
451 "stringy_thing = asd /( ¤%&(/\" BLÖÄRP\n" \
452 "coord = (1, 2, 4.5)\n" \
453 " # this is just a comment\n" \
454 "this is an invalid line\n" \
464 "blarg = \"\"\" \n" \
465 "some multiline text\n" \
466 " with leading whitespace!\n" \
469 " flags = defaults\n" \
470 " lacunarity = 2.4\n" \
473 " persistence = 0.7\n" \
476 " spread = (250,250,250)\n" \
479 "coord2 = (1,2,3.3)\n" \
480 "floaty_thing_2 = 1.2\n" \
481 "groupy_thing = {\n" \
482 " animals = cute\n" \
483 " num_apples = 4\n" \
484 " num_oranges = 53\n" \
487 struct TestSettings: public TestBase
494 // Test reading of settings
495 std::istringstream is(TEST_CONFIG_TEXT_BEFORE);
496 s.parseConfigLines(is);
498 UASSERT(s.getS32("leet") == 1337);
499 UASSERT(s.getS16("leetleet") == 32767);
500 UASSERT(s.getS16("leetleet_neg") == -32768);
502 // Not sure if 1.1 is an exact value as a float, but doesn't matter
503 UASSERT(fabs(s.getFloat("floaty_thing") - 1.1) < 0.001);
504 UASSERT(s.get("stringy_thing") == "asd /( ¤%&(/\" BLÖÄRP");
505 UASSERT(fabs(s.getV3F("coord").X - 1.0) < 0.001);
506 UASSERT(fabs(s.getV3F("coord").Y - 2.0) < 0.001);
507 UASSERT(fabs(s.getV3F("coord").Z - 4.5) < 0.001);
509 // Test the setting of settings too
510 s.setFloat("floaty_thing_2", 1.2);
511 s.setV3F("coord2", v3f(1, 2, 3.3));
512 UASSERT(s.get("floaty_thing_2").substr(0,3) == "1.2");
513 UASSERT(fabs(s.getFloat("floaty_thing_2") - 1.2) < 0.001);
514 UASSERT(fabs(s.getV3F("coord2").X - 1.0) < 0.001);
515 UASSERT(fabs(s.getV3F("coord2").Y - 2.0) < 0.001);
516 UASSERT(fabs(s.getV3F("coord2").Z - 3.3) < 0.001);
518 // Test settings groups
519 Settings *group = s.getGroup("asdf");
520 UASSERT(group != NULL);
521 UASSERT(s.getGroupNoEx("zoop", group) == false);
522 UASSERT(group->getS16("a") == 5);
523 UASSERT(fabs(group->getFloat("bb") - 2.5) < 0.001);
525 Settings *group3 = new Settings;
526 group3->set("cat", "meow");
527 group3->set("dog", "woof");
529 Settings *group2 = new Settings;
530 group2->setS16("num_apples", 4);
531 group2->setS16("num_oranges", 53);
532 group2->setGroup("animals", group3);
533 group2->set("animals", "cute"); //destroys group 3
534 s.setGroup("groupy_thing", group2);
536 // Test set failure conditions
537 UASSERT(s.set("Zoop = Poop\nsome_other_setting", "false") == false);
538 UASSERT(s.set("sneaky", "\"\"\"\njabberwocky = false") == false);
539 UASSERT(s.set("hehe", "asdfasdf\n\"\"\"\nsomething = false") == false);
541 // Test multiline settings
542 UASSERT(group->get("ccc") == "testy\n testa ");
544 UASSERT(s.get("blarg") ==
545 "some multiline text\n"
546 " with leading whitespace!");
549 UASSERT(s.getEntry("np_terrain").is_group == false);
552 UASSERT(s.getNoiseParams("np_terrain", np) == true);
553 UASSERT(fabs(np.offset - 5) < 0.001);
554 UASSERT(fabs(np.scale - 40) < 0.001);
555 UASSERT(fabs(np.spread.X - 250) < 0.001);
556 UASSERT(fabs(np.spread.Y - 250) < 0.001);
557 UASSERT(fabs(np.spread.Z - 250) < 0.001);
558 UASSERT(np.seed == 12341);
559 UASSERT(np.octaves == 5);
560 UASSERT(fabs(np.persist - 0.7) < 0.001);
564 s.setNoiseParams("np_terrain", np);
566 UASSERT(s.getEntry("np_terrain").is_group == true);
569 std::ostringstream os(std::ios_base::binary);
573 UASSERT(s.updateConfigObject(is, os, "", 0) == true);
574 //printf(">>>> expected config:\n%s\n", TEST_CONFIG_TEXT_AFTER);
575 //printf(">>>> actual config:\n%s\n", os.str().c_str());
576 UASSERT(os.str() == TEST_CONFIG_TEXT_AFTER);
577 } catch (SettingNotFoundException &e) {
578 UASSERT(!"Setting not found!");
583 struct TestSerialization: public TestBase
585 // To be used like this:
586 // mkstr("Some\0string\0with\0embedded\0nuls")
587 // since std::string("...") doesn't work as expected in that case.
588 template<size_t N> std::string mkstr(const char (&s)[N])
590 return std::string(s, N - 1);
595 // Tests some serialization primitives
597 UASSERT(serializeString("") == mkstr("\0\0"));
598 UASSERT(serializeWideString(L"") == mkstr("\0\0"));
599 UASSERT(serializeLongString("") == mkstr("\0\0\0\0"));
600 UASSERT(serializeJsonString("") == "\"\"");
602 std::string teststring = "Hello world!";
603 UASSERT(serializeString(teststring) ==
604 mkstr("\0\14Hello world!"));
605 UASSERT(serializeWideString(narrow_to_wide(teststring)) ==
606 mkstr("\0\14\0H\0e\0l\0l\0o\0 \0w\0o\0r\0l\0d\0!"));
607 UASSERT(serializeLongString(teststring) ==
608 mkstr("\0\0\0\14Hello world!"));
609 UASSERT(serializeJsonString(teststring) ==
612 std::string teststring2;
613 std::wstring teststring2_w;
614 std::string teststring2_w_encoded;
616 std::ostringstream tmp_os;
617 std::wostringstream tmp_os_w;
618 std::ostringstream tmp_os_w_encoded;
619 for(int i = 0; i < 256; i++)
622 tmp_os_w<<(wchar_t)i;
623 tmp_os_w_encoded<<(char)0<<(char)i;
625 teststring2 = tmp_os.str();
626 teststring2_w = tmp_os_w.str();
627 teststring2_w_encoded = tmp_os_w_encoded.str();
629 UASSERT(serializeString(teststring2) ==
630 mkstr("\1\0") + teststring2);
631 UASSERT(serializeWideString(teststring2_w) ==
632 mkstr("\1\0") + teststring2_w_encoded);
633 UASSERT(serializeLongString(teststring2) ==
634 mkstr("\0\0\1\0") + teststring2);
635 // MSVC fails when directly using "\\\\"
636 std::string backslash = "\\";
637 UASSERT(serializeJsonString(teststring2) ==
639 "\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007" +
640 "\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f" +
641 "\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017" +
642 "\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f" +
643 " !\\\"" + teststring2.substr(0x23, 0x2f-0x23) +
644 "\\/" + teststring2.substr(0x30, 0x5c-0x30) +
645 backslash + backslash + teststring2.substr(0x5d, 0x7f-0x5d) + "\\u007f" +
646 "\\u0080\\u0081\\u0082\\u0083\\u0084\\u0085\\u0086\\u0087" +
647 "\\u0088\\u0089\\u008a\\u008b\\u008c\\u008d\\u008e\\u008f" +
648 "\\u0090\\u0091\\u0092\\u0093\\u0094\\u0095\\u0096\\u0097" +
649 "\\u0098\\u0099\\u009a\\u009b\\u009c\\u009d\\u009e\\u009f" +
650 "\\u00a0\\u00a1\\u00a2\\u00a3\\u00a4\\u00a5\\u00a6\\u00a7" +
651 "\\u00a8\\u00a9\\u00aa\\u00ab\\u00ac\\u00ad\\u00ae\\u00af" +
652 "\\u00b0\\u00b1\\u00b2\\u00b3\\u00b4\\u00b5\\u00b6\\u00b7" +
653 "\\u00b8\\u00b9\\u00ba\\u00bb\\u00bc\\u00bd\\u00be\\u00bf" +
654 "\\u00c0\\u00c1\\u00c2\\u00c3\\u00c4\\u00c5\\u00c6\\u00c7" +
655 "\\u00c8\\u00c9\\u00ca\\u00cb\\u00cc\\u00cd\\u00ce\\u00cf" +
656 "\\u00d0\\u00d1\\u00d2\\u00d3\\u00d4\\u00d5\\u00d6\\u00d7" +
657 "\\u00d8\\u00d9\\u00da\\u00db\\u00dc\\u00dd\\u00de\\u00df" +
658 "\\u00e0\\u00e1\\u00e2\\u00e3\\u00e4\\u00e5\\u00e6\\u00e7" +
659 "\\u00e8\\u00e9\\u00ea\\u00eb\\u00ec\\u00ed\\u00ee\\u00ef" +
660 "\\u00f0\\u00f1\\u00f2\\u00f3\\u00f4\\u00f5\\u00f6\\u00f7" +
661 "\\u00f8\\u00f9\\u00fa\\u00fb\\u00fc\\u00fd\\u00fe\\u00ff" +
665 std::istringstream is(serializeString(teststring2), std::ios::binary);
666 UASSERT(deSerializeString(is) == teststring2);
672 std::istringstream is(serializeWideString(teststring2_w), std::ios::binary);
673 UASSERT(deSerializeWideString(is) == teststring2_w);
679 std::istringstream is(serializeLongString(teststring2), std::ios::binary);
680 UASSERT(deSerializeLongString(is) == teststring2);
686 std::istringstream is(serializeJsonString(teststring2), std::ios::binary);
687 //dstream<<serializeJsonString(deSerializeJsonString(is));
688 UASSERT(deSerializeJsonString(is) == teststring2);
696 struct TestNodedefSerialization: public TestBase
701 f.name = "default:stone";
702 for(int i = 0; i < 6; i++)
703 f.tiledef[i].name = "default_stone.png";
704 f.is_ground_content = true;
705 std::ostringstream os(std::ios::binary);
706 f.serialize(os, LATEST_PROTOCOL_VERSION);
707 verbosestream<<"Test ContentFeatures size: "<<os.str().size()<<std::endl;
708 std::istringstream is(os.str(), std::ios::binary);
711 UASSERT(f.walkable == f2.walkable);
712 UASSERT(f.node_box.type == f2.node_box.type);
716 struct TestCompress: public TestBase
722 SharedBuffer<u8> fromdata(4);
728 std::ostringstream os(std::ios_base::binary);
729 compress(fromdata, os, 0);
731 std::string str_out = os.str();
733 infostream<<"str_out.size()="<<str_out.size()<<std::endl;
734 infostream<<"TestCompress: 1,5,5,1 -> ";
735 for(u32 i=0; i<str_out.size(); i++)
737 infostream<<(u32)str_out[i]<<",";
739 infostream<<std::endl;
741 UASSERT(str_out.size() == 10);
743 UASSERT(str_out[0] == 0);
744 UASSERT(str_out[1] == 0);
745 UASSERT(str_out[2] == 0);
746 UASSERT(str_out[3] == 4);
747 UASSERT(str_out[4] == 0);
748 UASSERT(str_out[5] == 1);
749 UASSERT(str_out[6] == 1);
750 UASSERT(str_out[7] == 5);
751 UASSERT(str_out[8] == 0);
752 UASSERT(str_out[9] == 1);
754 std::istringstream is(str_out, std::ios_base::binary);
755 std::ostringstream os2(std::ios_base::binary);
757 decompress(is, os2, 0);
758 std::string str_out2 = os2.str();
760 infostream<<"decompress: ";
761 for(u32 i=0; i<str_out2.size(); i++)
763 infostream<<(u32)str_out2[i]<<",";
765 infostream<<std::endl;
767 UASSERT(str_out2.size() == fromdata.getSize());
769 for(u32 i=0; i<str_out2.size(); i++)
771 UASSERT(str_out2[i] == fromdata[i]);
778 SharedBuffer<u8> fromdata(4);
784 std::ostringstream os(std::ios_base::binary);
785 compress(fromdata, os, SER_FMT_VER_HIGHEST_READ);
787 std::string str_out = os.str();
789 infostream<<"str_out.size()="<<str_out.size()<<std::endl;
790 infostream<<"TestCompress: 1,5,5,1 -> ";
791 for(u32 i=0; i<str_out.size(); i++)
793 infostream<<(u32)str_out[i]<<",";
795 infostream<<std::endl;
797 std::istringstream is(str_out, std::ios_base::binary);
798 std::ostringstream os2(std::ios_base::binary);
800 decompress(is, os2, SER_FMT_VER_HIGHEST_READ);
801 std::string str_out2 = os2.str();
803 infostream<<"decompress: ";
804 for(u32 i=0; i<str_out2.size(); i++)
806 infostream<<(u32)str_out2[i]<<",";
808 infostream<<std::endl;
810 UASSERT(str_out2.size() == fromdata.getSize());
812 for(u32 i=0; i<str_out2.size(); i++)
814 UASSERT(str_out2[i] == fromdata[i]);
819 // Test zlib wrapper with large amounts of data (larger than its
822 infostream<<"Test: Testing zlib wrappers with a large amount "
823 <<"of pseudorandom data"<<std::endl;
825 infostream<<"Test: Input size of large compressZlib is "
828 data_in.resize(size);
829 PseudoRandom pseudorandom(9420);
830 for(u32 i=0; i<size; i++)
831 data_in[i] = pseudorandom.range(0,255);
832 std::ostringstream os_compressed(std::ios::binary);
833 compressZlib(data_in, os_compressed);
834 infostream<<"Test: Output size of large compressZlib is "
835 <<os_compressed.str().size()<<std::endl;
836 std::istringstream is_compressed(os_compressed.str(), std::ios::binary);
837 std::ostringstream os_decompressed(std::ios::binary);
838 decompressZlib(is_compressed, os_decompressed);
839 infostream<<"Test: Output size of large decompressZlib is "
840 <<os_decompressed.str().size()<<std::endl;
841 std::string str_decompressed = os_decompressed.str();
842 UTEST(str_decompressed.size() == data_in.size(), "Output size not"
843 " equal (output: %u, input: %u)",
844 (unsigned int)str_decompressed.size(), (unsigned int)data_in.size());
845 for(u32 i=0; i<size && i<str_decompressed.size(); i++){
846 UTEST(str_decompressed[i] == data_in[i],
847 "index out[%i]=%i differs from in[%i]=%i",
848 i, str_decompressed[i], i, data_in[i]);
854 struct TestMapNode: public TestBase
856 void Run(INodeDefManager *nodedef)
858 MapNode n(CONTENT_AIR);
860 UASSERT(n.getContent() == CONTENT_AIR);
861 UASSERT(n.getLight(LIGHTBANK_DAY, nodedef) == 0);
862 UASSERT(n.getLight(LIGHTBANK_NIGHT, nodedef) == 0);
865 n.setContent(CONTENT_AIR);
866 UASSERT(nodedef->get(n).light_propagates == true);
867 n.setContent(LEGN(nodedef, "CONTENT_STONE"));
868 UASSERT(nodedef->get(n).light_propagates == false);
872 struct TestVoxelManipulator: public TestBase
874 void Run(INodeDefManager *nodedef)
880 VoxelArea a(v3s16(-1,-1,-1), v3s16(1,1,1));
881 UASSERT(a.index(0,0,0) == 1*3*3 + 1*3 + 1);
882 UASSERT(a.index(-1,-1,-1) == 0);
884 VoxelArea c(v3s16(-2,-2,-2), v3s16(2,2,2));
885 // An area that is 1 bigger in x+ and z-
886 VoxelArea d(v3s16(-2,-2,-3), v3s16(3,2,2));
888 std::list<VoxelArea> aa;
892 std::vector<VoxelArea> results;
893 results.push_back(VoxelArea(v3s16(-2,-2,-3),v3s16(3,2,-3)));
894 results.push_back(VoxelArea(v3s16(3,-2,-2),v3s16(3,2,2)));
896 UASSERT(aa.size() == results.size());
898 infostream<<"Result of diff:"<<std::endl;
899 for(std::list<VoxelArea>::const_iterator
900 i = aa.begin(); i != aa.end(); ++i)
902 i->print(infostream);
903 infostream<<std::endl;
905 std::vector<VoxelArea>::iterator j = std::find(results.begin(), results.end(), *i);
906 UASSERT(j != results.end());
917 v.print(infostream, nodedef);
919 infostream<<"*** Setting (-1,0,-1)=2 ***"<<std::endl;
921 v.setNodeNoRef(v3s16(-1,0,-1), MapNode(CONTENT_GRASS));
923 v.print(infostream, nodedef);
925 UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == CONTENT_GRASS);
927 infostream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
929 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,0,-1)));
931 v.print(infostream, nodedef);
933 infostream<<"*** Adding area ***"<<std::endl;
937 v.print(infostream, nodedef);
939 UASSERT(v.getNode(v3s16(-1,0,-1)).getContent() == CONTENT_GRASS);
940 EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
944 struct TestVoxelAlgorithms: public TestBase
946 void Run(INodeDefManager *ndef)
949 voxalgo::propagateSunlight
953 for(u16 z=0; z<3; z++)
954 for(u16 y=0; y<3; y++)
955 for(u16 x=0; x<3; x++)
958 v.setNodeNoRef(p, MapNode(CONTENT_AIR));
960 VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
962 std::set<v3s16> light_sources;
963 voxalgo::setLight(v, a, 0, ndef);
964 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
965 v, a, true, light_sources, ndef);
966 //v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
967 UASSERT(res.bottom_sunlight_valid == true);
968 UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
971 v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE));
973 std::set<v3s16> light_sources;
974 voxalgo::setLight(v, a, 0, ndef);
975 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
976 v, a, true, light_sources, ndef);
977 UASSERT(res.bottom_sunlight_valid == true);
978 UASSERT(v.getNode(v3s16(1,1,1)).getLight(LIGHTBANK_DAY, ndef)
982 std::set<v3s16> light_sources;
983 voxalgo::setLight(v, a, 0, ndef);
984 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
985 v, a, false, light_sources, ndef);
986 UASSERT(res.bottom_sunlight_valid == true);
987 UASSERT(v.getNode(v3s16(2,0,2)).getLight(LIGHTBANK_DAY, ndef)
990 v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_STONE));
992 std::set<v3s16> light_sources;
993 voxalgo::setLight(v, a, 0, ndef);
994 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
995 v, a, true, light_sources, ndef);
996 UASSERT(res.bottom_sunlight_valid == true);
997 UASSERT(v.getNode(v3s16(1,1,2)).getLight(LIGHTBANK_DAY, ndef)
1001 std::set<v3s16> light_sources;
1002 voxalgo::setLight(v, a, 0, ndef);
1003 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1004 v, a, false, light_sources, ndef);
1005 UASSERT(res.bottom_sunlight_valid == true);
1006 UASSERT(v.getNode(v3s16(1,0,2)).getLight(LIGHTBANK_DAY, ndef)
1010 MapNode n(CONTENT_AIR);
1011 n.setLight(LIGHTBANK_DAY, 10, ndef);
1012 v.setNodeNoRef(v3s16(1,-1,2), n);
1015 std::set<v3s16> light_sources;
1016 voxalgo::setLight(v, a, 0, ndef);
1017 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1018 v, a, true, light_sources, ndef);
1019 UASSERT(res.bottom_sunlight_valid == true);
1022 std::set<v3s16> light_sources;
1023 voxalgo::setLight(v, a, 0, ndef);
1024 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1025 v, a, false, light_sources, ndef);
1026 UASSERT(res.bottom_sunlight_valid == true);
1029 MapNode n(CONTENT_AIR);
1030 n.setLight(LIGHTBANK_DAY, LIGHT_SUN, ndef);
1031 v.setNodeNoRef(v3s16(1,-1,2), n);
1034 std::set<v3s16> light_sources;
1035 voxalgo::setLight(v, a, 0, ndef);
1036 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1037 v, a, true, light_sources, ndef);
1038 UASSERT(res.bottom_sunlight_valid == false);
1041 std::set<v3s16> light_sources;
1042 voxalgo::setLight(v, a, 0, ndef);
1043 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1044 v, a, false, light_sources, ndef);
1045 UASSERT(res.bottom_sunlight_valid == false);
1047 v.setNodeNoRef(v3s16(1,3,2), MapNode(CONTENT_IGNORE));
1049 std::set<v3s16> light_sources;
1050 voxalgo::setLight(v, a, 0, ndef);
1051 voxalgo::SunlightPropagateResult res = voxalgo::propagateSunlight(
1052 v, a, true, light_sources, ndef);
1053 UASSERT(res.bottom_sunlight_valid == true);
1057 voxalgo::clearLightAndCollectSources
1061 for(u16 z=0; z<3; z++)
1062 for(u16 y=0; y<3; y++)
1063 for(u16 x=0; x<3; x++)
1066 v.setNode(p, MapNode(CONTENT_AIR));
1068 VoxelArea a(v3s16(0,0,0), v3s16(2,2,2));
1069 v.setNodeNoRef(v3s16(0,0,0), MapNode(CONTENT_STONE));
1070 v.setNodeNoRef(v3s16(1,1,1), MapNode(CONTENT_TORCH));
1072 MapNode n(CONTENT_AIR);
1073 n.setLight(LIGHTBANK_DAY, 1, ndef);
1074 v.setNode(v3s16(1,1,2), n);
1077 std::set<v3s16> light_sources;
1078 std::map<v3s16, u8> unlight_from;
1079 voxalgo::clearLightAndCollectSources(v, a, LIGHTBANK_DAY,
1080 ndef, light_sources, unlight_from);
1081 //v.print(dstream, ndef, VOXELPRINT_LIGHT_DAY);
1082 UASSERT(v.getNode(v3s16(0,1,1)).getLight(LIGHTBANK_DAY, ndef)
1084 UASSERT(light_sources.find(v3s16(1,1,1)) != light_sources.end());
1085 UASSERT(light_sources.size() == 1);
1086 UASSERT(unlight_from.find(v3s16(1,1,2)) != unlight_from.end());
1087 UASSERT(unlight_from.size() == 1);
1093 struct TestInventory: public TestBase
1095 void Run(IItemDefManager *idef)
1097 std::string serialized_inventory =
1109 "Item default:cobble 61\n"
1116 "Item default:dirt 71\n"
1124 "Item default:dirt 99\n"
1125 "Item default:cobble 38\n"
1132 "EndInventoryList\n"
1135 std::string serialized_inventory_2 =
1147 "Item default:cobble 61\n"
1154 "Item default:dirt 71\n"
1162 "Item default:dirt 99\n"
1163 "Item default:cobble 38\n"
1170 "EndInventoryList\n"
1173 Inventory inv(idef);
1174 std::istringstream is(serialized_inventory, std::ios::binary);
1175 inv.deSerialize(is);
1176 UASSERT(inv.getList("0"));
1177 UASSERT(!inv.getList("main"));
1178 inv.getList("0")->setName("main");
1179 UASSERT(!inv.getList("0"));
1180 UASSERT(inv.getList("main"));
1181 UASSERT(inv.getList("main")->getWidth() == 3);
1182 inv.getList("main")->setWidth(5);
1183 std::ostringstream inv_os(std::ios::binary);
1184 inv.serialize(inv_os);
1185 UASSERT(inv_os.str() == serialized_inventory_2);
1190 NOTE: These tests became non-working then NodeContainer was removed.
1191 These should be redone, utilizing some kind of a virtual
1192 interface for Map (IMap would be fine).
1195 struct TestMapBlock: public TestBase
1197 class TC : public NodeContainer
1202 bool position_valid;
1203 core::list<v3s16> validity_exceptions;
1207 position_valid = true;
1210 virtual bool isValidPosition(v3s16 p)
1212 //return position_valid ^ (p==position_valid_exception);
1213 bool exception = false;
1214 for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
1215 i != validity_exceptions.end(); i++)
1223 return exception ? !position_valid : position_valid;
1226 virtual MapNode getNode(v3s16 p)
1228 if(isValidPosition(p) == false)
1229 throw InvalidPositionException();
1233 virtual void setNode(v3s16 p, MapNode & n)
1235 if(isValidPosition(p) == false)
1236 throw InvalidPositionException();
1239 virtual u16 nodeContainerId() const
1249 MapBlock b(&parent, v3s16(1,1,1));
1250 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
1252 UASSERT(b.getPosRelative() == relpos);
1254 UASSERT(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
1255 UASSERT(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
1256 UASSERT(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
1257 UASSERT(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
1258 UASSERT(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
1259 UASSERT(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
1261 UASSERT(b.isValidPosition(v3s16(0,0,0)) == true);
1262 UASSERT(b.isValidPosition(v3s16(-1,0,0)) == false);
1263 UASSERT(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
1264 UASSERT(b.isValidPosition(v3s16(-124,142,2341)) == false);
1265 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
1266 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
1269 TODO: this method should probably be removed
1270 if the block size isn't going to be set variable
1272 /*UASSERT(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
1273 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
1275 // Changed flag should be initially set
1276 UASSERT(b.getModified() == MOD_STATE_WRITE_NEEDED);
1278 UASSERT(b.getModified() == MOD_STATE_CLEAN);
1280 // All nodes should have been set to
1281 // .d=CONTENT_IGNORE and .getLight() = 0
1282 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
1283 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
1284 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
1286 //UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_AIR);
1287 UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_IGNORE);
1288 UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
1289 UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
1293 MapNode n(CONTENT_AIR);
1294 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
1295 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
1296 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
1298 b.setNode(v3s16(x,y,z), n);
1303 Parent fetch functions
1305 parent.position_valid = false;
1306 parent.node.setContent(5);
1310 // Positions in the block should still be valid
1311 UASSERT(b.isValidPositionParent(v3s16(0,0,0)) == true);
1312 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
1313 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
1314 UASSERT(n.getContent() == CONTENT_AIR);
1316 // ...but outside the block they should be invalid
1317 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
1318 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == false);
1319 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
1322 bool exception_thrown = false;
1324 // This should throw an exception
1325 MapNode n = b.getNodeParent(v3s16(0,0,-1));
1327 catch(InvalidPositionException &e)
1329 exception_thrown = true;
1331 UASSERT(exception_thrown);
1334 parent.position_valid = true;
1335 // Now the positions outside should be valid
1336 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
1337 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == true);
1338 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
1339 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
1340 UASSERT(n.getContent() == 5);
1348 UASSERT(b.getNode(p).getContent() == 4);
1349 //TODO: Update to new system
1350 /*UASSERT(b.getNodeTile(p) == 4);
1351 UASSERT(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
1356 // Set lighting of all nodes to 0
1357 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
1358 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
1359 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
1360 MapNode n = b.getNode(v3s16(x,y,z));
1361 n.setLight(LIGHTBANK_DAY, 0);
1362 n.setLight(LIGHTBANK_NIGHT, 0);
1363 b.setNode(v3s16(x,y,z), n);
1369 Check how the block handles being a lonely sky block
1371 parent.position_valid = true;
1372 b.setIsUnderground(false);
1373 parent.node.setContent(CONTENT_AIR);
1374 parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
1375 parent.node.setLight(LIGHTBANK_NIGHT, 0);
1376 core::map<v3s16, bool> light_sources;
1377 // The bottom block is invalid, because we have a shadowing node
1378 UASSERT(b.propagateSunlight(light_sources) == false);
1379 UASSERT(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
1380 UASSERT(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
1381 UASSERT(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
1382 UASSERT(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
1383 UASSERT(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
1384 UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
1385 UASSERT(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
1386 UASSERT(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
1387 UASSERT(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
1388 // According to MapBlock::getFaceLight,
1389 // The face on the z+ side should have double-diminished light
1390 //UASSERT(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
1391 // The face on the z+ side should have diminished light
1392 UASSERT(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
1395 Check how the block handles being in between blocks with some non-sunlight
1396 while being underground
1399 // Make neighbours to exist and set some non-sunlight to them
1400 parent.position_valid = true;
1401 b.setIsUnderground(true);
1402 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
1403 core::map<v3s16, bool> light_sources;
1404 // The block below should be valid because there shouldn't be
1405 // sunlight in there either
1406 UASSERT(b.propagateSunlight(light_sources, true) == true);
1407 // Should not touch nodes that are not affected (that is, all of them)
1408 //UASSERT(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
1409 // Should set light of non-sunlighted blocks to 0.
1410 UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
1413 Set up a situation where:
1414 - There is only air in this block
1415 - There is a valid non-sunlighted block at the bottom, and
1416 - Invalid blocks elsewhere.
1417 - the block is not underground.
1419 This should result in bottom block invalidity
1422 b.setIsUnderground(false);
1424 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
1425 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
1426 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
1428 n.setContent(CONTENT_AIR);
1429 n.setLight(LIGHTBANK_DAY, 0);
1430 b.setNode(v3s16(x,y,z), n);
1434 // Make neighbours invalid
1435 parent.position_valid = false;
1436 // Add exceptions to the top of the bottom block
1437 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
1438 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
1440 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
1442 // Lighting value for the valid nodes
1443 parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
1444 core::map<v3s16, bool> light_sources;
1445 // Bottom block is not valid
1446 UASSERT(b.propagateSunlight(light_sources) == false);
1451 struct TestMapSector: public TestBase
1453 class TC : public NodeContainer
1458 bool position_valid;
1462 position_valid = true;
1465 virtual bool isValidPosition(v3s16 p)
1467 return position_valid;
1470 virtual MapNode getNode(v3s16 p)
1472 if(position_valid == false)
1473 throw InvalidPositionException();
1477 virtual void setNode(v3s16 p, MapNode & n)
1479 if(position_valid == false)
1480 throw InvalidPositionException();
1483 virtual u16 nodeContainerId() const
1492 parent.position_valid = false;
1494 // Create one with no heightmaps
1495 ServerMapSector sector(&parent, v2s16(1,1));
1497 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
1498 UASSERT(sector.getBlockNoCreateNoEx(1) == 0);
1500 MapBlock * bref = sector.createBlankBlock(-2);
1502 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
1503 UASSERT(sector.getBlockNoCreateNoEx(-2) == bref);
1505 //TODO: Check for AlreadyExistsException
1507 /*bool exception_thrown = false;
1511 catch(InvalidPositionException &e){
1512 exception_thrown = true;
1514 UASSERT(exception_thrown);*/
1520 struct TestCollision: public TestBase
1525 axisAlignedCollision
1528 for(s16 bx = -3; bx <= 3; bx++)
1529 for(s16 by = -3; by <= 3; by++)
1530 for(s16 bz = -3; bz <= 3; bz++)
1534 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1535 aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
1538 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1539 UASSERT(fabs(dtime - 1.000) < 0.001);
1542 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1543 aabb3f m(bx-2, by, bz, bx-1, by+1, bz+1);
1546 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == -1);
1549 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1550 aabb3f m(bx-2, by+1.5, bz, bx-1, by+2.5, bz-1);
1553 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == -1);
1556 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1557 aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
1560 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1561 UASSERT(fabs(dtime - 3.000) < 0.001);
1564 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1565 aabb3f m(bx-2, by-1.5, bz, bx-1.5, by+0.5, bz+1);
1568 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1569 UASSERT(fabs(dtime - 3.000) < 0.001);
1574 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1575 aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
1578 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1579 UASSERT(fabs(dtime - 1.000) < 0.001);
1582 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1583 aabb3f m(bx+2, by, bz, bx+3, by+1, bz+1);
1586 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == -1);
1589 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1590 aabb3f m(bx+2, by, bz+1.5, bx+3, by+1, bz+3.5);
1593 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == -1);
1596 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1597 aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
1598 v3f v(-0.5, 0.2, 0);
1600 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 1); // Y, not X!
1601 UASSERT(fabs(dtime - 2.500) < 0.001);
1604 aabb3f s(bx, by, bz, bx+1, by+1, bz+1);
1605 aabb3f m(bx+2, by-1.5, bz, bx+2.5, by-0.5, bz+1);
1606 v3f v(-0.5, 0.3, 0);
1608 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1609 UASSERT(fabs(dtime - 2.000) < 0.001);
1612 // TODO: Y-, Y+, Z-, Z+
1616 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1617 aabb3f m(bx+2.3, by+2.29, bz+2.29, bx+4.2, by+4.2, bz+4.2);
1618 v3f v(-1./3, -1./3, -1./3);
1620 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1621 UASSERT(fabs(dtime - 0.9) < 0.001);
1624 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1625 aabb3f m(bx+2.29, by+2.3, bz+2.29, bx+4.2, by+4.2, bz+4.2);
1626 v3f v(-1./3, -1./3, -1./3);
1628 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 1);
1629 UASSERT(fabs(dtime - 0.9) < 0.001);
1632 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1633 aabb3f m(bx+2.29, by+2.29, bz+2.3, bx+4.2, by+4.2, bz+4.2);
1634 v3f v(-1./3, -1./3, -1./3);
1636 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 2);
1637 UASSERT(fabs(dtime - 0.9) < 0.001);
1640 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1641 aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.3, by-2.29, bz-2.29);
1642 v3f v(1./7, 1./7, 1./7);
1644 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 0);
1645 UASSERT(fabs(dtime - 16.1) < 0.001);
1648 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1649 aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.3, bz-2.29);
1650 v3f v(1./7, 1./7, 1./7);
1652 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 1);
1653 UASSERT(fabs(dtime - 16.1) < 0.001);
1656 aabb3f s(bx, by, bz, bx+2, by+2, bz+2);
1657 aabb3f m(bx-4.2, by-4.2, bz-4.2, bx-2.29, by-2.29, bz-2.3);
1658 v3f v(1./7, 1./7, 1./7);
1660 UASSERT(axisAlignedCollision(s, m, v, 0, dtime) == 2);
1661 UASSERT(fabs(dtime - 16.1) < 0.001);
1667 struct TestSocket: public TestBase
1671 const int port = 30003;
1672 Address address(0, 0, 0, 0, port);
1673 Address bind_addr(0, 0, 0, 0, port);
1674 Address address6((IPv6AddressBytes*) NULL, port);
1677 * Try to use the bind_address for servers with no localhost address
1678 * For example: FreeBSD jails
1680 std::string bind_str = g_settings->get("bind_address");
1682 bind_addr.Resolve(bind_str.c_str());
1684 if (!bind_addr.isIPv6()) {
1685 address = bind_addr;
1687 } catch (ResolveError &e) {
1691 if (g_settings->getBool("enable_ipv6")) {
1694 if (!socket6.init(true, true)) {
1695 /* Note: Failing to create an IPv6 socket is not technically an
1696 error because the OS may not support IPv6 or it may
1697 have been disabled. IPv6 is not /required/ by
1698 minetest and therefore this should not cause the unit
1701 dstream << "WARNING: IPv6 socket creation failed (unit test)"
1704 const char sendbuffer[] = "hello world!";
1705 IPv6AddressBytes bytes;
1706 bytes.bytes[15] = 1;
1708 socket6.Bind(address6);
1711 socket6.Send(Address(&bytes, port), sendbuffer, sizeof(sendbuffer));
1715 char rcvbuffer[256] = { 0 };
1719 if (socket6.Receive(sender, rcvbuffer, sizeof(rcvbuffer )) < 0)
1722 //FIXME: This fails on some systems
1723 UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
1724 UASSERT(memcmp(sender.getAddress6().sin6_addr.s6_addr,
1725 Address(&bytes, 0).getAddress6().sin6_addr.s6_addr, 16) == 0);
1727 catch (SendFailedException &e) {
1728 errorstream << "IPv6 support enabled but not available!"
1736 UDPSocket socket(false);
1737 socket.Bind(address);
1739 const char sendbuffer[] = "hello world!";
1741 * If there is a bind address, use it.
1742 * It's useful in container environments
1744 if (address != Address(0, 0, 0, 0, port)) {
1745 socket.Send(address, sendbuffer, sizeof(sendbuffer));
1748 socket.Send(Address(127, 0, 0 ,1, port), sendbuffer, sizeof(sendbuffer));
1752 char rcvbuffer[256] = { 0 };
1755 if (socket.Receive(sender, rcvbuffer, sizeof(rcvbuffer)) < 0)
1758 //FIXME: This fails on some systems
1759 UASSERT(strncmp(sendbuffer, rcvbuffer, sizeof(sendbuffer)) == 0);
1761 if (address != Address(0, 0, 0, 0, port)) {
1762 UASSERT(sender.getAddress().sin_addr.s_addr ==
1763 address.getAddress().sin_addr.s_addr);
1766 UASSERT(sender.getAddress().sin_addr.s_addr ==
1767 Address(127, 0, 0, 1, 0).getAddress().sin_addr.s_addr);
1773 struct TestConnection: public TestBase
1778 Test helper functions
1781 // Some constants for testing
1782 u32 proto_id = 0x12345678;
1785 SharedBuffer<u8> data1(1);
1787 Address a(127,0,0,1, 10);
1788 const u16 seqnum = 34352;
1790 con::BufferedPacket p1 = con::makePacket(a, data1,
1791 proto_id, peer_id, channel);
1793 We should now have a packet with this data:
1796 [4] u16 sender_peer_id
1801 UASSERT(readU32(&p1.data[0]) == proto_id);
1802 UASSERT(readU16(&p1.data[4]) == peer_id);
1803 UASSERT(readU8(&p1.data[6]) == channel);
1804 UASSERT(readU8(&p1.data[7]) == data1[0]);
1806 //infostream<<"initial data1[0]="<<((u32)data1[0]&0xff)<<std::endl;
1808 SharedBuffer<u8> p2 = con::makeReliablePacket(data1, seqnum);
1810 /*infostream<<"p2.getSize()="<<p2.getSize()<<", data1.getSize()="
1811 <<data1.getSize()<<std::endl;
1812 infostream<<"readU8(&p2[3])="<<readU8(&p2[3])
1813 <<" p2[3]="<<((u32)p2[3]&0xff)<<std::endl;
1814 infostream<<"data1[0]="<<((u32)data1[0]&0xff)<<std::endl;*/
1816 UASSERT(p2.getSize() == 3 + data1.getSize());
1817 UASSERT(readU8(&p2[0]) == TYPE_RELIABLE);
1818 UASSERT(readU16(&p2[1]) == seqnum);
1819 UASSERT(readU8(&p2[3]) == data1[0]);
1822 struct Handler : public con::PeerHandler
1824 Handler(const char *a_name)
1830 void peerAdded(con::Peer *peer)
1832 infostream<<"Handler("<<name<<")::peerAdded(): "
1833 "id="<<peer->id<<std::endl;
1837 void deletingPeer(con::Peer *peer, bool timeout)
1839 infostream<<"Handler("<<name<<")::deletingPeer(): "
1841 <<", timeout="<<timeout<<std::endl;
1853 DSTACK("TestConnection::Run");
1858 Test some real connections
1860 NOTE: This mostly tests the legacy interface.
1863 u32 proto_id = 0xad26846a;
1865 Handler hand_server("server");
1866 Handler hand_client("client");
1868 Address address(0, 0, 0, 0, 30001);
1869 Address bind_addr(0, 0, 0, 0, 30001);
1871 * Try to use the bind_address for servers with no localhost address
1872 * For example: FreeBSD jails
1874 std::string bind_str = g_settings->get("bind_address");
1876 bind_addr.Resolve(bind_str.c_str());
1878 if (!bind_addr.isIPv6()) {
1879 address = bind_addr;
1881 } catch (ResolveError &e) {
1884 infostream<<"** Creating server Connection"<<std::endl;
1885 con::Connection server(proto_id, 512, 5.0, false, &hand_server);
1886 server.Serve(address);
1888 infostream<<"** Creating client Connection"<<std::endl;
1889 con::Connection client(proto_id, 512, 5.0, false, &hand_client);
1891 UASSERT(hand_server.count == 0);
1892 UASSERT(hand_client.count == 0);
1896 Address server_address(127, 0, 0, 1, 30001);
1897 if (address != Address(0, 0, 0, 0, 30001)) {
1898 server_address = bind_addr;
1901 infostream<<"** running client.Connect()"<<std::endl;
1902 client.Connect(server_address);
1906 // Client should not have added client yet
1907 UASSERT(hand_client.count == 0);
1912 SharedBuffer<u8> data;
1913 infostream<<"** running client.Receive()"<<std::endl;
1914 u32 size = client.Receive(peer_id, data);
1915 infostream<<"** Client received: peer_id="<<peer_id
1919 catch(con::NoIncomingDataException &e)
1923 // Client should have added server now
1924 UASSERT(hand_client.count == 1);
1925 UASSERT(hand_client.last_id == 1);
1926 // Server should not have added client yet
1927 UASSERT(hand_server.count == 0);
1934 SharedBuffer<u8> data;
1935 infostream<<"** running server.Receive()"<<std::endl;
1936 u32 size = server.Receive(peer_id, data);
1937 infostream<<"** Server received: peer_id="<<peer_id
1941 catch(con::NoIncomingDataException &e)
1943 // No actual data received, but the client has
1944 // probably been connected
1947 // Client should be the same
1948 UASSERT(hand_client.count == 1);
1949 UASSERT(hand_client.last_id == 1);
1950 // Server should have the client
1951 UASSERT(hand_server.count == 1);
1952 UASSERT(hand_server.last_id == 2);
1956 while(client.Connected() == false)
1961 SharedBuffer<u8> data;
1962 infostream<<"** running client.Receive()"<<std::endl;
1963 u32 size = client.Receive(peer_id, data);
1964 infostream<<"** Client received: peer_id="<<peer_id
1968 catch(con::NoIncomingDataException &e)
1979 SharedBuffer<u8> data;
1980 infostream<<"** running server.Receive()"<<std::endl;
1981 u32 size = server.Receive(peer_id, data);
1982 infostream<<"** Server received: peer_id="<<peer_id
1986 catch(con::NoIncomingDataException &e)
1991 Simple send-receive test
1994 /*u8 data[] = "Hello World!";
1995 u32 datasize = sizeof(data);*/
1996 SharedBuffer<u8> data = SharedBufferFromString("Hello World!");
1998 infostream<<"** running client.Send()"<<std::endl;
1999 client.Send(PEER_ID_SERVER, 0, data, true);
2004 SharedBuffer<u8> recvdata;
2005 infostream<<"** running server.Receive()"<<std::endl;
2006 u32 size = server.Receive(peer_id, recvdata);
2007 infostream<<"** Server received: peer_id="<<peer_id
2011 UASSERT(memcmp(*data, *recvdata, data.getSize()) == 0);
2014 u16 peer_id_client = 2;
2017 Send consequent packets in different order
2018 Not compatible with new Connection, thus commented out.
2021 //u8 data1[] = "hello1";
2022 //u8 data2[] = "hello2";
2023 SharedBuffer<u8> data1 = SharedBufferFromString("hello1");
2024 SharedBuffer<u8> data2 = SharedBufferFromString("Hello2");
2026 Address client_address =
2027 server.GetPeerAddress(peer_id_client);
2029 infostream<<"*** Sending packets in wrong order (2,1,2)"
2033 con::Channel *ch = &server.getPeer(peer_id_client)->channels[chn];
2034 u16 sn = ch->next_outgoing_seqnum;
2035 ch->next_outgoing_seqnum = sn+1;
2036 server.Send(peer_id_client, chn, data2, true);
2037 ch->next_outgoing_seqnum = sn;
2038 server.Send(peer_id_client, chn, data1, true);
2039 ch->next_outgoing_seqnum = sn+1;
2040 server.Send(peer_id_client, chn, data2, true);
2044 infostream<<"*** Receiving the packets"<<std::endl;
2047 SharedBuffer<u8> recvdata;
2050 infostream<<"** running client.Receive()"<<std::endl;
2052 size = client.Receive(peer_id, recvdata);
2053 infostream<<"** Client received: peer_id="<<peer_id
2055 <<", data="<<*recvdata
2057 UASSERT(size == data1.getSize());
2058 UASSERT(memcmp(*data1, *recvdata, data1.getSize()) == 0);
2059 UASSERT(peer_id == PEER_ID_SERVER);
2061 infostream<<"** running client.Receive()"<<std::endl;
2063 size = client.Receive(peer_id, recvdata);
2064 infostream<<"** Client received: peer_id="<<peer_id
2066 <<", data="<<*recvdata
2068 UASSERT(size == data2.getSize());
2069 UASSERT(memcmp(*data2, *recvdata, data2.getSize()) == 0);
2070 UASSERT(peer_id == PEER_ID_SERVER);
2072 bool got_exception = false;
2075 infostream<<"** running client.Receive()"<<std::endl;
2077 size = client.Receive(peer_id, recvdata);
2078 infostream<<"** Client received: peer_id="<<peer_id
2080 <<", data="<<*recvdata
2083 catch(con::NoIncomingDataException &e)
2085 infostream<<"** No incoming data for client"<<std::endl;
2086 got_exception = true;
2088 UASSERT(got_exception);
2093 Send large amounts of packets (infinite test)
2094 Commented out because of infinity.
2097 infostream<<"Sending large amounts of packets (infinite test)"<<std::endl;
2100 int datasize = myrand_range(0,5)==0?myrand_range(100,10000):myrand_range(0,100);
2101 infostream<<"datasize="<<datasize<<std::endl;
2102 SharedBuffer<u8> data1(datasize);
2103 for(u16 i=0; i<datasize; i++)
2106 int sendtimes = myrand_range(1,10);
2107 for(int i=0; i<sendtimes; i++){
2108 server.Send(peer_id_client, 0, data1, true);
2111 infostream<<"sendcount="<<sendcount<<std::endl;
2113 //int receivetimes = myrand_range(1,20);
2114 int receivetimes = 20;
2115 for(int i=0; i<receivetimes; i++){
2116 SharedBuffer<u8> recvdata;
2119 bool received = false;
2121 size = client.Receive(peer_id, recvdata);
2123 }catch(con::NoIncomingDataException &e){
2133 const int datasize = 30000;
2134 SharedBuffer<u8> data1(datasize);
2135 for(u16 i=0; i<datasize; i++){
2139 infostream<<"Sending data (size="<<datasize<<"):";
2140 for(int i=0; i<datasize && i<20; i++){
2141 if(i%2==0) infostream<<" ";
2143 snprintf(buf, 10, "%.2X", ((int)((const char*)*data1)[i])&0xff);
2148 infostream<<std::endl;
2150 server.Send(peer_id_client, 0, data1, true);
2154 SharedBuffer<u8> recvdata;
2155 infostream<<"** running client.Receive()"<<std::endl;
2158 bool received = false;
2159 u32 timems0 = porting::getTimeMs();
2161 if(porting::getTimeMs() - timems0 > 5000 || received)
2164 size = client.Receive(peer_id, recvdata);
2166 }catch(con::NoIncomingDataException &e){
2171 infostream<<"** Client received: peer_id="<<peer_id
2175 infostream<<"Received data (size="<<size<<"): ";
2176 for(int i=0; i<size && i<20; i++){
2177 if(i%2==0) infostream<<" ";
2179 snprintf(buf, 10, "%.2X", ((int)(recvdata[i]))&0xff);
2184 infostream<<std::endl;
2186 UASSERT(memcmp(*data1, *recvdata, data1.getSize()) == 0);
2187 UASSERT(peer_id == PEER_ID_SERVER);
2190 // Check peer handlers
2191 UASSERT(hand_client.count == 1);
2192 UASSERT(hand_client.last_id == 1);
2193 UASSERT(hand_server.count == 1);
2194 UASSERT(hand_server.last_id == 2);
2200 #define TEST(X) do {\
2202 infostream<<"Running " #X <<std::endl;\
2205 tests_failed += x.test_failed ? 1 : 0;\
2208 #define TESTPARAMS(X, ...) do {\
2210 infostream<<"Running " #X <<std::endl;\
2211 x.Run(__VA_ARGS__);\
2213 tests_failed += x.test_failed ? 1 : 0;\
2218 DSTACK(__FUNCTION_NAME);
2221 int tests_failed = 0;
2223 // Create item and node definitions
2224 IWritableItemDefManager *idef = createItemDefManager();
2225 IWritableNodeDefManager *ndef = createNodeDefManager();
2226 define_some_nodes(idef, ndef);
2228 log_set_lev_silence(LMT_ERROR, true);
2230 infostream<<"run_tests() started"<<std::endl;
2231 TEST(TestUtilities);
2235 TEST(TestSerialization);
2236 TEST(TestNodedefSerialization);
2237 TESTPARAMS(TestMapNode, ndef);
2238 TESTPARAMS(TestVoxelManipulator, ndef);
2239 TESTPARAMS(TestVoxelAlgorithms, ndef);
2240 TESTPARAMS(TestInventory, idef);
2241 //TEST(TestMapBlock);
2242 //TEST(TestMapSector);
2243 TEST(TestCollision);
2244 if(INTERNET_SIMULATOR == false){
2246 dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
2247 TEST(TestConnection);
2248 dout_con<<"=== END RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;
2251 log_set_lev_silence(LMT_ERROR, false);
2256 if(tests_failed == 0){
2257 infostream<<"run_tests(): "<<tests_failed<<" / "<<tests_run<<" tests failed."<<std::endl;
2258 infostream<<"run_tests() passed."<<std::endl;
2261 errorstream<<"run_tests(): "<<tests_failed<<" / "<<tests_run<<" tests failed."<<std::endl;
2262 errorstream<<"run_tests() aborting."<<std::endl;