1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
#include "RadiantTest.h"
#include <fstream>
#include "ieclass.h"
#include "icolourscheme.h"
#include "ientity.h"
#include "imap.h"
#include "ibrush.h"
#include "ifilesystem.h"
#include "iselection.h"
#include "scenelib.h"
namespace test
{
// Test context setting up a temporary game folder
class Quake4TestContext :
public radiant::TestContext
{
private:
std::string _projectFolder;
public:
Quake4TestContext()
{
// Set up the temporary settings folder
_projectFolder = (os::getTemporaryPath() / "empty_q4_project/").string();
os::removeDirectory(_projectFolder);
os::makeDirectory(_projectFolder);
}
virtual ~Quake4TestContext()
{
if (!_projectFolder.empty())
{
os::removeDirectory(_projectFolder);
}
}
virtual std::string getTestProjectPath() const override
{
return os::standardPathWithSlash(_projectFolder);
}
};
// Test setup using an empty Q4 project config
// containing just an empty Quake4.exe and a q4base/ folder
class EmptyQuake4Setup :
public RadiantTest
{
private:
Quake4TestContext _context;
public:
protected:
virtual void setupGameFolder() override
{
RadiantTest::setupGameFolder();
// Create the q4base folder
os::makeDirectory(_context.getTestProjectPath() + "q4base");
std::ofstream outfile(_context.getTestProjectPath() + "Quake4.exe");
outfile << " " << std::endl;
outfile.close();
}
virtual void handleGameConfigMessage(game::ConfigurationNeeded& message) override
{
game::GameConfiguration config;
config.gameType = "Quake 4";
config.enginePath = _context.getTestProjectPath();
message.setConfig(config);
message.setHandled(true);
}
};
using Quake4WorldspawnColourTest = EmptyQuake4Setup;
TEST_F(Quake4WorldspawnColourTest, SchemeBrushColourIsUsed)
{
// File system should be loaded and ready
EXPECT_TRUE(GlobalFileSystem().isInitialised());
// This setup doesn't have a worldspawn
EXPECT_FALSE(GlobalEntityClassManager().findClass("worldspawn"));
// Create a worldspawn
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
// The eclass wire shader should match the colour defined in the scheme
const auto& schemeColour = GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
}
TEST_F(RadiantTest, SchemeBrushColourIsUsed)
{
// This setup does have a worldspawn
EXPECT_TRUE(GlobalEntityClassManager().findOrInsert("worldspawn", true));
// Create a worldspawn
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
// The eclass wire shader should match the colour defined in the scheme
const auto& schemeColour = GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
}
TEST_F(RadiantTest, SchemeBrushColourChange)
{
// Create a worldspawn
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
// The eclass wire shader should match the colour defined in the scheme
auto schemeColour = GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
// Modify the brush colour
Vector3 changedColour(0.25, 0.9, 0.99);
GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour() = changedColour;
// This in itself doesn't affect the entity yet
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
// But calling saveColourSchemes should update the wire shader
GlobalColourSchemeManager().saveColourSchemes();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(changedColour, 1));
}
TEST_F(RadiantTest, SchemeBrushColourRevert)
{
// Create a worldspawn
auto worldspawn = GlobalMapModule().findOrInsertWorldspawn();
// The eclass wire shader should match the colour defined in the scheme
auto schemeColour = GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
// Modify the brush colour
Vector3 changedColour(0.25, 0.9, 0.99);
GlobalColourSchemeManager().getActiveScheme().getColour("default_brush").getColour() = changedColour;
// This in itself doesn't affect the entity yet
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
// This should update the eclasses, but not save anything to the registry
GlobalColourSchemeManager().emitEclassOverrides();
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(changedColour, 1));
// Revert the colour schemes to the values in the registry
GlobalColourSchemeManager().restoreColourSchemes();
// We should be back at the theme colour we had before
EXPECT_EQ(Node_getEntity(worldspawn)->getEntityClass()->getColour(), Vector4(schemeColour, 1));
}
}
|