Skip to content

Instantly share code, notes, and snippets.

@drewpts
Created May 31, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewpts/4947d6f2f93f62a72924 to your computer and use it in GitHub Desktop.
Save drewpts/4947d6f2f93f62a72924 to your computer and use it in GitHub Desktop.
find subprojects by path
virtual FileSetLoader * findSubprojectByPath(const Path&) const = 0;
////////////////////////////////
/*!
* \brief This function performs searching existing subproject loader by path to
* subproject
* \param[in] std::string with path to subproject
* \return loader of subproject
*/
/*virtual*/ FileSetLoader * findSubprojectByPath(const FileSetLoader::Path & path) const;
FileSetLoader *
JsonFileSetLoader::findSubprojectByPath(const std::string &path) const
{
for (auto it = subprojects.cbegin(); it != subprojects.cend(); ++it)
{
if (it->second->getPathToNode() == path)
return it->second;
}
throw FileSetRuntimeError(FileSetRuntimeError::SubprojectsIncongruity, "Subproject not found by path search");
}
////////////////////////
class TestFindSubprojectByPath : public TestSkeleton {
public:
FileSetLoader::Path pathToProjectWithOneNormalSubprojects = R"(project_files/getsubprojectspaths/getpath.libproject)";
FileSetLoader::Path pathToProjectWithPairNormalSubprojects = R"(project_files/getsubprojectspaths/getpaths.libproject)";
FileSetLoader::Path pathToProjectWithoutSubprojects = R"(project_files/getsubprojectspaths/nosubprojects.libproject)";
FileSetLoader::Path pathToOneSubproject = "";
FileSetLoader::Path pathToAnotherSubproject = "";
FileSetLoader::Path pathToNonExistentSubproject = "";
};
TEST_F(TestFindSubprojectByPath, FindInProjectWithTwoSubprojects) {
ASSERT_NO_THROW({
loader = LoaderPtr(FileSetFactory::createFileSet(pathToProjectWithPairNormalSubprojects));
loader->open;
loader->findSubprojectByPath;
});
loader->save();
ifstream i(pathToMainFileWhichWillNotBeLoaded);
fileToTest << i;
ASSERT_EQ(contentReference_withTwoSuprojects.dump(4), fileToTest.dump(4));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment