apps: lc-compliance: Use std::vector for argument array

Just use an `std::vector` to store the arguments passed to
`InitGoogleTest()`. This removes the need for the map and
the separate `argc` variable used for size-keeping.

Signed-off-by: Barnabás Pőcze <pobrn@protonmail.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Barnabás Pőcze 2024-12-19 18:27:01 +01:00
parent 1f02966f3f
commit 5c3eb98374

View file

@ -80,45 +80,27 @@ static int initCamera(CameraManager *cm, OptionsParser::Options options)
static int initGtestParameters(char *arg0, OptionsParser::Options options) static int initGtestParameters(char *arg0, OptionsParser::Options options)
{ {
const std::map<std::string, std::string> gtestFlags = { { "list", "--gtest_list_tests" }, std::vector<const char *> argv;
{ "filter", "--gtest_filter" } };
int argc = 0;
std::string filterParam; std::string filterParam;
/* argv.push_back(arg0);
* +2 to have space for both the 0th argument that is needed but not
* used and the null at the end.
*/
char **argv = new char *[(gtestFlags.size() + 2)];
if (!argv)
return -ENOMEM;
argv[0] = arg0; if (options.isSet(OptList))
argc++; argv.push_back("--gtest_list_tests");
if (options.isSet(OptList)) {
argv[argc] = const_cast<char *>(gtestFlags.at("list").c_str());
argc++;
}
if (options.isSet(OptFilter)) { if (options.isSet(OptFilter)) {
/* /*
* The filter flag needs to be passed as a single parameter, in * The filter flag needs to be passed as a single parameter, in
* the format --gtest_filter=filterStr * the format --gtest_filter=filterStr
*/ */
filterParam = gtestFlags.at("filter") + "=" + filterParam = "--gtest_filter=" + options[OptFilter].toString();
static_cast<const std::string &>(options[OptFilter]); argv.push_back(filterParam.c_str());
argv[argc] = const_cast<char *>(filterParam.c_str());
argc++;
} }
argv[argc] = nullptr; argv.push_back(nullptr);
::testing::InitGoogleTest(&argc, argv); int argc = argv.size();
::testing::InitGoogleTest(&argc, const_cast<char **>(argv.data()));
delete[] argv;
return 0; return 0;
} }