| 271 | } |
| 272 | |
| 273 | inline 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 |
| 311 | TEST_F(ParticlesTest, SaveNewParticleToNewFile) |
no test coverage detected