[Cppunit-devel] Re: TestFactoryRegistry and Library
Brought to you by:
blep
From: Baptiste L. <gai...@fr...> - 2001-06-13 14:20:32
|
Quoting Baptiste Lepilleur <gai...@fr...>: This is a follow up to Michael Gerleck second question in the forum. > Quoting Michael Gerleck: > Well, it turns out I can't make use of the registry functionality > anyway: near > as I can tell, global ctor's in libraries aren't exported to the calling > > context under MSVC6. That is, > > - suite1.lib contains a bunch of testscases, all auotregister'd into > "Suite1" > > - main driver contains the line > masterSuite->addTest( CppUnit::TestFactoryRegistry::getRegistry > ("Suite1").makeTest() ); > > At runtime, the registry lookup doesn't find "Suite1", because the ctor > wasn't > linked in to the executable -- because there's no reference to it from > main. I'm don't what is the "Global constructor" you are refering to. The registry use a static variable: TestFactoryRegistry & TestFactoryRegistry::getRegistry() { static TestFactoryRegistry registry; <<< return registry; } To my knowlegde, the behavior you are observing is the normal behavior. Anyway, there are some simple workaround. Have your librairies publishing an interface that provide an access to their TestFactoryRegistry. For example, in suite1.lib project, you add: TestFactoryRegistry &getSuite1Registry() { return TestFactoryRegistry::getRegistry(); } Since this function is compiled within suite1.lib, it returns a reference to the registry used within suite1.lib. In the main driver you can then do: masterSuite->addTest( getSuite1Registry().getRegistry ("Suite1").makeTest() ); This should work (I haven't tried). An alternative that I find much cleaner would be to either publish the TestSuite, or provide an indirect access to the registry: class SuiteProvider { TestSuite *suite() { // Here you can play anyway you want with the registry, or create the // suite by hand if you don't want to use the registry. return TestFactoryRegistry::getRegistry().makeTest(); // or return new AllTestSuite(); } // or TestSuite *suiteFor( std::string name ) { return TestFactoryRegistry::getRegistry( name ).makeTest(); } }; Well, as you see much can be done. > > [Editorial: I suspect MSVC6 is broken here, because it only fails to > work when > Suite1 is in a separate library. Global ctors should always be > respected, no?] > > This is a pain, because I've got a lot of testcases and a lot of > libraries and > a lot of developers to deal with -- it would have been nice to have it > all just > magically work, without a lot of explicit includes and suite creation > calls. So > much for the magic of registries and factories; back to the drawing > board... I'd really like to know how the TestRunner react with so many suite... How many TestCase did you end up with ? > > I'll migrate over to the dev-list. > > -mpg --- Baptiste Lepilleur <gai...@fr...> http://gaiacrtn.free.fr/index.html Language: English, French |