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