Skip to content

Commit

Permalink
#5200: Working on getting the test environment to start up
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Aug 22, 2020
1 parent 35ea168 commit 874b0b2
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 8 deletions.
12 changes: 6 additions & 6 deletions libs/module/ApplicationContextBase.h
Expand Up @@ -32,12 +32,12 @@ class ApplicationContextBase :
virtual void initialise(int argc, char* argv[]);

/* ApplicationContext implementation */
std::string getApplicationPath() const override;
std::string getLibraryPath() const override;
std::string getRuntimeDataPath() const override;
std::string getHTMLPath() const override;
std::string getSettingsPath() const override;
std::string getBitmapsPath() const override;
virtual std::string getApplicationPath() const override;
virtual std::string getLibraryPath() const override;
virtual std::string getRuntimeDataPath() const override;
virtual std::string getHTMLPath() const override;
virtual std::string getSettingsPath() const override;
virtual std::string getBitmapsPath() const override;
const ArgumentList& getCmdLineArgs() const override;

const ErrorHandlingFunction& getErrorHandlingFunction() const override;
Expand Down
50 changes: 48 additions & 2 deletions test/RadiantTest.h
@@ -1,10 +1,15 @@
#pragma once

#include "gtest/gtest.h"
#include <sigc++/functors/mem_fun.h>
#include <iostream>

#include "module/ApplicationContextBase.h"
#include "imessagebus.h"
#include "iradiant.h"

#include "TestContext.h"
#include "module/CoreModule.h"
#include "messages/GameConfigNeededMessage.h"

/**
* Test fixture setting up the application context and
Expand All @@ -16,10 +21,12 @@ class RadiantTest :
protected:
// The RadiantApp owns the ApplicationContext which is then passed to the
// ModuleRegistry as a reference.
radiant::ApplicationContextBase _context;
radiant::TestContext _context;

std::unique_ptr<module::CoreModule> _coreModule;

std::size_t _gameSetupListener;

protected:
RadiantTest()
{
Expand All @@ -40,13 +47,52 @@ class RadiantTest :
// Streams are not yet initialised, so log to std::err at this point
std::cerr << ex.what() << std::endl;
}

// Set up the test game environment
setupGameFolder();

// Wire up the game-config-needed handler, we need to respond
_gameSetupListener = _coreModule->get()->getMessageBus().addListener(
radiant::IMessage::Type::GameConfigNeeded,
radiant::TypeListener<game::ConfigurationNeeded>(
sigc::mem_fun(this, &RadiantTest::handleGameConfigMessage)));

try
{
// Startup the application
_coreModule->get()->startup();
}
catch (const radiant::IRadiant::StartupFailure & ex)
{
// An unhandled exception during module initialisation => display a popup and exit
rError() << "Unhandled Exception: " << ex.what() << std::endl;
abort();
}
}

~RadiantTest()
{
_coreModule->get()->getMessageBus().removeListener(_gameSetupListener);

// Issue a shutdown() call to all the modules
module::GlobalModuleRegistry().shutdownModules();

_coreModule.reset();
}

private:
void setupGameFolder()
{

}

void handleGameConfigMessage(game::ConfigurationNeeded& message)
{
game::GameConfiguration config;

config.gameType = "The Dark Mod 2.0 (Standalone)";

message.setConfig(config);
message.setHandled(true);
}
};
37 changes: 37 additions & 0 deletions test/TestContext.h
@@ -0,0 +1,37 @@
#pragma once

#include "module/ApplicationContextBase.h"
#include "os/fs.h"
#include "os/dir.h"

namespace radiant
{

/**
* Application context implementation used in DarkRadiant's unit tests
*/
class TestContext :
public radiant::ApplicationContextBase
{
private:
std::string _settingsFolder;

public:
TestContext()
{
// Set up the temporary settings folder
auto settingsFolder = os::getTemporaryPath() / "dr_temp_settings";

_settingsFolder = settingsFolder.string();

os::removeDirectory(_settingsFolder);
os::makeDirectory(_settingsFolder);
}

std::string getSettingsPath() const override
{
return _settingsFolder;
}
};

}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -52,6 +52,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\RadiantTest.h" />
<ClInclude Include="..\..\..\test\TestContext.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\test\test.cpp" />
Expand Down

0 comments on commit 874b0b2

Please sign in to comment.