MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / expectParticleIsPresentInFile

Function expectParticleIsPresentInFile

test/Particles.cpp:273–308  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273inline void expectParticleIsPresentInFile(const particles::IParticleDef::Ptr& decl, const std::string& path, bool expectPresent)
274{
275 auto contents = algorithm::loadTextFromVfsFile(path);
276
277 parser::DefBlockSyntaxParser<const std::string> parser(contents);
278 auto syntaxTree = parser.parse();
279
280 std::vector<parser::DefBlockSyntax::Ptr> foundBlocks;
281 auto particleName = string::to_lower_copy(decl->getDeclName());
282
283 syntaxTree->foreachBlock([&](const parser::DefBlockSyntax::Ptr& block)
284 {
285 auto blockContents = block->getBlockContents();
286
287 if (decl->getNumStages() > 0 &&
288 block->getType() && block->getType()->getString() == "particle" &&
289 block->getName() && block->getName()->getString() == particleName)
290 {
291 if (blockContents.find(decl->getStage(0)->getMaterialName()) == std::string::npos)
292 {
293 return;
294 }
295
296 foundBlocks.push_back(block);
297 }
298 });
299
300 if (expectPresent)
301 {
302 EXPECT_EQ(foundBlocks.size(), 1) << "Expected exactly one particle " << particleName << " in the contents in the file";
303 }
304 else
305 {
306 EXPECT_TRUE(foundBlocks.empty()) << "Expected no particle " << particleName << " in the contents in the file";
307 }
308}
309
310// Save a new particle to a file on disk
311TEST_F(ParticlesTest, SaveNewParticleToNewFile)

Callers 1

TEST_FFunction · 0.85

Calls 15

loadTextFromVfsFileFunction · 0.85
to_lower_copyFunction · 0.85
getDeclNameMethod · 0.80
foreachBlockMethod · 0.80
getBlockContentsMethod · 0.80
getStageMethod · 0.80
parseMethod · 0.45
getNumStagesMethod · 0.45
getTypeMethod · 0.45
getStringMethod · 0.45
getNameMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected