Cleanup sound manager class (#7158)
[oweals/minetest.git] / src / unittest / test.cpp
index 911b647f7cfe0d8640b097ed97e708a2952b1b64..18215a94749558164d1ce262d0a3526c84ef8bfe 100644 (file)
@@ -19,10 +19,13 @@ 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 "modchannels.h"
 #include "mods.h"
+#include "util/numeric.h"
 
 content_t t_CONTENT_STONE;
 content_t t_CONTENT_GRASS;
@@ -43,7 +46,7 @@ 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; }
@@ -68,10 +71,17 @@ 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;
@@ -80,10 +90,12 @@ private:
        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();
@@ -102,7 +114,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;
@@ -119,8 +131,8 @@ void TestGameDef::defineSomeNodes()
                "{default_stone.png";
        f = ContentFeatures();
        f.name = itemdef.name;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_stone.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_stone.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        t_CONTENT_STONE = ndef->set(f.name, f);
@@ -174,8 +186,8 @@ void TestGameDef::defineSomeNodes()
        f.liquid_viscosity = 4;
        f.is_ground_content = true;
        f.groups["liquids"] = 3;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_water.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_water.png";
        idef->registerItem(itemdef);
        t_CONTENT_WATER = ndef->set(f.name, f);
 
@@ -196,8 +208,8 @@ void TestGameDef::defineSomeNodes()
        f.light_source = LIGHT_MAX-1;
        f.is_ground_content = true;
        f.groups["liquids"] = 3;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_lava.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_lava.png";
        idef->registerItem(itemdef);
        t_CONTENT_LAVA = ndef->set(f.name, f);
 
@@ -214,21 +226,38 @@ void TestGameDef::defineSomeNodes()
                "{default_brick.png";
        f = ContentFeatures();
        f.name = itemdef.name;
-       for(int i = 0; i < 6; i++)
-               f.tiledef[i].name = "default_brick.png";
+       for (TileDef &tiledef : f.tiledef)
+               tiledef.name = "default_brick.png";
        f.is_ground_content = true;
        idef->registerItem(itemdef);
        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;