Skip to content

Commit

Permalink
#5977: Separate SoundManager tests from DefBlockTokeniser tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jun 26, 2022
1 parent 9063113 commit 93bf93f
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 17 deletions.
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Expand Up @@ -8,6 +8,7 @@ add_executable(drtest
ContinuousBuffer.cpp
CSG.cpp
DeclManager.cpp
DefBlockTokeniser.cpp
Entity.cpp
Favourites.cpp
FileTypes.cpp
Expand Down Expand Up @@ -41,6 +42,7 @@ add_executable(drtest
SelectionAlgorithm.cpp
Selection.cpp
Settings.cpp
SoundManager.cpp
TextureManipulation.cpp
TextureTool.cpp
Transformation.cpp
Expand Down
16 changes: 1 addition & 15 deletions test/Parsing.cpp → test/DefBlockTokeniser.cpp
@@ -1,6 +1,5 @@
#include "RadiantTest.h"
#include "gtest/gtest.h"

#include "isound.h"
#include "parser/DefBlockTokeniser.h"

namespace test
Expand Down Expand Up @@ -209,17 +208,4 @@ TEST(DefBlockTokeniser, WhitespaceAfterTypename)
});
}

using SoundShaderParsingTests = RadiantTest;

TEST_F(SoundShaderParsingTests, ShaderParsing)
{
// All of these shaders need to be parsed and present
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case1"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case2"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case3"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case4"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case5"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case6"));
}

}
57 changes: 57 additions & 0 deletions test/SoundManager.cpp
@@ -0,0 +1,57 @@
#include "RadiantTest.h"

#include "isound.h"

namespace test
{

using SoundManagerTest = RadiantTest;

TEST_F(SoundManagerTest, ShaderParsing)
{
// All of these shaders need to be parsed and present
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case1"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case2"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case3"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case4"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case5"));
EXPECT_TRUE(GlobalSoundManager().getSoundShader("parsing_test_case6"));
}

TEST_F(SoundManagerTest, GetExistingSoundShader)
{
// This shader is defined
auto existing = GlobalSoundManager().getSoundShader("parsing_test_case1");
EXPECT_TRUE(existing) << "Could not find parsing_test_case1 shader";

EXPECT_EQ(existing->getDeclName(), "parsing_test_case1");
EXPECT_EQ(existing->getModName(), "The Dark Mod 2.0 (Standalone)");
EXPECT_EQ(existing->getDeclType(), decl::Type::SoundShader);
EXPECT_EQ(existing->getDisplayFolder(), "ambient/environmental/city");
EXPECT_NEAR(existing->getRadii().getMin(true), 9, 0.01); // in meters
EXPECT_NEAR(existing->getRadii().getMax(true), 30, 0.01); // in meters
EXPECT_EQ(existing->getShaderFilePath(), "sound/parsing_test.sndshd");
auto fileList = existing->getSoundFileList();
EXPECT_EQ(fileList.size(), 2);
EXPECT_EQ(fileList.at(0), "sound/nonexistent.ogg");
EXPECT_EQ(fileList.at(1), "sound/nonexistent2.ogg");

EXPECT_NE(existing->getDefinition().find("maxDistance 30"), std::string::npos)
<< "Didn't find the expected contents";

EXPECT_NE(existing->getBlockSyntax().contents.find("maxDistance 30"), std::string::npos)
<< "Didn't find the expected contents";
}

TEST_F(SoundManagerTest, GetNonExistingSoundShader)
{
// This shader is defined nowhere
auto nonexisting = GlobalSoundManager().getSoundShader("nonexisting_shader_1242");
EXPECT_TRUE(nonexisting) << "SoundManager should always return a non-empty reference";
EXPECT_EQ(nonexisting->getBlockSyntax().fileInfo.visibility, vfs::Visibility::HIDDEN)
<< "Non-existing shader's VFS visibility should be hidden";
EXPECT_TRUE(nonexisting->getBlockSyntax().contents.empty())
<< "Non-existing shader's content should be empty";
}

}
1 change: 1 addition & 0 deletions test/resources/tdm/sound/parsing_test.sndshd
Expand Up @@ -10,6 +10,7 @@ parsing_test_case1
looping

sound/nonexistent.ogg
sound/nonexistent2.ogg
}

// Opening brace in the same line
Expand Down
3 changes: 2 additions & 1 deletion tools/msvc/Tests/Tests.vcxproj
Expand Up @@ -89,6 +89,7 @@
<ClCompile Include="..\..\..\test\ContinuousBuffer.cpp" />
<ClCompile Include="..\..\..\test\CSG.cpp" />
<ClCompile Include="..\..\..\test\DeclManager.cpp" />
<ClCompile Include="..\..\..\test\DefBlockTokeniser.cpp" />
<ClCompile Include="..\..\..\test\Entity.cpp" />
<ClCompile Include="..\..\..\test\EntityInspector.cpp" />
<ClCompile Include="..\..\..\test\Favourites.cpp" />
Expand All @@ -112,7 +113,6 @@
<ClCompile Include="..\..\..\test\ModelExport.cpp" />
<ClCompile Include="..\..\..\test\Models.cpp" />
<ClCompile Include="..\..\..\test\ModelScale.cpp" />
<ClCompile Include="..\..\..\test\Parsing.cpp" />
<ClCompile Include="..\..\..\test\Particles.cpp" />
<ClCompile Include="..\..\..\test\Patch.cpp" />
<ClCompile Include="..\..\..\test\PatchIterators.cpp" />
Expand All @@ -124,6 +124,7 @@
<ClCompile Include="..\..\..\test\Selection.cpp" />
<ClCompile Include="..\..\..\test\SelectionAlgorithm.cpp" />
<ClCompile Include="..\..\..\test\Settings.cpp" />
<ClCompile Include="..\..\..\test\SoundManager.cpp" />
<ClCompile Include="..\..\..\test\TextureManipulation.cpp" />
<ClCompile Include="..\..\..\test\TextureTool.cpp" />
<ClCompile Include="..\..\..\test\Transformation.cpp" />
Expand Down
3 changes: 2 additions & 1 deletion tools/msvc/Tests/Tests.vcxproj.filters
Expand Up @@ -32,7 +32,6 @@
<ClCompile Include="..\..\..\test\LayerManipulation.cpp" />
<ClCompile Include="..\..\..\test\Favourites.cpp" />
<ClCompile Include="..\..\..\test\Prefabs.cpp" />
<ClCompile Include="..\..\..\test\Parsing.cpp" />
<ClCompile Include="..\..\..\test\Entity.cpp" />
<ClCompile Include="..\..\..\test\Basic.cpp" />
<ClCompile Include="..\..\..\test\MaterialExport.cpp" />
Expand Down Expand Up @@ -60,6 +59,8 @@
<ClCompile Include="..\..\..\test\Settings.cpp" />
<ClCompile Include="..\..\..\test\Patch.cpp" />
<ClCompile Include="..\..\..\test\DeclManager.cpp" />
<ClCompile Include="..\..\..\test\SoundManager.cpp" />
<ClCompile Include="..\..\..\test\DefBlockTokeniser.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\test\HeadlessOpenGLContext.h" />
Expand Down

0 comments on commit 93bf93f

Please sign in to comment.