Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zpl-zak committed Feb 4, 2024
2 parents d98cbce + 4cdd897 commit 3c7de24
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
18 changes: 18 additions & 0 deletions code/framework/src/scripting/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ namespace Framework::Scripting {

default: break;
}

// Make sure we got a valid pointer
if (!_engine) {
return ModuleError::MODULE_ENGINE_NULL;
}

_engine->SetModName(_modName);

_engineType = engineType;
Expand Down Expand Up @@ -73,6 +79,12 @@ namespace Framework::Scripting {
}

bool Module::LoadGamemode() const {
// Make sure there is an engine
if (!_engine) {
return false;
}

// Load the gamemode
const cppfs::FileHandle dir = cppfs::fs::open("gamemode");
if (!dir.exists() || !dir.isDirectory()) {
Logging::GetLogger(FRAMEWORK_INNER_SCRIPTING)->error("Failed to find the gamemode directory");
Expand All @@ -83,6 +95,12 @@ namespace Framework::Scripting {
}

bool Module::UnloadGamemode() const {
// Make sure there is an engine
if (!_engine) {
return false;
}

// Unload the gamemode
return _engine->UnloadGamemode("gamemode");
}
} // namespace Framework::Scripting
4 changes: 2 additions & 2 deletions code/tests/framework_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

/* TEST CATEGORIES */
#include "modules/interpolator_ut.h"
#include "modules/scripting_engine_ut.h"
#include "modules/scripting_module_ut.h"

int main() {
UNIT_CREATE("FrameworkTests");

Framework::Logging::GetInstance()->PauseLogging(true);

UNIT_MODULE(interpolator);
UNIT_MODULE(scripting_engine);
UNIT_MODULE(scripting_module);

return UNIT_RUN();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,33 @@
#include "scripting/engines/node/engine.h"
#include "scripting/module.h"

MODULE(scripting_engine, {
MODULE(scripting_module, {
using namespace Framework::Scripting;

IT("should not allow to initialize the engine with an invalid type", {
Module *pEngine = new Module;
EQUALS(pEngine->Init(static_cast<EngineTypes>(-1), NULL), ModuleError::MODULE_ENGINE_NULL);
delete pEngine;
});

IT("should not allow to shutdown if the engine is not initialized", {
Module *pEngine = new Module;
EQUALS(pEngine->Shutdown(), ModuleError::MODULE_ENGINE_NULL);
delete pEngine;
});

IT("should not allow to load gamemode if the engine is not initialized", {
Module *pEngine = new Module;
EQUALS(pEngine->LoadGamemode(), false);
delete pEngine;
});

IT("should not allow to unload gamemode if the engine is not initialized", {
Module *pEngine = new Module;
EQUALS(pEngine->UnloadGamemode(), false);
delete pEngine;
});

IT("can allocate and deallocate a valid scripting engine instance", {
Module *pEngine = new Module;

Expand Down

0 comments on commit 3c7de24

Please sign in to comment.