Skip to content

Commit

Permalink
#5977: Add a variant unit test checking that the skins reloaded signa…
Browse files Browse the repository at this point in the history
…l is the one causing models to update their skin remaps
  • Loading branch information
codereader committed Jul 8, 2022
1 parent 3005c71 commit ddbb5dc
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/Skin.cpp
Expand Up @@ -133,4 +133,49 @@ skin temporary_skin
EXPECT_EQ(activeMaterials.at(0), "textures/common/noclip");
}

// A slight variant of the above ReloadDeclsRefreshesModels: in this test the
// skin body is changed manually (similar to what happens during reloadDecls)
// and the declsReloaded signal is fired manually by the test code.
// This is to hide the dominant entityDefs-reloaded signal that is making
// the above test green without even without any skin signal listening code
TEST_F(ModelSkinTest, ReloadDeclsRefreshesModelsUsingSignal)
{
// Create a model and insert it into the scene
auto funcStaticClass = GlobalEntityClassManager().findClass("func_static");
auto funcStatic = GlobalEntityModule().createEntity(funcStaticClass);
scene::addNodeToContainer(funcStatic, GlobalMapModule().getRoot());

// Set model and skin spawnargs
funcStatic->getEntity().setKeyValue("model", "models/ase/tiles.ase");
funcStatic->getEntity().setKeyValue("skin", "tile_skin");

// Find the child model node
auto model = algorithm::findChildModel(funcStatic);
EXPECT_EQ(model->getIModel().getModelPath(), "models/ase/tiles.ase");

// Check the contents of the materials list
auto activeMaterials = model->getIModel().getActiveMaterials();
EXPECT_EQ(activeMaterials.size(), 1);
EXPECT_EQ(activeMaterials.at(0), "textures/numbers/10");

// Inject a new block syntax into the existing skin declaration
auto skin = GlobalModelSkinCache().findSkin("tile_skin");
decl::DeclarationBlockSyntax syntax;

syntax.name = skin->getDeclName();
syntax.typeName = "skin";
syntax.contents = R"(
model models/ase/tiles.ase
textures/atest/a textures/common/noclip
)";
skin->setBlockSyntax(syntax);

// Create an artificial skins-reloaded event
GlobalDeclarationManager().signal_DeclsReloaded(decl::Type::Skin).emit();

activeMaterials = model->getIModel().getActiveMaterials();
EXPECT_EQ(activeMaterials.size(), 1);
EXPECT_EQ(activeMaterials.at(0), "textures/common/noclip");
}

}

0 comments on commit ddbb5dc

Please sign in to comment.