Skip to content

Commit

Permalink
Add unit tests for SAO load / unload behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed Mar 3, 2024
1 parent e2aa256 commit 50f3c72
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/script/scripting_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server.h"
#include "log.h"
#include "settings.h"
#include "filesys.h"
#include "cpp_api/s_internal.h"
#include "lua_api/l_areastore.h"
#include "lua_api/l_auth.h"
Expand Down Expand Up @@ -89,6 +90,12 @@ ServerScripting::ServerScripting(Server* server):
infostream << "SCRIPTAPI: Initialized game modules" << std::endl;
}

void ServerScripting::loadBuiltin()
{
loadMod(Server::getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
checkSetByBuiltin();
}

void ServerScripting::saveGlobals()
{
SCRIPTAPI_PRECHECKHEADER
Expand Down
1 change: 1 addition & 0 deletions src/script/scripting_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ServerScripting:
public:
ServerScripting(Server* server);

void loadBuiltin();
// use ScriptApiBase::loadMod() to load mods

// Save globals that are copied into other Lua envs
Expand Down
3 changes: 1 addition & 2 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,7 @@ void Server::init()
// Must be created before mod loading because we have some inventory creation
m_inventory_mgr = std::make_unique<ServerInventoryManager>();

m_script->loadMod(getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
m_script->checkSetByBuiltin();
m_script->loadBuiltin();

m_gamespec.checkAndLog();
m_modmgr->loadMods(m_script);
Expand Down
3 changes: 2 additions & 1 deletion src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,8 @@ void ServerEnvironment::step(float dtime)
}

// Send outdated detached inventories
m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true);
if (!m_players.empty())
m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true);

// Notify mods of modified mapblocks
if (m_on_mapblocks_changed_receiver.receiving &&
Expand Down
1 change: 1 addition & 0 deletions src/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set (UNITTEST_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/test_objdef.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_profiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_random.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_sao.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_schematic.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_serialization.cpp
${CMAKE_CURRENT_SOURCE_DIR}/test_serveractiveobjectmgr.cpp
Expand Down
5 changes: 4 additions & 1 deletion src/unittest/mock_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <server.h>
#include "server.h"

class MockServer : public Server
{
Expand All @@ -29,6 +29,9 @@ class MockServer : public Server
)
{}

void start() = delete;
void stop() = delete;

private:
void SendChatMessage(session_t peer_id, const ChatMessage &message) {}
};
4 changes: 1 addition & 3 deletions src/unittest/test_moveaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "mock_inventorymanager.h"
#include "mock_server.h"
#include "mock_serveractiveobject.h"

#include "scripting_server.h"


class TestMoveAction : public TestBase
{
public:
Expand Down Expand Up @@ -74,7 +72,7 @@ void TestMoveAction::runTests(IGameDef *gamedef)

ServerScripting server_scripting(&server);
try {
server_scripting.loadMod(Server::getBuiltinLuaPath() + DIR_DELIM "init.lua", BUILTIN_MOD_NAME);
server_scripting.loadBuiltin();
server_scripting.loadMod(helper_lua, BUILTIN_MOD_NAME);
} catch (ModError &e) {
// Print backtrace in case of syntax errors
Expand Down

0 comments on commit 50f3c72

Please sign in to comment.