84fad41cef895b1fd43bb3555fd897f59e689162
[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         u64 t1 = porting::getTimeMs();
232         TestGameDef gamedef;
233
234         g_logger.setLevelSilenced(LL_ERROR, true);
235
236         u32 num_modules_failed     = 0;
237         u32 num_total_tests_failed = 0;
238         u32 num_total_tests_run    = 0;
239         std::vector<TestBase *> &testmods = TestManager::getTestModules();
240         for (size_t i = 0; i != testmods.size(); i++) {
241                 if (!testmods[i]->testModule(&gamedef))
242                         num_modules_failed++;
243
244                 num_total_tests_failed += testmods[i]->num_tests_failed;
245                 num_total_tests_run += testmods[i]->num_tests_run;
246         }
247
248         u64 tdiff = porting::getTimeMs() - t1;
249
250         g_logger.setLevelSilenced(LL_ERROR, false);
251
252         const char *overall_status = (num_modules_failed == 0) ? "PASSED" : "FAILED";
253
254         rawstream
255                 << "++++++++++++++++++++++++++++++++++++++++"
256                 << "++++++++++++++++++++++++++++++++++++++++" << std::endl
257                 << "Unit Test Results: " << overall_status << std::endl
258                 << "    " << num_modules_failed << " / " << testmods.size()
259                 << " failed modules (" << num_total_tests_failed << " / "
260                 << num_total_tests_run << " failed individual tests)." << std::endl
261                 << "    Testing took " << tdiff << "ms total." << std::endl
262                 << "++++++++++++++++++++++++++++++++++++++++"
263                 << "++++++++++++++++++++++++++++++++++++++++" << std::endl;
264
265         return num_modules_failed;
266 }
267
268 ////
269 //// TestBase
270 ////
271
272 bool TestBase::testModule(IGameDef *gamedef)
273 {
274         rawstream << "======== Testing module " << getName() << std::endl;
275         u64 t1 = porting::getTimeMs();
276
277
278         runTests(gamedef);
279
280         u64 tdiff = porting::getTimeMs() - t1;
281         rawstream << "======== Module " << getName() << " "
282                 << (num_tests_failed ? "failed" : "passed") << " (" << num_tests_failed
283                 << " failures / " << num_tests_run << " tests) - " << tdiff
284                 << "ms" << std::endl;
285
286         if (!m_test_dir.empty())
287                 fs::RecursiveDelete(m_test_dir);
288
289         return num_tests_failed == 0;
290 }
291
292 std::string TestBase::getTestTempDirectory()
293 {
294         if (!m_test_dir.empty())
295                 return m_test_dir;
296
297         char buf[32];
298         snprintf(buf, sizeof(buf), "%08X", myrand());
299
300         m_test_dir = fs::TempPath() + DIR_DELIM "mttest_" + buf;
301         if (!fs::CreateDir(m_test_dir))
302                 throw TestFailedException();
303
304         return m_test_dir;
305 }
306
307 std::string TestBase::getTestTempFile()
308 {
309         char buf[32];
310         snprintf(buf, sizeof(buf), "%08X", myrand());
311
312         return getTestTempDirectory() + DIR_DELIM + buf + ".tmp";
313 }
314
315
316 /*
317         NOTE: These tests became non-working then NodeContainer was removed.
318               These should be redone, utilizing some kind of a virtual
319                   interface for Map (IMap would be fine).
320 */
321 #if 0
322 struct TestMapBlock: public TestBase
323 {
324         class TC : public NodeContainer
325         {
326         public:
327
328                 MapNode node;
329                 bool position_valid;
330                 core::list<v3s16> validity_exceptions;
331
332                 TC()
333                 {
334                         position_valid = true;
335                 }
336
337                 virtual bool isValidPosition(v3s16 p)
338                 {
339                         //return position_valid ^ (p==position_valid_exception);
340                         bool exception = false;
341                         for(core::list<v3s16>::Iterator i=validity_exceptions.begin();
342                                         i != validity_exceptions.end(); i++)
343                         {
344                                 if(p == *i)
345                                 {
346                                         exception = true;
347                                         break;
348                                 }
349                         }
350                         return exception ? !position_valid : position_valid;
351                 }
352
353                 virtual MapNode getNode(v3s16 p)
354                 {
355                         if(isValidPosition(p) == false)
356                                 throw InvalidPositionException();
357                         return node;
358                 }
359
360                 virtual void setNode(v3s16 p, MapNode & n)
361                 {
362                         if(isValidPosition(p) == false)
363                                 throw InvalidPositionException();
364                 };
365
366                 virtual u16 nodeContainerId() const
367                 {
368                         return 666;
369                 }
370         };
371
372         void Run()
373         {
374                 TC parent;
375
376                 MapBlock b(&parent, v3s16(1,1,1));
377                 v3s16 relpos(MAP_BLOCKSIZE, MAP_BLOCKSIZE, MAP_BLOCKSIZE);
378
379                 UASSERT(b.getPosRelative() == relpos);
380
381                 UASSERT(b.getBox().MinEdge.X == MAP_BLOCKSIZE);
382                 UASSERT(b.getBox().MaxEdge.X == MAP_BLOCKSIZE*2-1);
383                 UASSERT(b.getBox().MinEdge.Y == MAP_BLOCKSIZE);
384                 UASSERT(b.getBox().MaxEdge.Y == MAP_BLOCKSIZE*2-1);
385                 UASSERT(b.getBox().MinEdge.Z == MAP_BLOCKSIZE);
386                 UASSERT(b.getBox().MaxEdge.Z == MAP_BLOCKSIZE*2-1);
387
388                 UASSERT(b.isValidPosition(v3s16(0,0,0)) == true);
389                 UASSERT(b.isValidPosition(v3s16(-1,0,0)) == false);
390                 UASSERT(b.isValidPosition(v3s16(-1,-142,-2341)) == false);
391                 UASSERT(b.isValidPosition(v3s16(-124,142,2341)) == false);
392                 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
393                 UASSERT(b.isValidPosition(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE,MAP_BLOCKSIZE-1)) == false);
394
395                 /*
396                         TODO: this method should probably be removed
397                         if the block size isn't going to be set variable
398                 */
399                 /*UASSERT(b.getSizeNodes() == v3s16(MAP_BLOCKSIZE,
400                                 MAP_BLOCKSIZE, MAP_BLOCKSIZE));*/
401
402                 // Changed flag should be initially set
403                 UASSERT(b.getModified() == MOD_STATE_WRITE_NEEDED);
404                 b.resetModified();
405                 UASSERT(b.getModified() == MOD_STATE_CLEAN);
406
407                 // All nodes should have been set to
408                 // .d=CONTENT_IGNORE and .getLight() = 0
409                 for(u16 z=0; z<MAP_BLOCKSIZE; z++)
410                 for(u16 y=0; y<MAP_BLOCKSIZE; y++)
411                 for(u16 x=0; x<MAP_BLOCKSIZE; x++)
412                 {
413                         //UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_AIR);
414                         UASSERT(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_IGNORE);
415                         UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
416                         UASSERT(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
417                 }
418
419                 {
420                         MapNode n(CONTENT_AIR);
421                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
422                         for(u16 y=0; y<MAP_BLOCKSIZE; y++)
423                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
424                         {
425                                 b.setNode(v3s16(x,y,z), n);
426                         }
427                 }
428
429                 /*
430                         Parent fetch functions
431                 */
432                 parent.position_valid = false;
433                 parent.node.setContent(5);
434
435                 MapNode n;
436
437                 // Positions in the block should still be valid
438                 UASSERT(b.isValidPositionParent(v3s16(0,0,0)) == true);
439                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
440                 n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
441                 UASSERT(n.getContent() == CONTENT_AIR);
442
443                 // ...but outside the block they should be invalid
444                 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
445                 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == false);
446                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == false);
447
448                 {
449                         bool exception_thrown = false;
450                         try{
451                                 // This should throw an exception
452                                 MapNode n = b.getNodeParent(v3s16(0,0,-1));
453                         }
454                         catch(InvalidPositionException &e)
455                         {
456                                 exception_thrown = true;
457                         }
458                         UASSERT(exception_thrown);
459                 }
460
461                 parent.position_valid = true;
462                 // Now the positions outside should be valid
463                 UASSERT(b.isValidPositionParent(v3s16(-121,2341,0)) == true);
464                 UASSERT(b.isValidPositionParent(v3s16(-1,0,0)) == true);
465                 UASSERT(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
466                 n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
467                 UASSERT(n.getContent() == 5);
468
469                 /*
470                         Set a node
471                 */
472                 v3s16 p(1,2,0);
473                 n.setContent(4);
474                 b.setNode(p, n);
475                 UASSERT(b.getNode(p).getContent() == 4);
476                 //TODO: Update to new system
477                 /*UASSERT(b.getNodeTile(p) == 4);
478                 UASSERT(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
479
480                 /*
481                         propagateSunlight()
482                 */
483                 // Set lighting of all nodes to 0
484                 for(u16 z=0; z<MAP_BLOCKSIZE; z++){
485                         for(u16 y=0; y<MAP_BLOCKSIZE; y++){
486                                 for(u16 x=0; x<MAP_BLOCKSIZE; x++){
487                                         MapNode n = b.getNode(v3s16(x,y,z));
488                                         n.setLight(LIGHTBANK_DAY, 0);
489                                         n.setLight(LIGHTBANK_NIGHT, 0);
490                                         b.setNode(v3s16(x,y,z), n);
491                                 }
492                         }
493                 }
494                 {
495                         /*
496                                 Check how the block handles being a lonely sky block
497                         */
498                         parent.position_valid = true;
499                         b.setIsUnderground(false);
500                         parent.node.setContent(CONTENT_AIR);
501                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
502                         parent.node.setLight(LIGHTBANK_NIGHT, 0);
503                         core::map<v3s16, bool> light_sources;
504                         // The bottom block is invalid, because we have a shadowing node
505                         UASSERT(b.propagateSunlight(light_sources) == false);
506                         UASSERT(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
507                         UASSERT(b.getNode(v3s16(1,3,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
508                         UASSERT(b.getNode(v3s16(1,2,0)).getLight(LIGHTBANK_DAY) == 0);
509                         UASSERT(b.getNode(v3s16(1,1,0)).getLight(LIGHTBANK_DAY) == 0);
510                         UASSERT(b.getNode(v3s16(1,0,0)).getLight(LIGHTBANK_DAY) == 0);
511                         UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == LIGHT_SUN);
512                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,1,0)) == LIGHT_SUN);
513                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,-1,0)) == 0);
514                         UASSERT(b.getFaceLight2(0, p, v3s16(0,-1,0)) == 0);
515                         // According to MapBlock::getFaceLight,
516                         // The face on the z+ side should have double-diminished light
517                         //UASSERT(b.getFaceLight(p, v3s16(0,0,1)) == diminish_light(diminish_light(LIGHT_MAX)));
518                         // The face on the z+ side should have diminished light
519                         UASSERT(b.getFaceLight2(1000, p, v3s16(0,0,1)) == diminish_light(LIGHT_MAX));
520                 }
521                 /*
522                         Check how the block handles being in between blocks with some non-sunlight
523                         while being underground
524                 */
525                 {
526                         // Make neighbours to exist and set some non-sunlight to them
527                         parent.position_valid = true;
528                         b.setIsUnderground(true);
529                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
530                         core::map<v3s16, bool> light_sources;
531                         // The block below should be valid because there shouldn't be
532                         // sunlight in there either
533                         UASSERT(b.propagateSunlight(light_sources, true) == true);
534                         // Should not touch nodes that are not affected (that is, all of them)
535                         //UASSERT(b.getNode(v3s16(1,2,3)).getLight() == LIGHT_SUN);
536                         // Should set light of non-sunlighted blocks to 0.
537                         UASSERT(b.getNode(v3s16(1,2,3)).getLight(LIGHTBANK_DAY) == 0);
538                 }
539                 /*
540                         Set up a situation where:
541                         - There is only air in this block
542                         - There is a valid non-sunlighted block at the bottom, and
543                         - Invalid blocks elsewhere.
544                         - the block is not underground.
545
546                         This should result in bottom block invalidity
547                 */
548                 {
549                         b.setIsUnderground(false);
550                         // Clear block
551                         for(u16 z=0; z<MAP_BLOCKSIZE; z++){
552                                 for(u16 y=0; y<MAP_BLOCKSIZE; y++){
553                                         for(u16 x=0; x<MAP_BLOCKSIZE; x++){
554                                                 MapNode n;
555                                                 n.setContent(CONTENT_AIR);
556                                                 n.setLight(LIGHTBANK_DAY, 0);
557                                                 b.setNode(v3s16(x,y,z), n);
558                                         }
559                                 }
560                         }
561                         // Make neighbours invalid
562                         parent.position_valid = false;
563                         // Add exceptions to the top of the bottom block
564                         for(u16 x=0; x<MAP_BLOCKSIZE; x++)
565                         for(u16 z=0; z<MAP_BLOCKSIZE; z++)
566                         {
567                                 parent.validity_exceptions.push_back(v3s16(MAP_BLOCKSIZE+x, MAP_BLOCKSIZE-1, MAP_BLOCKSIZE+z));
568                         }
569                         // Lighting value for the valid nodes
570                         parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2);
571                         core::map<v3s16, bool> light_sources;
572                         // Bottom block is not valid
573                         UASSERT(b.propagateSunlight(light_sources) == false);
574                 }
575         }
576 };
577
578 struct TestMapSector: public TestBase
579 {
580         class TC : public NodeContainer
581         {
582         public:
583
584                 MapNode node;
585                 bool position_valid;
586
587                 TC()
588                 {
589                         position_valid = true;
590                 }
591
592                 virtual bool isValidPosition(v3s16 p)
593                 {
594                         return position_valid;
595                 }
596
597                 virtual MapNode getNode(v3s16 p)
598                 {
599                         if(position_valid == false)
600                                 throw InvalidPositionException();
601                         return node;
602                 }
603
604                 virtual void setNode(v3s16 p, MapNode & n)
605                 {
606                         if(position_valid == false)
607                                 throw InvalidPositionException();
608                 };
609
610                 virtual u16 nodeContainerId() const
611                 {
612                         return 666;
613                 }
614         };
615
616         void Run()
617         {
618                 TC parent;
619                 parent.position_valid = false;
620
621                 // Create one with no heightmaps
622                 ServerMapSector sector(&parent, v2s16(1,1));
623
624                 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
625                 UASSERT(sector.getBlockNoCreateNoEx(1) == 0);
626
627                 MapBlock * bref = sector.createBlankBlock(-2);
628
629                 UASSERT(sector.getBlockNoCreateNoEx(0) == 0);
630                 UASSERT(sector.getBlockNoCreateNoEx(-2) == bref);
631
632                 //TODO: Check for AlreadyExistsException
633
634                 /*bool exception_thrown = false;
635                 try{
636                         sector.getBlock(0);
637                 }
638                 catch(InvalidPositionException &e){
639                         exception_thrown = true;
640                 }
641                 UASSERT(exception_thrown);*/
642
643         }
644 };
645 #endif