Translated using Weblate (Russian)
[oweals/minetest.git] / src / unittest / test.cpp
index 615ec2162466dc27988c1f13455d7a9942db3ba0..a783ccd3293d7cbea5c6a06f8c8ae4a4f3465dda 100644 (file)
@@ -19,11 +19,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #include "test.h"
 
+#include "client/sound.h"
 #include "nodedef.h"
 #include "itemdef.h"
 #include "gamedef.h"
-#include "mods.h"
+#include "modchannels.h"
+#include "content/mods.h"
 #include "util/numeric.h"
+#include "porting.h"
 
 content_t t_CONTENT_STONE;
 content_t t_CONTENT_GRASS;
@@ -44,12 +47,11 @@ public:
        ~TestGameDef();
 
        IItemDefManager *getItemDefManager() { return m_itemdef; }
-       INodeDefManager *getNodeDefManager() { return m_nodedef; }
+       const NodeDefManager *getNodeDefManager() { return m_nodedef; }
        ICraftDefManager *getCraftDefManager() { return m_craftdef; }
        ITextureSource *getTextureSource() { return m_texturesrc; }
        IShaderSource *getShaderSource() { return m_shadersrc; }
        ISoundManager *getSoundManager() { return m_soundmgr; }
-       MtEventManager *getEventManager() { return m_eventmgr; }
        scene::ISceneManager *getSceneManager() { return m_scenemgr; }
        IRollbackManager *getRollbackManager() { return m_rollbackmgr; }
        EmergeManager *getEmergeManager() { return m_emergemgr; }
@@ -69,22 +71,30 @@ public:
        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);
+       bool leaveModChannel(const std::string &channel);
+       bool sendModChannelMessage(const std::string &channel, const std::string &message);
+       ModChannel *getModChannel(const std::string &channel)
+       {
+               return m_modchannel_mgr->getModChannel(channel);
+       }
 
 private:
        IItemDefManager *m_itemdef = nullptr;
-       INodeDefManager *m_nodedef = nullptr;
+       const NodeDefManager *m_nodedef = nullptr;
        ICraftDefManager *m_craftdef = nullptr;
        ITextureSource *m_texturesrc = nullptr;
        IShaderSource *m_shadersrc = nullptr;
        ISoundManager *m_soundmgr = nullptr;
-       MtEventManager *m_eventmgr = nullptr;
        scene::ISceneManager *m_scenemgr = nullptr;
        IRollbackManager *m_rollbackmgr = nullptr;
        EmergeManager *m_emergemgr = nullptr;
+       std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
 };
 
 
-TestGameDef::TestGameDef()
+TestGameDef::TestGameDef() :
+       m_modchannel_mgr(new ModChannelMgr())
 {
        m_itemdef = createItemDefManager();
        m_nodedef = createNodeDefManager();
@@ -103,7 +113,7 @@ TestGameDef::~TestGameDef()
 void TestGameDef::defineSomeNodes()
 {
        IWritableItemDefManager *idef = (IWritableItemDefManager *)m_itemdef;
-       IWritableNodeDefManager *ndef = (IWritableNodeDefManager *)m_nodedef;
+       NodeDefManager *ndef = (NodeDefManager *)m_nodedef;
 
        ItemDefinition itemdef;
        ContentFeatures f;
@@ -222,14 +232,31 @@ void TestGameDef::defineSomeNodes()
        t_CONTENT_BRICK = ndef->set(f.name, f);
 }
 
+bool TestGameDef::joinModChannel(const std::string &channel)
+{
+       return m_modchannel_mgr->joinChannel(channel, PEER_ID_SERVER);
+}
+
+bool TestGameDef::leaveModChannel(const std::string &channel)
+{
+       return m_modchannel_mgr->leaveChannel(channel, PEER_ID_SERVER);
+}
+
+bool TestGameDef::sendModChannelMessage(const std::string &channel,
+       const std::string &message)
+{
+       if (!m_modchannel_mgr->channelRegistered(channel))
+               return false;
+
+       return true;
+}
+
 ////
 //// run_tests
 ////
 
 bool run_tests()
 {
-       DSTACK(FUNCTION_NAME);
-
        u64 t1 = porting::getTimeMs();
        TestGameDef gamedef;
 
@@ -297,7 +324,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))
@@ -309,7 +336,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";
 }
@@ -623,12 +650,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