]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/test.cpp
Enable multiline signs
[dragonfireclient.git] / src / test.cpp
index 6a0e991e201c334d08dca90fba39ffdd6c917b8c..bc0692a78325f05ee5fcfb6fac7d2d81b4619081 100644 (file)
@@ -40,6 +40,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "inventory.h"
 #include "util/numeric.h"
 #include "util/serialize.h"
+#include "noise.h" // PseudoRandom used for random data for compression
+#include "clientserver.h" // LATEST_PROTOCOL_VERSION
 
 /*
        Asserts that the exception occurs
@@ -313,6 +315,26 @@ struct TestSerialization: public TestBase
        }
 };
 
+struct TestNodedefSerialization: public TestBase
+{
+       void Run()
+       {
+               ContentFeatures f;
+               f.name = "default:stone";
+               for(int i = 0; i < 6; i++)
+                       f.tiledef[i].name = "default_stone.png";
+               f.is_ground_content = true;
+               std::ostringstream os(std::ios::binary);
+               f.serialize(os, LATEST_PROTOCOL_VERSION);
+               verbosestream<<"Test ContentFeatures size: "<<os.str().size()<<std::endl;
+               std::istringstream is(os.str(), std::ios::binary);
+               ContentFeatures f2;
+               f2.deSerialize(is);
+               UASSERT(f.walkable == f2.walkable);
+               UASSERT(f.node_box.type == f2.node_box.type);
+       }
+};
+
 struct TestCompress: public TestBase
 {
        void Run()
@@ -415,6 +437,39 @@ struct TestCompress: public TestBase
                }
 
                }
+
+               // Test zlib wrapper with large amounts of data (larger than its
+               // internal buffers)
+               {
+                       infostream<<"Test: Testing zlib wrappers with a large amount "
+                                       <<"of pseudorandom data"<<std::endl;
+                       u32 size = 50000;
+                       infostream<<"Test: Input size of large compressZlib is "
+                                       <<size<<std::endl;
+                       std::string data_in;
+                       data_in.resize(size);
+                       PseudoRandom pseudorandom(9420);
+                       for(u32 i=0; i<size; i++)
+                               data_in[i] = pseudorandom.range(0,255);
+                       std::ostringstream os_compressed(std::ios::binary);
+                       compressZlib(data_in, os_compressed);
+                       infostream<<"Test: Output size of large compressZlib is "
+                                       <<os_compressed.str().size()<<std::endl;
+                       std::istringstream is_compressed(os_compressed.str(), std::ios::binary);
+                       std::ostringstream os_decompressed(std::ios::binary);
+                       decompressZlib(is_compressed, os_decompressed);
+                       infostream<<"Test: Output size of large decompressZlib is "
+                                       <<os_decompressed.str().size()<<std::endl;
+                       std::string str_decompressed = os_decompressed.str();
+                       UTEST(str_decompressed.size() == data_in.size(), "Output size not"
+                                       " equal (output: %i, input: %i)",
+                                       str_decompressed.size(), data_in.size());
+                       for(u32 i=0; i<size && i<str_decompressed.size(); i++){
+                               UTEST(str_decompressed[i] == data_in[i],
+                                               "index out[%i]=%i differs from in[%i]=%i",
+                                               i, str_decompressed[i], i, data_in[i]);
+                       }
+               }
        }
 };
 
@@ -664,6 +719,7 @@ struct TestInventory: public TestBase
        {
                std::string serialized_inventory =
                "List 0 32\n"
+               "Width 3\n"
                "Empty\n"
                "Empty\n"
                "Empty\n"
@@ -701,6 +757,7 @@ struct TestInventory: public TestBase
                
                std::string serialized_inventory_2 =
                "List main 32\n"
+               "Width 5\n"
                "Empty\n"
                "Empty\n"
                "Empty\n"
@@ -744,6 +801,8 @@ struct TestInventory: public TestBase
                inv.getList("0")->setName("main");
                UASSERT(!inv.getList("0"));
                UASSERT(inv.getList("main"));
+               UASSERT(inv.getList("main")->getWidth() == 3);
+               inv.getList("main")->setWidth(5);
                std::ostringstream inv_os(std::ios::binary);
                inv.serialize(inv_os);
                UASSERT(inv_os.str() == serialized_inventory_2);
@@ -1698,6 +1757,7 @@ void run_tests()
        TEST(TestSettings);
        TEST(TestCompress);
        TEST(TestSerialization);
+       TEST(TestNodedefSerialization);
        TESTPARAMS(TestMapNode, ndef);
        TESTPARAMS(TestVoxelManipulator, ndef);
        TESTPARAMS(TestVoxelAlgorithms, ndef);