]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/test.cpp
quick fix to it not building with gettext on my visual studio environment
[dragonfireclient.git] / src / test.cpp
index 07ef772eff7755c2b74de152bea0091520b1d30a..3ff4dc8071d6ae41baf6b45a2a93a2e366458f07 100644 (file)
@@ -30,6 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "voxel.h"
 #include <sstream>
 #include "porting.h"
+#include "content_mapnode.h"
+#include "mapsector.h"
 
 /*
        Asserts that the exception occurs
@@ -59,6 +61,38 @@ struct TestUtilities
                assert(is_yes("FAlse") == false);
        }
 };
+
+struct TestSettings
+{
+       void Run()
+       {
+               Settings s;
+               // Test reading of settings
+               s.parseConfigLine("leet = 1337");
+               s.parseConfigLine("leetleet = 13371337");
+               s.parseConfigLine("leetleet_neg = -13371337");
+               s.parseConfigLine("floaty_thing = 1.1");
+               s.parseConfigLine("stringy_thing = asd /( ¤%&(/\" BLÖÄRP");
+               s.parseConfigLine("coord = (1, 2, 4.5)");
+               assert(s.getS32("leet") == 1337);
+               assert(s.getS16("leetleet") == 32767);
+               assert(s.getS16("leetleet_neg") == -32768);
+               // Not sure if 1.1 is an exact value as a float, but doesn't matter
+               assert(fabs(s.getFloat("floaty_thing") - 1.1) < 0.001);
+               assert(s.get("stringy_thing") == "asd /( ¤%&(/\" BLÖÄRP");
+               assert(fabs(s.getV3F("coord").X - 1.0) < 0.001);
+               assert(fabs(s.getV3F("coord").Y - 2.0) < 0.001);
+               assert(fabs(s.getV3F("coord").Z - 4.5) < 0.001);
+               // Test the setting of settings too
+               s.setFloat("floaty_thing_2", 1.2);
+               s.setV3F("coord2", v3f(1, 2, 3.3));
+               assert(s.get("floaty_thing_2").substr(0,3) == "1.2");
+               assert(fabs(s.getFloat("floaty_thing_2") - 1.2) < 0.001);
+               assert(fabs(s.getV3F("coord2").X - 1.0) < 0.001);
+               assert(fabs(s.getV3F("coord2").Y - 2.0) < 0.001);
+               assert(fabs(s.getV3F("coord2").Z - 3.3) < 0.001);
+       }
+};
                
 struct TestCompress
 {
@@ -185,14 +219,14 @@ struct TestMapNode
                MapNode n;
 
                // Default values
-               assert(n.d == CONTENT_AIR);
+               assert(n.getContent() == CONTENT_AIR);
                assert(n.getLight(LIGHTBANK_DAY) == 0);
                assert(n.getLight(LIGHTBANK_NIGHT) == 0);
                
                // Transparency
-               n.d = CONTENT_AIR;
+               n.setContent(CONTENT_AIR);
                assert(n.light_propagates() == true);
-               n.d = CONTENT_STONE;
+               n.setContent(CONTENT_STONE);
                assert(n.light_propagates() == false);
        }
 };
@@ -250,7 +284,7 @@ struct TestVoxelManipulator
 
                v.print(dstream);
 
-               assert(v.getNode(v3s16(-1,0,-1)).d == 2);
+               assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
 
                dstream<<"*** Reading from inexistent (0,0,-1) ***"<<std::endl;
 
@@ -264,7 +298,7 @@ struct TestVoxelManipulator
                
                v.print(dstream);
 
-               assert(v.getNode(v3s16(-1,0,-1)).d == 2);
+               assert(v.getNode(v3s16(-1,0,-1)).getContent() == 2);
                EXCEPTION_CHECK(InvalidPositionException, v.getNode(v3s16(0,1,1)));
 
 #if 0
@@ -297,11 +331,11 @@ struct TestVoxelManipulator
                        MapNode n;
                        //n.pressure = size.Y - y;
                        if(*p == '#')
-                               n.d = CONTENT_STONE;
+                               n.setContent(CONTENT_STONE);
                        else if(*p == '.')
-                               n.d = CONTENT_WATER;
+                               n.setContent(CONTENT_WATER);
                        else if(*p == ' ')
-                               n.d = CONTENT_AIR;
+                               n.setContent(CONTENT_AIR);
                        else
                                assert(0);
                        v.setNode(v3s16(x,y,z), n);
@@ -338,6 +372,12 @@ struct TestVoxelManipulator
        }
 };
 
+/*
+       NOTE: These tests became non-working then NodeContainer was removed.
+             These should be redone, utilizing some kind of a virtual
+                 interface for Map (IMap would be fine).
+*/
+#if 0
 struct TestMapBlock
 {
        class TC : public NodeContainer
@@ -424,21 +464,32 @@ struct TestMapBlock
                assert(b.getChangedFlag() == false);
 
                // All nodes should have been set to
-               // .d=CONTENT_AIR and .getLight() = 0
+               // .d=CONTENT_IGNORE and .getLight() = 0
                for(u16 z=0; z<MAP_BLOCKSIZE; z++)
                for(u16 y=0; y<MAP_BLOCKSIZE; y++)
                for(u16 x=0; x<MAP_BLOCKSIZE; x++)
                {
-                       assert(b.getNode(v3s16(x,y,z)).d == CONTENT_AIR);
+                       //assert(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_AIR);
+                       assert(b.getNode(v3s16(x,y,z)).getContent() == CONTENT_IGNORE);
                        assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_DAY) == 0);
                        assert(b.getNode(v3s16(x,y,z)).getLight(LIGHTBANK_NIGHT) == 0);
                }
                
