summaryrefslogtreecommitdiff
path: root/src/unittest
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2020-01-25 16:56:54 +0100
committerGitHub <noreply@github.com>2020-01-25 16:56:54 +0100
commitcde2a7f6f24f638421238ead4e61b155322fefc8 (patch)
tree96b6b1dd00a0c14660eea6f3f518b5d832dc1bd8 /src/unittest
parent9cb3219f34be983e1b84a62a64c25e137d587365 (diff)
downloadminetest-cde2a7f6f24f638421238ead4e61b155322fefc8.tar.gz
minetest-cde2a7f6f24f638421238ead4e61b155322fefc8.tar.bz2
minetest-cde2a7f6f24f638421238ead4e61b155322fefc8.zip
Settings: Add get_flags API for mapgen flags (mg_flags, mgv6_spflags, ...) (#9284)
Unified flags handling in C++ and Lua Settings API -> Reading only, for now. Writing can be implemented later, if needed. API function to read the currently active flags -> was impossible from Lua Co-authored-by: Wuzzy <wuzzy2@mail.ru>
Diffstat (limited to 'src/unittest')
-rw-r--r--src/unittest/test_settings.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/unittest/test_settings.cpp b/src/unittest/test_settings.cpp
index b2666559e..aa56f3e06 100644
--- a/src/unittest/test_settings.cpp
+++ b/src/unittest/test_settings.cpp
@@ -31,6 +31,7 @@ public:
void runTests(IGameDef *gamedef);
void testAllSettings();
+ void testFlagDesc();
static const char *config_text_before;
static const std::string config_text_after;
@@ -41,6 +42,7 @@ static TestSettings g_test_instance;
void TestSettings::runTests(IGameDef *gamedef)
{
TEST(testAllSettings);
+ TEST(testFlagDesc);
}
////////////////////////////////////////////////////////////////////////////////
@@ -206,3 +208,38 @@ void TestSettings::testAllSettings()
UASSERT(!"Setting not found!");
}
}
+
+void TestSettings::testFlagDesc()
+{
+ Settings s;
+ FlagDesc flagdesc[] = {
+ { "biomes", 0x01 },
+ { "trees", 0x02 },
+ { "jungles", 0x04 },
+ { "oranges", 0x08 },
+ { "tables", 0x10 },
+ { nullptr, 0 }
+ };
+
+ // Enabled: biomes, jungles, oranges (default)
+ s.setDefault("test_desc", flagdesc, readFlagString(
+ "biomes,notrees,jungles,oranges", flagdesc, nullptr));
+ UASSERT(s.getFlagStr("test_desc", flagdesc, nullptr) == (0x01 | 0x04 | 0x08));
+
+ // Enabled: jungles, oranges, tables
+ s.set("test_desc", "nobiomes,tables");
+ UASSERT(s.getFlagStr("test_desc", flagdesc, nullptr) == (0x04 | 0x08 | 0x10));
+
+ // Enabled: (nothing)
+ s.set("test_desc", "nobiomes,nojungles,nooranges,notables");
+ UASSERT(s.getFlagStr("test_desc", flagdesc, nullptr) == 0x00);
+
+ // Numeric flag tests (override)
+ // Enabled: trees, tables
+ s.setDefault("test_flags", flagdesc, 0x02 | 0x10);
+ UASSERT(s.getFlagStr("test_flags", flagdesc, nullptr) == (0x02 | 0x10));
+
+ // Enabled: tables
+ s.set("test_flags", "16");
+ UASSERT(s.getFlagStr("test_flags", flagdesc, nullptr) == 0x10);
+}