18215a94749558164d1ce262d0a3526c84ef8bfe
[oweals/minetest.git] / src / unittest / test.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 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 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.
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 Lesser General Public License for more details.
14
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.
18 */
19
20 #include "test.h"
21
22 #include "client/sound.h"
23 #include "nodedef.h"
24 #include "itemdef.h"
25 #include "gamedef.h"
26 #include "modchannels.h"
27 #include "mods.h"
28 #include "util/numeric.h"
29
30 content_t t_CONTENT_STONE;
31 content_t t_CONTENT_GRASS;
32 content_t t_CONTENT_TORCH;
33 content_t t_CONTENT_WATER;
34 content_t t_CONTENT_LAVA;
35 content_t t_CONTENT_BRICK;
36
37 ////////////////////////////////////////////////////////////////////////////////
38
39 ////
40 //// TestGameDef
41 ////
42
43 class TestGameDef : public IGameDef {
44 public:
45         TestGameDef();
46         ~TestGameDef();
47
48         IItemDefManager *getItemDefManager() { return m_itemdef; }
49         const NodeDefManager *getNodeDefManager() { return m_nodedef; }
50         ICraftDefManager *getCraftDefManager() { return m_craftdef; }
51         ITextureSource *getTextureSource() { return m_texturesrc; }
52         IShaderSource *getShaderSource() { return m_shadersrc; }
53         ISoundManager *getSoundManager() { return m_soundmgr; }
54         MtEventManager *getEventManager() { return m_eventmgr; }
55         scene::ISceneManager *getSceneManager() { return m_scenemgr; }
56         IRollbackManager *getRollbackManager() { return m_rollbackmgr; }
57         EmergeManager *getEmergeManager() { return m_emergemgr; }
58
59         scene::IAnimatedMesh *getMesh(const std::string &filename) { return NULL; }
60         bool checkLocalPrivilege(const std::string &priv) { return false; }
61         u16 allocateUnknownNodeId(const std::string &name) { return 0; }
62
63         void defineSomeNodes();
64
65         virtual const std::vector<ModSpec> &getMods() const
66         {
67                 static std::vector<ModSpec> testmodspec;
68                 return testmodspec;
69         }
70         virtual const ModSpec* getModSpec(const std::string &modname) const { return NULL; }
71         virtual std::string getModStoragePath() const { return "."; }
72         virtual bool registerModStorage(ModMetadata *meta) { return true; }
73         virtual void unregisterModStorage(const std::string &name) {}
74         bool joinModChannel(const std::string &channel);
75         bool leaveModChannel(const std::string &channel);
76         bool sendModChannelMessage(const std::string &channel, const std::string &message);
77         ModChannel *getModChannel(const std::string &channel)
78         {
79                 return m_modchannel_mgr->getModChannel(channel);
80         }
81
82 private:
83         IItemDefManager *m_itemdef = nullptr;
84         const NodeDefManager *m_nodedef = nullptr;
85         ICraftDefManager *m_craftdef = nullptr;
86         ITextureSource *m_texturesrc = nullptr;
87         IShaderSource *m_shadersrc = nullptr;
88         ISoundManager *m_soundmgr = nullptr;
89         MtEventManager *m_eventmgr = nullptr;
90         scene::ISceneManager *m_scenemgr = nullptr;
91         IRollbackManager *m_rollbackmgr = nullptr;
92         EmergeManager *m_emergemgr = nullptr;
93         std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
94 };
95
96
97 TestGameDef::TestGameDef() :
98         m_modchannel_mgr(new ModChannelMgr())
99 {
100         m_itemdef = createItemDefManager();
101         m_nodedef = createNodeDefManager();
102
103         defineSomeNodes();
104 }
105
106
107 TestGameDef::~TestGameDef()
108 {
109         delete m_itemdef;
110         delete m_nodedef;
111 }
112
113
114 void TestGameDef::defineSomeNodes()
115 {
116         IWritableItemDefManager *idef = (IWritableItemDefManager *)m_itemdef;
117         NodeDefManager *ndef = (NodeDefManager *)m_nodedef;
118
119         ItemDefinition itemdef;
120         ContentFeatures f;
121
122         //// Stone
123         itemdef = ItemDefinition();
124         itemdef.type = ITEM_NODE;
125         itemdef.name = "default:stone";
126         itemdef.description = "Stone";
127         itemdef.groups["cracky"] = 3;
128         itemdef.inventory_image = "[inventorycube"
129                 "{default_stone.png"
130                 "{default_stone.png"
131                 "{default_stone.png";
132         f = ContentFeatures();
133         f.name = itemdef.name;
134         for (TileDef &tiledef : f.tiledef)
135                 tiledef.name = "default_stone.png";
136         f.is_ground_content = true;
137         idef->registerItem(itemdef);
138         t_CONTENT_STONE = ndef->set(f.name, f);
139
140         //// Grass
141         itemdef = ItemDefinition();
142         itemdef.type = ITEM_NODE;
143         itemdef.name = "default:dirt_with_grass";
144         itemdef.description = "Dirt with grass";
145         itemdef.groups["crumbly"] = 3;
146         itemdef.inventory_image = "[inventorycube"
147                 "{default_grass.png"
148                 "{default_dirt.png&default_grass_side.png"
149                 "{default_dirt.png&default_grass_side.png";
150         f = ContentFeatures();
151         f.name = itemdef.name;
152         f.tiledef[0].name = "default_grass.png";
153         f.tiledef[1].name = "default_dirt.png";
154         for(int i = 2; i < 6; i++)
155                 f.tiledef[i].name = "default_dirt.png^default_grass_side.png";
156         f.is_ground_content = true;
157         idef->registerItem(itemdef);
158         t_CONTENT_GRASS = ndef->set(f.name, f);
159
160         //// Torch (minimal definition for lighting tests)
161         itemdef = ItemDefinition();
162         itemdef.type = ITEM_NODE;
163         itemdef.name = "default:torch";
164         f = ContentFeatures();
165         f.name = itemdef.name;
166         f.param_type = CPT_LIGHT;
167         f.light_propagates = true;
168         f.sunlight_propagates = true;
169         f.light_source = LIGHT_MAX-1;
170         idef->registerItem(itemdef);
171         t_CONTENT_TORCH = ndef->set(f.name, f);
172
173         //// Water
174         itemdef = ItemDefinition();
175         itemdef.type = ITEM_NODE;
176         itemdef.name = "default:water";
177         itemdef.description = "Water";
178         itemdef.inventory_image = "[inventorycube"
179                 "{default_water.png"
180                 "{default_water.png"
181                 "{default_water.png";
182         f = ContentFeatures();
183         f.name = itemdef.name;
184         f.alpha = 128;
185         f.liquid_type = LIQUID_SOURCE;
186         f.liquid_viscosity = 4;
187         f.is_ground_content = true;
188         f.groups["liquids"] = 3;
189         for (TileDef &tiledef : f.tiledef)
190                 tiledef.name = "default_water.png";
191         idef->registerItem(itemdef);
192         t_CONTENT_WATER = ndef->set(f.name, f);
193
194         //// Lava
195         itemdef = ItemDefinition();
196         itemdef.type = ITEM_NODE;
197         itemdef.name = "default:lava";
198         itemdef.description = "Lava";
199         itemdef.inventory_image = "[inventorycube"
200                 "{default_lava.png"
201                 "{default_lava.png"
202                 "{default_lava.png";
203         f = ContentFeatures();
204         f.name = itemdef.name;
205         f.alpha = 128;
206         f.liquid_type = LIQUID_SOURCE;
207         f.liquid_viscosity = 7;
208         f.light_source = LIGHT_MAX-1;
209         f.is_ground_content = true;
210         f.groups["liquids"] = 3;
211         for (TileDef &tiledef : f.tiledef)
212                 tiledef.name = "default_lava.png";
213         idef->registerItem(itemdef);
214         t_CONTENT_LAVA = ndef->set(f.name, f);
215
216
217         //// Brick
218         itemdef = ItemDefinition();
219         itemdef.type = ITEM_NODE;
220         itemdef.name = "default:brick";
221         itemdef.description = "Brick";
222         itemdef.groups["cracky"] = 3;
223         itemdef.inventory_image = "[inventorycube"
224                 "{default_brick.png"
225                 "{default_brick.png"
226                 "{default_brick.png";
227         f = ContentFeatures();
228         f.name = itemdef.name;
229         for (TileDef &tiledef : f.tiledef)
230                 tiledef.name = "default_brick.png";
231         f.is_ground_content = true;
232         idef->registerItem(itemdef);
233         t_CONTENT_BRICK = ndef->set(f.name, f);
234 }
235
236 bool TestGameDef::joinModChannel(const std::string &channel)
237 {
238         return m_modchannel_mgr->joinChannel(channel, PEER_ID_SERVER);
239 }
240
241 bool TestGameDef::leaveModChannel(const std::string &channel)
242 {
243         return m_modchannel_mgr->leaveChannel(channel, PEER_ID_SERVER);
244 }
245
246 bool TestGameDef::sendModChannelMessage(const std::string &channel,
247         const std::string &message)
248 {
249         if (!m_modchannel_mgr->channelRegistered(channel))
250                 return false;
251
252         return true;
253 }
254
255 ////
256 //// run_tests
257 ////
258
259 bool run_tests()
260 {
261         u64 t1 = porting::getTimeMs();
262         TestGameDef gamedef;
263
264         g_logger.setLevelSilenced(LL_ERROR, true);
265
266         u32 num_modules_failed     = 0;
267         u32 num_total_tests_failed = 0;
268         u32 num_total_tests_run    = 0;
269         std::vector<TestBase *> &testmods = TestManager::getTestModules();
270         for (size_t i = 0; i != testmods.size(); i++) {
271                 if (!testmods[i]->testModule(&gamedef))
272                         num_modules_failed++;
273
274                 num_total_tests_failed += testmods[i]->num_tests_failed;
275                 num_total_tests_run += testmods[i]->num_tests_run;
276         }
277
278         u64 tdiff = porting::getTimeMs() - t1;
279
280         g_logger.setLevelSilenced(LL_ERROR, false);
281
282         const char *overall_status = (num_modules_failed == 0) ? "PASSED" : "FAILED";
283
284         rawstream
285                 << "++++++++++++++++++++++++++++++++++++++++"
286                 << "++++++++++++++++++++++++++++++++++++++++" << std::endl
287                 << "Unit Test Results: " << overall_status << std::endl
288                 << "    " << num_modules_failed << " / " << testmods.size()
289                 << " failed modules (" << num_total_tests_failed << " / "
290                 << num_total_tests_run << " failed individual tests)." << std::endl
291                 << "    Testing took " << tdiff << "ms total." << std::endl
292                 << "++++++++++++++++++++++++++++++++++++++++"
293                 << "++++++++++++++++++++++++++++++++++++++++" << std::endl;
294
295         return num_modules_failed;
296 }
297
298 ////
299 //// TestBase
300 ////
301
302 bool TestBase::testModule(IGameDef *gamedef)
303 {
304         rawstream << "======== Testing module " << getName() << std::endl;
305         u64 t1 = porting::getTimeMs();
306
307
308         runTests(gamedef);
309
310         u64 tdiff = porting::getTimeMs() - t1;
311         rawstream << "======== Module " << getName() << " "
312                 << (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
313                 << " failures / " << num_tests_run << " tests) - " << tdiff
314                 << "ms" << std::endl;
315
316         if (!m_test_dir.empty())
317                 fs::RecursiveDelete(m_test_dir);
318
319         return num_tests_failed == 0;
320 }
321
322 std::string TestBase::getTestTempDirectory()
323 {
324         if (!m_test_dir.empty())
325                 return m_test_dir;
326
327         char buf[32];
328         snprintf(buf, sizeof(buf), "%08X", myrand());
329
330         m_test_dir = fs::TempPath() + DIR_DELIM "mttest_" + buf;
331         if (!fs::CreateDir(m_test_dir))
332                 throw TestFailedException();
333
334         return m_test_dir;
335 }
336
337 std::string TestBase::getTestTempFile()
338 {
339         char buf[32];
340         snprintf(buf, sizeof(buf), "%08X", myrand());
341
342         return getTestTempDirectory() + DIR_DELIM + buf + ".tmp";
343 }
344
345
346 /*
347         NOTE: These tests became non-working then NodeContainer was removed.
348               These should be redone, utilizing some kind of a virtual
349                   interface for Map (IMap would be fine).
350 */
351 #if 0
352 struct TestMapBlock: public TestBase
353 {
354         class TC : public NodeContainer
355         {
356         public:
357
358                 MapNode node;
359                 bool position_valid;
360                 core::list<v3s16> validity_exceptions;
361
362                 TC()
363                 {
364                         position_valid = true;
365                 }
366
367                 virtual bool isValidPosition(v3s16 p)
368                 {
369                         //return position_valid ^ (p==position_valid_exception);
370                         bool exception = false;
371                         for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
372                                         i != validity_exceptions.end(); i++)
373                         {
374                                 if(p == *i)
375                                 {
376                                         exception = true;
377                                         break;
378                                 }
379                         }
380                         return exception ? !position_valid : position_valid;
381                 }
382
383                 virtual MapNode getNode(v3s16 p)
384                 {
385                         if(isValidPosition(p) == false)
386                                 throw InvalidPositionException();
387                         return node;
388                 }
389
390                 virtual void setNode(v3s16 p, MapNode & n)
391                 {
392                         if(isValidPosition(p) == false)
393                                 throw InvalidPositionException();
394                 };
395
396                 virtual u16 nodeContainerId() const
397                 {
398                         return 666;
399                 }
400         };
401
402         void Run()
403         {
404                 TC parent;
405
406                 MapBlock b(&parent, v3s16(1,1,1));
407                 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
408
409                 UASSERT(b.getPosRelative() == relpos);
410
411                 UASSERT(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
412                 UASSERT(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
413                 UASSERT(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
414                 UASSERT(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
415                 UASSERT(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
416                 UASSERT(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
417
418                 UASSERT(b.isValidPosition(v3s16(0,0,0)) == true);
419                 UASSERT(b.isValidPosition(v3s16(-1,0,0)) == false);
420                 UASSERT(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
421                 UASSERT(b.isValidPosition(v3s16(-124,142,2341)) == false);
422                 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
423                 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
424
425                 /*
426                         TODO: this method should probably be removed
427                         if the block size isn't going to be set variable
428                 */
429                 /*UASSERT(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
430                                 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
431
432                 // Changed flag should be initially set
433                 UASSERT(b.getModified() == MOD_STATE_WRITE_NEEDED);
434                 b.resetModified();
435                 UASSERT(b.getModified() == MOD_STATE_CLEAN);
436
437                 // All nodes should have been set to
438                 // .d=CONTENT_IGNORE and .getLight() = 0
439                 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
440                 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
441                 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
442                 {
443                         //UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_AIR);
444                         UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_IGNORE);
445                         UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
446                         UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
447                 }
448
449                 {
450                         MapNode n(CONTENT_AIR);
451                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
452                         for(u16 y=0; y<MAP_BLOCKSIZE; y++)
453                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
454                         {
455                                 b.setNode(v3s16(x,y,z), n);
456                         }
457                 }
458
459                 /*
460                         Parent fetch functions
461                 */
462                 parent.position_valid = false;
463                 parent.node.setContent(5);
464
465                 MapNode n;
466
467                 // Positions in the block should still be valid
468                 UASSERT(b.isValidPositionParent(v3s16(0,0,0)) == true);
469                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
470                 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
471                 UASSERT(n.getContent() == CONTENT_AIR);
472
473                 // ...but outside the block they should be invalid
474                 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
475                 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == false);
476                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
477
478                 {
479                         bool exception_thrown = false;
480                         try{
481                                 // This should throw an exception
482                                 MapNode n = b.getNodeParent(v3s16(0,0,-1));
483                         }
484                         catch(InvalidPositionException &e)
485                         {
486                                 exception_thrown = true;
487                         }
488                         UASSERT(exception_thrown);
489                 }
490
491                 parent.position_valid = true;
492                 // Now the positions outside should be valid
493                 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
494                 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == true);
495                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
496                 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
497                 UASSERT(n.getContent() == 5);
498
499                 /*
500                         Set a node
501                 */
502                 v3s16 p(1,2,0);
503                 n.setContent(4);
504                 b.setNode(p, n);
505                 UASSERT(b.getNode(p).getContent() == 4);
506                 //TODO: Update to new system
507                 /*UASSERT(b.getNodeTile(p) == 4);
508                 UASSERT(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
509
510                 /*
511                         propagateSunlight()
512                 */
513                 // Set lighting of all nodes to 0
514                 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
515                         for(u16 y=0; y<MAP_BLOCKSIZE; y++){
516                                 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
517                                         MapNode n = b.getNode(v3s16(x,y,z));
518                                         n.setLight(LIGHTBANK_DAY, 0);
519                                         n.setLight(LIGHTBANK_NIGHT, 0);
520                                         b.setNode(v3s16(x,y,z), n);
521                                 }
522                         }
523                 }
524                 {
525                         /*
526                                 Check how the block handles being a lonely sky block
527                         */
528                         parent.position_valid = true;
529                         b.setIsUnderground(false);
530                         parent.node.setContent(CONTENT_AIR);
531                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
532                         parent.node.setLight(LIGHTBANK_NIGHT, 0);
533                         core::map<v3s16, bool> light_sources;
534                         // The bottom block is invalid, because we have a shadowing node
535                         UASSERT(b.propagateSunlight(light_sources) == false);
536                         UASSERT(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
537                         UASSERT(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
538                         UASSERT(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
539                         UASSERT(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
540                         UASSERT(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
541                         UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
542                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
543                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
544                         UASSERT(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
545                         // According to MapBlock::getFaceLight,
546                         // The face on the z+ side should have double-diminished light
547                         //UASSERT(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
548                         // The face on the z+ side should have diminished light
549                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
550                 }
551                 /*
552                         Check how the block handles being in between blocks with some non-sunlight
553                         while being underground
554                 */
555                 {
556                         // Make neighbours to exist and set some non-sunlight to them
557                         parent.position_valid = true;
558                         b.setIsUnderground(true);
559                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
560                         core::map<v3s16, bool> light_sources;
561                         // The block below should be valid because there shouldn't be
562                         // sunlight in there either
563                         UASSERT(b.propagateSunlight(light_sources, true) == true);
564                         // Should not touch nodes that are not affected (that is, all of them)
565                         //UASSERT(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
566                         // Should set light of non-sunlighted blocks to 0.
567                         UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
568                 }
569                 /*
570                         Set up a situation where:
571                         - There is only air in this block
572                         - There is a valid non-sunlighted block at the bottom, and
573                         - Invalid blocks elsewhere.
574                         - the block is not underground.
575
576                         This should result in bottom block invalidity
577                 */
578                 {
579                         b.setIsUnderground(false);
580                         // Clear block
581                         for(u16 z=0; z<MAP_BLOCKSIZE; z++){
582                                 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
583                                         for(u16 x=0; x<MAP_BLOCKSIZE; x++){
584                                                 MapNode n;
585                                                 n.setContent(CONTENT_AIR);
586                                                 n.setLight(LIGHTBANK_DAY, 0);
587                                                 b.setNode(v3s16(x,y,z), n);
588                                         }
589                                 }
590                         }
591                         // Make neighbours invalid
592                         parent.position_valid = false;
593                         // Add exceptions to the top of the bottom block
594                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
595                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
596                         {
597                                 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
598                         }
599                         // Lighting value for the valid nodes
600                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
601                         core::map<v3s16, bool> light_sources;
602                         // Bottom block is not valid
603                         UASSERT(b.propagateSunlight(light_sources) == false);
604                 }
605         }
606 };
607
608 struct TestMapSector: public TestBase
609 {
610         class TC : public NodeContainer
611         {
612         public:
613
614                 MapNode node;
615                 bool position_valid;
616
617                 TC()
618                 {
619                         position_valid = true;
620                 }
621
622                 virtual bool isValidPosition(v3s16 p)
623                 {
624                         return position_valid;
625                 }
626
627                 virtual MapNode getNode(v3s16 p)
628                 {
629                         if(position_valid == false)
630                                 throw InvalidPositionException();
631                         return node;
632                 }
633
634                 virtual void setNode(v3s16 p, MapNode & n)
635                 {
636                         if(position_valid == false)
637                                 throw InvalidPositionException();
638                 };
639
640                 virtual u16 nodeContainerId() const
641                 {
642                         return 666;
643                 }
644         };
645
646         void Run()
647         {
648                 TC parent;
649                 parent.position_valid = false;
650
651                 // Create one with no heightmaps
652                 ServerMapSector sector(&parent, v2s16(1,1));
653
654                 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
655                 UASSERT(sector.getBlockNoCreateNoEx(1) == 0);
656
657                 MapBlock * bref = sector.createBlankBlock(-2);
658
659                 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
660                 UASSERT(sector.getBlockNoCreateNoEx(-2) == bref);
661
662                 //TODO: Check for AlreadyExistsException
663
664                 /*bool exception_thrown = false;
665                 try{
666                         sector.getBlock(0);
667                 }
668                 catch(InvalidPositionException &e){
669                         exception_thrown = true;
670                 }
671                 UASSERT(exception_thrown);*/
672
673         }
674 };
675 #endif