X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Funittest%2Ftest.cpp;h=af30c209dba101c77dedf12fe3d05ef37f508a7f;hb=9f338f5a56e5adee3d11d59827f7e2b8a714e6c2;hp=7a0ef16b10cca605cfc60ed6ef211dcdcb84185b;hpb=ce873108aa91d19104f46c5acd3350385e7a4541;p=dragonfireclient.git diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 7a0ef16b1..af30c209d 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -24,8 +24,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "itemdef.h" #include "gamedef.h" #include "modchannels.h" -#include "mods.h" +#include "content/mods.h" +#include "database/database-dummy.h" #include "util/numeric.h" +#include "porting.h" content_t t_CONTENT_STONE; content_t t_CONTENT_GRASS; @@ -54,6 +56,7 @@ class TestGameDef : public IGameDef { scene::ISceneManager *getSceneManager() { return m_scenemgr; } IRollbackManager *getRollbackManager() { return m_rollbackmgr; } EmergeManager *getEmergeManager() { return m_emergemgr; } + ModMetadataDatabase *getModStorageDatabase() { return m_mod_storage_database; } scene::IAnimatedMesh *getMesh(const std::string &filename) { return NULL; } bool checkLocalPrivilege(const std::string &priv) { return false; } @@ -67,7 +70,6 @@ class TestGameDef : public IGameDef { return testmodspec; } virtual const ModSpec* getModSpec(const std::string &modname) const { return NULL; } - virtual std::string getModStoragePath() const { return "."; } virtual bool registerModStorage(ModMetadata *meta) { return true; } virtual void unregisterModStorage(const std::string &name) {} bool joinModChannel(const std::string &channel); @@ -88,11 +90,13 @@ class TestGameDef : public IGameDef { scene::ISceneManager *m_scenemgr = nullptr; IRollbackManager *m_rollbackmgr = nullptr; EmergeManager *m_emergemgr = nullptr; + ModMetadataDatabase *m_mod_storage_database = nullptr; std::unique_ptr m_modchannel_mgr; }; TestGameDef::TestGameDef() : + m_mod_storage_database(new Database_Dummy()), m_modchannel_mgr(new ModChannelMgr()) { m_itemdef = createItemDefManager(); @@ -106,6 +110,7 @@ TestGameDef::~TestGameDef() { delete m_itemdef; delete m_nodedef; + delete m_mod_storage_database; } @@ -179,7 +184,7 @@ void TestGameDef::defineSomeNodes() "{default_water.png"; f = ContentFeatures(); f.name = itemdef.name; - f.alpha = 128; + f.alpha = ALPHAMODE_BLEND; f.liquid_type = LIQUID_SOURCE; f.liquid_viscosity = 4; f.is_ground_content = true; @@ -200,7 +205,7 @@ void TestGameDef::defineSomeNodes() "{default_lava.png"; f = ContentFeatures(); f.name = itemdef.name; - f.alpha = 128; + f.alpha = ALPHAMODE_OPAQUE; f.liquid_type = LIQUID_SOURCE; f.liquid_viscosity = 7; f.light_source = LIGHT_MAX-1; @@ -323,7 +328,7 @@ std::string TestBase::getTestTempDirectory() return m_test_dir; char buf[32]; - snprintf(buf, sizeof(buf), "%08X", myrand()); + porting::mt_snprintf(buf, sizeof(buf), "%08X", myrand()); m_test_dir = fs::TempPath() + DIR_DELIM "mttest_" + buf; if (!fs::CreateDir(m_test_dir)) @@ -335,7 +340,7 @@ std::string TestBase::getTestTempDirectory() std::string TestBase::getTestTempFile() { char buf[32]; - snprintf(buf, sizeof(buf), "%08X", myrand()); + porting::mt_snprintf(buf, sizeof(buf), "%08X", myrand()); return getTestTempDirectory() + DIR_DELIM + buf + ".tmp"; } @@ -355,7 +360,7 @@ struct TestMapBlock: public TestBase MapNode node; bool position_valid; - core::list validity_exceptions; + std::list validity_exceptions; TC() { @@ -366,7 +371,7 @@ struct TestMapBlock: public TestBase { //return position_valid ^ (p==position_valid_exception); bool exception = false; - for(core::list::Iterator i=validity_exceptions.begin(); + for(std::list::iterator i=validity_exceptions.begin(); i != validity_exceptions.end(); i++) { if(p == *i) @@ -528,7 +533,7 @@ struct TestMapBlock: public TestBase parent.node.setContent(CONTENT_AIR); parent.node.setLight(LIGHTBANK_DAY, LIGHT_SUN); parent.node.setLight(LIGHTBANK_NIGHT, 0); - core::map light_sources; + std::map light_sources; // The bottom block is invalid, because we have a shadowing node UASSERT(b.propagateSunlight(light_sources) == false); UASSERT(b.getNode(v3s16(1,4,0)).getLight(LIGHTBANK_DAY) == LIGHT_SUN); @@ -555,7 +560,7 @@ struct TestMapBlock: public TestBase parent.position_valid = true; b.setIsUnderground(true); parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2); - core::map light_sources; + std::map light_sources; // The block below should be valid because there shouldn't be // sunlight in there either UASSERT(b.propagateSunlight(light_sources, true) == true); @@ -596,7 +601,7 @@ struct TestMapBlock: public TestBase } // Lighting value for the valid nodes parent.node.setLight(LIGHTBANK_DAY, LIGHT_MAX/2); - core::map light_sources; + std::map light_sources; // Bottom block is not valid UASSERT(b.propagateSunlight(light_sources) == false); } @@ -649,12 +654,12 @@ struct TestMapSector: public TestBase // Create one with no heightmaps ServerMapSector sector(&parent, v2s16(1,1)); - UASSERT(sector.getBlockNoCreateNoEx(0) == 0); - UASSERT(sector.getBlockNoCreateNoEx(1) == 0); + UASSERT(sector.getBlockNoCreateNoEx(0) == nullptr); + UASSERT(sector.getBlockNoCreateNoEx(1) == nullptr); MapBlock * bref = sector.createBlankBlock(-2); - UASSERT(sector.getBlockNoCreateNoEx(0) == 0); + UASSERT(sector.getBlockNoCreateNoEx(0) == nullptr); UASSERT(sector.getBlockNoCreateNoEx(-2) == bref); //TODO: Check for AlreadyExistsException