gpt4 book ai didi

c++ - 更新到 CppUnit 1.12 时如何从 CppUnit 1.9 替换过时的 getRegistryList()?

转载 作者:行者123 更新时间:2023-11-30 04:29:04 27 4
gpt4 key购买 nike

我正在移植包含大量基于 CppUnit 1.9.11 左右的测试套件的代码。我的测试运行器可以使用这个(已弃用?)成语打印所有命名的测试套件:

cout << "\n Usage: UnitTest testSuiteName ...\n\n";
cout << " Tests available: \n";
CppUnit::TestFactoryRegistry registry("All Tests");
CppUnit::Test* test = registry.getRegistry().makeTest();
CppUnit::Registries registryList = registry.getRegistryList();
CppUnit::Registries::iterator it;
for (it = registryList.begin(); it != registryList.end(); ++it)
{
cout << " - " << it->first << endl;
}

显然 CppUnit 1.12 中不存在 getRegistryList()。是否有等效的习语来获取所有已注册的命名测试套件?

最佳答案

回答我自己的问题:

cout << "\n Usage: UnitTest TestNames\n\n";
cout << " Tests available: \n";

CppUnit::TestFactoryRegistry &registry =
CppUnit::TestFactoryRegistry::getRegistry(); // "All Tests"
CppUnit::Test *test = registry.makeTest();
CppUnit::TestSuite *s = dynamic_cast<CppUnit::TestSuite*>(test);
if (!s) {
cerr << "can't get TestSuite" << endl;
} else {
typedef CppUnitVector<CppUnit::Test *> container_type;
const container_type &tests( s->getTests() );
container_type::const_iterator ii;
for (ii=tests.begin(); ii != tests.end(); ++ii) {
const CppUnit::Test *t = (*ii);
cout << " - " << t->getName() << endl;
}
}

关于c++ - 更新到 CppUnit 1.12 时如何从 CppUnit 1.9 替换过时的 getRegistryList()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9675358/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com