Skip to content

Commit

Permalink
#5361: Migrate the rest of the unit tests to gtest.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 25, 2020
1 parent 54c0347 commit 0a75b47
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 151 deletions.
4 changes: 4 additions & 0 deletions include/ishaders.h
Expand Up @@ -2,6 +2,7 @@

#include "iimage.h"
#include "imodule.h"
#include "ifilesystem.h"
#include <sigc++/signal.h>

#include "math/Vector3.h"
Expand Down Expand Up @@ -194,6 +195,9 @@ class Material
// get shader file name (ie the file where this one is defined)
virtual const char* getShaderFileName() const = 0;

// Returns the VFS info structure of the file this shader is defined in
virtual const vfs::FileInfo& getShaderFileInfo() const = 0;

/**
* \brief
* Return the requested sort position of this material.
Expand Down
37 changes: 0 additions & 37 deletions radiant/test/VFSFixture.h

This file was deleted.

104 changes: 0 additions & 104 deletions radiant/test/shadersTest.cpp

This file was deleted.

25 changes: 16 additions & 9 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -21,11 +21,11 @@ namespace shaders
/* Constructor. Sets the name and the ShaderDefinition to use.
*/
CShader::CShader(const std::string& name, const ShaderDefinition& definition) :
_template(definition.shaderTemplate),
_fileName(definition.file.name),
_name(name),
m_bInUse(false),
_visible(true)
_template(definition.shaderTemplate),
_fileInfo(definition.file),
_name(name),
m_bInUse(false),
_visible(true)
{
// Realise the shader
realise();
Expand Down Expand Up @@ -131,8 +131,9 @@ int CShader::getMaterialFlags() const
}

// test if it's a true shader, or a default shader created to wrap around a texture
bool CShader::IsDefault() const {
return _fileName.empty();
bool CShader::IsDefault() const
{
return _fileInfo.name.empty();
}

// get the cull type
Expand Down Expand Up @@ -177,8 +178,14 @@ Material::Coverage CShader::getCoverage() const
}

// get shader file name (ie the file where this one is defined)
const char* CShader::getShaderFileName() const {
return _fileName.c_str();
const char* CShader::getShaderFileName() const
{
return _fileInfo.name.c_str();
}

const vfs::FileInfo& CShader::getShaderFileInfo() const
{
return _fileInfo;
}

std::string CShader::getDefinition()
Expand Down
4 changes: 3 additions & 1 deletion radiantcore/shaders/CShader.h
Expand Up @@ -16,7 +16,7 @@ class CShader
ShaderTemplatePtr _template;

// The shader file name (i.e. the file where this one is defined)
std::string _fileName;
vfs::FileInfo _fileInfo;

// Name of shader
std::string _name;
Expand Down Expand Up @@ -98,6 +98,8 @@ class CShader
// get shader file name (ie the file where this one is defined)
const char* getShaderFileName() const;

const vfs::FileInfo& getShaderFileInfo() const override;

// Returns the description string of this material
std::string getDescription() const;

Expand Down
1 change: 1 addition & 0 deletions test/Makefile.am
Expand Up @@ -29,6 +29,7 @@ drtest_SOURCES = Camera.cpp \
HeadlessOpenGLContext.cpp \
Math.cpp \
FacePlane.cpp \
Materials.cpp \
ModelScale.cpp \
SelectionAlgorithm.cpp \
VFS.cpp
40 changes: 40 additions & 0 deletions test/Materials.cpp
@@ -0,0 +1,40 @@
#include "RadiantTest.h"

#include "ishaders.h"

namespace test
{

using MaterialsTest = RadiantTest;

TEST_F(MaterialsTest, MaterialFileInfo)
{
auto& materialManager = GlobalMaterialManager();

// Expect our example material definitions in the ShaderLibrary
EXPECT_TRUE(materialManager.materialExists("textures/orbweaver/drain_grille"));
EXPECT_TRUE(materialManager.materialExists("models/md5/chars/nobles/noblewoman/noblebottom"));
EXPECT_TRUE(materialManager.materialExists("tdm_spider_black"));

// ShaderDefinitions should contain their source file infos
const auto& drainGrille = materialManager.getMaterialForName("textures/orbweaver/drain_grille");
EXPECT_EQ(drainGrille->getShaderFileInfo().name, "example.mtr");
EXPECT_EQ(drainGrille->getShaderFileInfo().visibility, vfs::Visibility::NORMAL);

const auto& nobleTop = materialManager.getMaterialForName("models/md5/chars/nobles/noblewoman/nobletop");
EXPECT_EQ(nobleTop->getShaderFileInfo().name, "tdm_ai_nobles.mtr");
EXPECT_EQ(nobleTop->getShaderFileInfo().visibility, vfs::Visibility::NORMAL);

// Visibility should be parsed from assets.lst
const auto& hiddenTex = materialManager.getMaterialForName("textures/orbweaver/drain_grille_h");
EXPECT_EQ(hiddenTex->getShaderFileInfo().name, "hidden.mtr");
EXPECT_EQ(hiddenTex->getShaderFileInfo().visibility, vfs::Visibility::HIDDEN);

// assets.lst visibility applies to the MTR file, and should propagate to
// all shaders within it
const auto& hiddenTex2 = materialManager.getMaterialForName("textures/darkmod/another_white");
EXPECT_EQ(hiddenTex2->getShaderFileInfo().name, "hidden.mtr");
EXPECT_EQ(hiddenTex2->getShaderFileInfo().visibility, vfs::Visibility::HIDDEN);
}

}
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -65,6 +65,7 @@
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\FacePlane.cpp" />
<ClCompile Include="..\..\..\test\HeadlessOpenGLContext.cpp" />
<ClCompile Include="..\..\..\test\Materials.cpp" />
<ClCompile Include="..\..\..\test\Math.cpp" />
<ClCompile Include="..\..\..\test\ModelScale.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
Expand Down
1 change: 1 addition & 0 deletions tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -9,6 +9,7 @@
<ClCompile Include="..\..\..\test\Math.cpp" />
<ClCompile Include="..\..\..\test\FacePlane.cpp" />
<ClCompile Include="..\..\..\test\VFS.cpp" />
<ClCompile Include="..\..\..\test\Materials.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 0a75b47

Please sign in to comment.