Skip to content

Commit

Permalink
#6162: Add basic unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Nov 14, 2022
1 parent 0944ba7 commit 45a2e21
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
2 changes: 1 addition & 1 deletion include/modelskin.h
Expand Up @@ -34,7 +34,7 @@ class ISkin :
virtual std::string getRemap(const std::string& name) = 0;

// Returns the list of models this skin applies to
virtual std::set<std::string> getModels() = 0;
virtual const std::set<std::string>& getModels() = 0;

// The list of all remappings defined in this skin
virtual const std::vector<Remapping>& getAllRemappings() = 0;
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/skins/Doom3ModelSkin.cpp
Expand Up @@ -17,7 +17,7 @@ std::string Skin::getSkinFileName() const
return getDeclFilePath();
}

std::set<std::string> Skin::getModels()
const std::set<std::string>& Skin::getModels()
{
ensureParsed();

Expand Down
2 changes: 1 addition & 1 deletion radiantcore/skins/Doom3ModelSkin.h
Expand Up @@ -30,7 +30,7 @@ class Skin :

std::string getSkinFileName() const;

std::set<std::string> getModels() override;
const std::set<std::string>& getModels() override;
const std::vector<Remapping>& getAllRemappings() override;

// Get this skin's remap for the provided material name (if any).
Expand Down
39 changes: 39 additions & 0 deletions test/Skin.cpp
Expand Up @@ -46,6 +46,45 @@ TEST_F(ModelSkinTest, FindSkinsIsCaseInsensitive)
EXPECT_EQ(tileSkin->getRemap("textures/atest/a"), "textures/numbers/10");
}

inline bool containsRemap(const std::vector<decl::ISkin::Remapping>& remaps,
const std::string& original, const std::string& replacement)
{
for (const auto& remap : remaps)
{
if (remap.Original == original && remap.Replacement == replacement)
{
return true;
}
}

return false;
}

TEST_F(ModelSkinTest, GetAllRemaps)
{
auto skin = GlobalModelSkinCache().findSkin("skin_with_wildcard");

const auto& remaps = skin->getAllRemappings();

EXPECT_EQ(remaps.size(), 2);
EXPECT_TRUE(containsRemap(remaps, "textures/common/caulk", "textures/common/shadowcaulk"));
EXPECT_TRUE(containsRemap(remaps, "*", "textures/common/nodraw"));
}

TEST_F(ModelSkinTest, GetModels)
{
// Skin without any models listed
auto skin = GlobalModelSkinCache().findSkin("skin_with_wildcard");
EXPECT_EQ(skin->getModels().size(), 0);

// Skin with 2 models
skin = GlobalModelSkinCache().findSkin("separated_tile_skin");
const auto& models = skin->getModels();
EXPECT_EQ(models.size(), 2);
EXPECT_TRUE(models.count("models/ase/separated_tiles.ase"), 1);
EXPECT_TRUE(models.count("models/ase/separated_tiles22.ase"), 1);
}

TEST_F(ModelSkinTest, GetRemap)
{
auto tileSkin = GlobalModelSkinCache().findSkin("tile_skin2");
Expand Down
1 change: 1 addition & 0 deletions test/resources/tdm/skins/test_skins.skin
Expand Up @@ -19,6 +19,7 @@ tile_skin2
separated_tile_skin
{
model "models/ase/separated_tiles.ase"
model "models/ase/separated_tiles22.ase"

material textures/numbers/11
textures/numbers/1 textures/numbers/11
Expand Down

0 comments on commit 45a2e21

Please sign in to comment.