testing: allow backends to register tests after main()

Backends are now allowed to create RegisterSyncSourceTest instances
with empty name. They will be ignored except that their init() method
will be called after main() and before the list of source tests is
used.

This can be used to create additional RegisterSyncSourceTest instances
at a time when the test of libsyncevolution is initialized. This is
needed by the WebDAV backend, which has to instantiate sources and use
the config system. That crashed when done before the ConfigProperty
instances were initialized.
This commit is contained in:
Patrick Ohly 2012-06-12 17:26:09 +02:00
parent c1a705169d
commit e749586310
2 changed files with 26 additions and 2 deletions

View File

@ -138,6 +138,16 @@ public:
m_initialized = true;
}
// allow each backend test to create more backend tests
size_t count = 0;
while (count != m_configs.size()) {
count = m_configs.size();
BOOST_FOREACH (const RegisterSyncSourceTest *test,
TestRegistry(m_configs)) {
test->init();
}
}
const char *server = getenv("CLIENT_TEST_SERVER");
if (m_clientID == "1") {
@ -169,12 +179,15 @@ public:
boost::split(sources, sourcelist, boost::is_any_of(","));
} else {
BOOST_FOREACH(const RegisterSyncSourceTest *test, m_configs) {
sources.insert(test->m_configName);
if (!test->m_configName.empty()) {
sources.insert(test->m_configName);
}
}
}
BOOST_FOREACH(const RegisterSyncSourceTest *test, m_configs) {
if (sources.find(test->m_configName) != sources.end()) {
if (sources.find(test->m_configName) != sources.end() &&
!test->m_configName.empty()) {
m_syncSource2Config.push_back(test->m_configName);
}
}
@ -213,6 +226,10 @@ public:
config->setDevID(m_clientID == "1" ? "sc-api-nat" : "sc-pim-ppc");
}
BOOST_FOREACH(const RegisterSyncSourceTest *test, m_configs) {
if (test->m_configName.empty()) {
continue;
}
ClientTest::Config testconfig;
getSourceConfig(test, testconfig);
CPPUNIT_ASSERT(!testconfig.m_type.empty());

View File

@ -538,6 +538,13 @@ struct ClientTestConfig {
class RegisterSyncSourceTest
{
public:
/**
* Invoked after all global constructors are run.
* May add further RegisterSyncSourceTests to the
* global registry.
*/
virtual void init() const {}
/**
* This call is invoked after setting up the config with default
* values for the test cases selected via the constructor's