aboutsummaryrefslogtreecommitdiff
path: root/src/unittest/test_map_settings_manager.cpp
diff options
context:
space:
mode:
authorSmallJoker <mk939@ymail.com>2020-11-22 17:49:30 +0100
committersfan5 <sfan5@live.de>2021-01-29 17:32:35 +0100
commit37a05ec8d6cbf9ff4432225cffe78c16fdd0647d (patch)
tree727e4272f1f16fe1a6a51484d1bba728c8632615 /src/unittest/test_map_settings_manager.cpp
parent5e9dd1667b244df4e7767be404d4a12966d6a90a (diff)
downloadminetest-37a05ec8d6cbf9ff4432225cffe78c16fdd0647d.tar.gz
minetest-37a05ec8d6cbf9ff4432225cffe78c16fdd0647d.tar.bz2
minetest-37a05ec8d6cbf9ff4432225cffe78c16fdd0647d.zip
Settings: Proper priority hierarchy
Remove old defaults system Introduce priority-based fallback list Use new functions for map_meta special functions Change groups to use end tags Unittest changes: * Adapt unittest to the new code * Compare Settings objects
Diffstat (limited to 'src/unittest/test_map_settings_manager.cpp')
-rw-r--r--src/unittest/test_map_settings_manager.cpp86
1 files changed, 55 insertions, 31 deletions
diff --git a/src/unittest/test_map_settings_manager.cpp b/src/unittest/test_map_settings_manager.cpp
index 3d642a9b4..81ca68705 100644
--- a/src/unittest/test_map_settings_manager.cpp
+++ b/src/unittest/test_map_settings_manager.cpp
@@ -30,7 +30,7 @@ public:
TestMapSettingsManager() { TestManager::registerTestModule(this); }
const char *getName() { return "TestMapSettingsManager"; }
- void makeUserConfig(Settings *conf);
+ void makeUserConfig();
std::string makeMetaFile(bool make_corrupt);
void runTests(IGameDef *gamedef);
@@ -65,8 +65,11 @@ void check_noise_params(const NoiseParams *np1, const NoiseParams *np2)
}
-void TestMapSettingsManager::makeUserConfig(Settings *conf)
+void TestMapSettingsManager::makeUserConfig()
{
+ delete Settings::getLayer(SL_GLOBAL);
+ Settings *conf = Settings::createLayer(SL_GLOBAL);
+
conf->set("mg_name", "v7");
conf->set("seed", "5678");
conf->set("water_level", "20");
@@ -103,12 +106,11 @@ std::string TestMapSettingsManager::makeMetaFile(bool make_corrupt)
void TestMapSettingsManager::testMapSettingsManager()
{
- Settings user_settings;
- makeUserConfig(&user_settings);
+ makeUserConfig();
std::string test_mapmeta_path = makeMetaFile(false);
- MapSettingsManager mgr(&user_settings, test_mapmeta_path);
+ MapSettingsManager mgr(test_mapmeta_path);
std::string value;
UASSERT(mgr.getMapSetting("mg_name", &value));
@@ -140,6 +142,12 @@ void TestMapSettingsManager::testMapSettingsManager()
mgr.setMapSettingNoiseParams("mgv5_np_height", &script_np_height);
mgr.setMapSettingNoiseParams("mgv5_np_factor", &script_np_factor);
+ {
+ NoiseParams dummy;
+ mgr.getMapSettingNoiseParams("mgv5_np_factor", &dummy);
+ check_noise_params(&dummy, &script_np_factor);
+ }
+
// Now make our Params and see if the values are correctly sourced
MapgenParams *params = mgr.makeMapgenParams();
UASSERT(params->mgtype == MAPGEN_V5);
@@ -188,50 +196,66 @@ void TestMapSettingsManager::testMapSettingsManager()
void TestMapSettingsManager::testMapMetaSaveLoad()
{
- Settings conf;
std::string path = getTestTempDirectory()
+ DIR_DELIM + "foobar" + DIR_DELIM + "map_meta.txt";
+ makeUserConfig();
+ Settings &conf = *Settings::getLayer(SL_GLOBAL);
+
+ // There cannot be two MapSettingsManager
+ // copy the mapgen params to compare them
+ MapgenParams params1, params2;
// Create a set of mapgen params and save them to map meta
- conf.set("seed", "12345");
- conf.set("water_level", "5");
- MapSettingsManager mgr1(&conf, path);
- MapgenParams *params1 = mgr1.makeMapgenParams();
- UASSERT(params1);
- UASSERT(mgr1.saveMapMeta());
+ {
+ conf.set("seed", "12345");
+ conf.set("water_level", "5");
+ MapSettingsManager mgr(path);
+ MapgenParams *params = mgr.makeMapgenParams();
+ UASSERT(params);
+ params1 = *params;
+ params1.bparams = nullptr; // No double-free
+ UASSERT(mgr.saveMapMeta());
+ }
// Now try loading the map meta to mapgen params
- conf.set("seed", "67890");
- conf.set("water_level", "32");
- MapSettingsManager mgr2(&conf, path);
- UASSERT(mgr2.loadMapMeta());
- MapgenParams *params2 = mgr2.makeMapgenParams();
- UASSERT(params2);
+ {
+ conf.set("seed", "67890");
+ conf.set("water_level", "32");
+ MapSettingsManager mgr(path);
+ UASSERT(mgr.loadMapMeta());
+ MapgenParams *params = mgr.makeMapgenParams();
+ UASSERT(params);
+ params2 = *params;
+ params2.bparams = nullptr; // No double-free
+ }
// Check that both results are correct
- UASSERTEQ(u64, params1->seed, 12345);
- UASSERTEQ(s16, params1->water_level, 5);
- UASSERTEQ(u64, params2->seed, 12345);
- UASSERTEQ(s16, params2->water_level, 5);
+ UASSERTEQ(u64, params1.seed, 12345);
+ UASSERTEQ(s16, params1.water_level, 5);
+ UASSERTEQ(u64, params2.seed, 12345);
+ UASSERTEQ(s16, params2.water_level, 5);
}
void TestMapSettingsManager::testMapMetaFailures()
{
std::string test_mapmeta_path;
- Settings conf;
// Check to see if it'll fail on a non-existent map meta file
- test_mapmeta_path = "woobawooba/fgdfg/map_meta.txt";
- UASSERT(!fs::PathExists(test_mapmeta_path));
+ {
+ test_mapmeta_path = "woobawooba/fgdfg/map_meta.txt";
+ UASSERT(!fs::PathExists(test_mapmeta_path));
- MapSettingsManager mgr1(&conf, test_mapmeta_path);
- UASSERT(!mgr1.loadMapMeta());
+ MapSettingsManager mgr1(test_mapmeta_path);
+ UASSERT(!mgr1.loadMapMeta());
+ }
// Check to see if it'll fail on a corrupt map meta file
- test_mapmeta_path = makeMetaFile(true);
- UASSERT(fs::PathExists(test_mapmeta_path));
+ {
+ test_mapmeta_path = makeMetaFile(true);
+ UASSERT(fs::PathExists(test_mapmeta_path));
- MapSettingsManager mgr2(&conf, test_mapmeta_path);
- UASSERT(!mgr2.loadMapMeta());
+ MapSettingsManager mgr2(test_mapmeta_path);
+ UASSERT(!mgr2.loadMapMeta());
+ }
}