+               {
+                       MapNode n(CONTENT_AIR);
+                       for(u16 z=0; z<MAP_BLOCKSIZE; z++)
+                       for(u16 y=0; y<MAP_BLOCKSIZE; y++)
+                       for(u16 x=0; x<MAP_BLOCKSIZE; x++)
+                       {
+                               b.setNode(v3s16(x,y,z), n);
+                       }
+               }
+                       
                /*
                        Parent fetch functions
                */
                parent.position_valid = false;
-               parent.node.d = 5;
+               parent.node.setContent(5);
 
                MapNode n;
                
@@ -446,7 +497,7 @@ struct TestMapBlock
                assert(b.isValidPositionParent(v3s16(0,0,0)) == true);
                assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1)) == true);
                n = b.getNodeParent(v3s16(0,MAP_BLOCKSIZE-1,0));
-               assert(n.d == CONTENT_AIR);
+               assert(n.getContent() == CONTENT_AIR);
 
                // ...but outside the block they should be invalid
                assert(b.isValidPositionParent(v3s16(-121,2341,0)) == false);
@@ -472,15 +523,15 @@ struct TestMapBlock
                assert(b.isValidPositionParent(v3s16(-1,0,0)) == true);
                assert(b.isValidPositionParent(v3s16(MAP_BLOCKSIZE-1,MAP_BLOCKSIZE-1,MAP_BLOCKSIZE)) == true);
                n = b.getNodeParent(v3s16(0,0,MAP_BLOCKSIZE));
-               assert(n.d == 5);
+               assert(n.getContent() == 5);
 
                /*
                        Set a node
                */
                v3s16 p(1,2,0);
-               n.d = 4;
+               n.setContent(4);
                b.setNode(p, n);
-               assert(b.getNode(p).d == 4);
+               assert(b.getNode(p).getContent() == 4);
                //TODO: Update to new system
                /*assert(b.getNodeTile(p) == 4);
                assert(b.getNodeTile(v3s16(-1,-1,0)) == 5);*/
@@ -505,7 +556,7 @@ struct TestMapBlock
                        */
                        parent.position_valid = true;
                        b.setIsUnderground(false);
-                       parent.node.d = CONTENT_AIR;
+                       parent.node.setContent(CONTENT_AIR);
                        parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN);
                        parent.node.setLight(LIGHTBANK_NIGHT, 0);
                        core::map<v3s16, bool> light_sources;
@@ -560,7 +611,7 @@ struct TestMapBlock
                                for(u16 y=0; y<MAP_BLOCKSIZE; y++){
                                        for(u16 x=0; x<MAP_BLOCKSIZE; x++){
                                                MapNode n;
-                                               n.d = CONTENT_AIR;
+                                               n.setContent(CONTENT_AIR);
                                                n.setLight(LIGHTBANK_DAY, 0);
                                                b.setNode(v3s16(x,y,z), n);
                                        }
@@ -629,13 +680,13 @@ struct TestMapSector
                // Create one with no heightmaps
                ServerMapSector sector(&parent, v2s16(1,1));
                
-               EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
-               EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(1));
+               assert(sector.getBlockNoCreateNoEx(0) == 0);
+               assert(sector.getBlockNoCreateNoEx(1) == 0);
 
                MapBlock * bref = sector.createBlankBlock(-2);
                
-               EXCEPTION_CHECK(InvalidPositionException, sector.getBlockNoCreate(0));
-               assert(sector.getBlockNoCreate(-2) == bref);
+               assert(sector.getBlockNoCreateNoEx(0) == 0);
+               assert(sector.getBlockNoCreateNoEx(-2) == bref);
                
                //TODO: Check for AlreadyExistsException
 
@@ -650,6 +701,7 @@ struct TestMapSector
 
        }
 };
+#endif
 
 struct TestSocket
 {
@@ -1013,11 +1065,12 @@ void run_tests()
        DSTACK(__FUNCTION_NAME);
        dstream<<"run_tests() started"<<std::endl;
        TEST(TestUtilities);
+       TEST(TestSettings);
        TEST(TestCompress);
        TEST(TestMapNode);
        TEST(TestVoxelManipulator);
-       TEST(TestMapBlock);
-       TEST(TestMapSector);
+       //TEST(TestMapBlock);
+       //TEST(TestMapSector);
        if(INTERNET_SIMULATOR == false){
                TEST(TestSocket);
                dout_con<<"=== BEGIN RUNNING UNIT TESTS FOR CONNECTION ==="<<std::endl;