Mapgens: Rename m_emerge to prevent name collisions
[oweals/minetest.git] / src / test.cpp
index 932f9e7ccde97b87a92799810c7ea34aaf481a7f..072bda8ef79ab63bd5abae70662328667918db68 100644 (file)
@@ -428,9 +428,9 @@ struct TestPath: public TestBase
        "      # this is just a comment\n"        \
        "this is an invalid line\n"               \
        "asdf = {\n"                              \
-       "       a = 5\n"                              \
-       "       b = 2.5\n"                            \
-       "       c = \"\"\"\n"                         \
+       "       a   = 5\n"                            \
+       "       bb  = 2.5\n"                          \
+       "       ccc = \"\"\"\n"                       \
        "testy\n"                                 \
        "   testa   \n"                           \
        "\"\"\"\n"                                \
@@ -440,6 +440,7 @@ struct TestPath: public TestBase
        "some multiline text\n"                   \
        "     with leading whitespace!\n"         \
        "\"\"\"\n"                                \
+       "np_terrain = 5, 40, (250, 250, 250), 12341, 5, 0.7, 2.4\n" \
        "zoop = true"
 
 #define TEST_CONFIG_TEXT_AFTER                \
@@ -452,37 +453,42 @@ struct TestPath: public TestBase
        "      # this is just a comment\n"        \
        "this is an invalid line\n"               \
        "asdf = {\n"                              \
-       "       a = 5\n"                              \
-       "       b = 2.5\n"                            \
-       "       c = \"\"\"\n"                         \
+       "       a   = 5\n"                            \
+       "       bb  = 2.5\n"                          \
+       "       ccc = \"\"\"\n"                       \
        "testy\n"                                 \
        "   testa   \n"                           \
        "\"\"\"\n"                                \
        "\n"                                      \
        "}\n"                                     \
-       "blarg = \"\"\"\n"                        \
+       "blarg = \"\"\" \n"                       \
        "some multiline text\n"                   \
        "     with leading whitespace!\n"         \
        "\"\"\"\n"                                \
+       "np_terrain = {\n"                        \
+       "       flags = defaults\n"                   \
+       "       lacunarity = 2.4\n"                   \
+       "       octaves = 6\n"                        \
+       "       offset = 3.5\n"                       \
+       "       persistence = 0.7\n"                  \
+       "       scale = 40\n"                         \
+       "       seed = 12341\n"                       \
+       "       spread = (250,250,250)\n"             \
+       "}\n"                                     \
        "zoop = true\n"                           \
        "coord2 = (1,2,3.3)\n"                    \
        "floaty_thing_2 = 1.2\n"                  \
-       "groupy_thing = \n"                       \
        "groupy_thing = {\n"                      \
-       "       animals = \n"                         \
-       "       animals = {\n"                        \
-       "               cat = meow\n"                     \
-       "               dog = woof\n"                     \
-       "       }\n"                                  \
+       "       animals = cute\n"                     \
        "       num_apples = 4\n"                     \
        "       num_oranges = 53\n"                   \
        "}\n"
 
-
 struct TestSettings: public TestBase
 {
        void Run()
        {
+               try {
                Settings s;
 
                // Test reading of settings
@@ -514,7 +520,7 @@ struct TestSettings: public TestBase
                UASSERT(group != NULL);
                UASSERT(s.getGroupNoEx("zoop", group) == false);
                UASSERT(group->getS16("a") == 5);
-               UASSERT(fabs(group->getFloat("b") - 2.5) < 0.001);
+               UASSERT(fabs(group->getFloat("bb") - 2.5) < 0.001);
 
                Settings *group3 = new Settings;
                group3->set("cat", "meow");
@@ -524,14 +530,41 @@ struct TestSettings: public TestBase
                group2->setS16("num_apples", 4);
                group2->setS16("num_oranges", 53);
                group2->setGroup("animals", group3);
+               group2->set("animals", "cute"); //destroys group 3
                s.setGroup("groupy_thing", group2);
 
+               // Test set failure conditions
+               UASSERT(s.set("Zoop = Poop\nsome_other_setting", "false") == false);
+               UASSERT(s.set("sneaky", "\"\"\"\njabberwocky = false") == false);
+               UASSERT(s.set("hehe", "asdfasdf\n\"\"\"\nsomething = false") == false);
+
                // Test multiline settings
-               UASSERT(group->get("c") == "testy\n   testa   ");
+               UASSERT(group->get("ccc") == "testy\n   testa   ");
+
                UASSERT(s.get("blarg") ==
                        "some multiline text\n"
                        "     with leading whitespace!");
 
+               // Test NoiseParams
+               UASSERT(s.getEntry("np_terrain").is_group == false);
+
+               NoiseParams np;
+               UASSERT(s.getNoiseParams("np_terrain", np) == true);
+               UASSERT(fabs(np.offset - 5) < 0.001);
+               UASSERT(fabs(np.scale - 40) < 0.001);
+               UASSERT(fabs(np.spread.X - 250) < 0.001);
+               UASSERT(fabs(np.spread.Y - 250) < 0.001);
+               UASSERT(fabs(np.spread.Z - 250) < 0.001);
+               UASSERT(np.seed == 12341);
+               UASSERT(np.octaves == 5);
+               UASSERT(fabs(np.persist - 0.7) < 0.001);
+
+               np.offset  = 3.5;
+               np.octaves = 6;
+               s.setNoiseParams("np_terrain", np);
+
+               UASSERT(s.getEntry("np_terrain").is_group == true);
+
                // Test writing
                std::ostringstream os(std::ios_base::binary);
                is.clear();
@@ -541,6 +574,9 @@ struct TestSettings: public TestBase
                //printf(">>>> expected config:\n%s\n", TEST_CONFIG_TEXT_AFTER);
                //printf(">>>> actual config:\n%s\n", os.str().c_str());
                UASSERT(os.str() == TEST_CONFIG_TEXT_AFTER);
+               } catch (SettingNotFoundException &e) {
+                       UASSERT(!"Setting not found!");
+               }
        }
 };