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