From cde2a7f6f24f638421238ead4e61b155322fefc8 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 25 Jan 2020 16:56:54 +0100 Subject: 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 --- src/unittest/test_settings.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/unittest') 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); +} -- cgit v1.2.3