Having done this the first part of my unit test was to get a url of a PNG in the bundle:
CFURLRef png1 = ::CFBundleCopyResourceURL(
CFBundleGetMainBundle(),
CFSTR("DWCGImageSource_100x100a.png"), NULL, NULL);
CPTAssert(png1);
This test failed immediately. It failed because URL of the main bundle when running the test is /Developer/Tools. Increasingly my calls to core foundation are lightly wrapped and CFBundleGetMainBundle() is a default parameter to my functions that get thr URLs of things relative to bundles. The solution I found was to add a #define _UNITTEST in the global defines and to write a new function to get the bundle.
I then use this GetMainBundle in the places where I used CFBundleGetMainBundle.
inline CFBundleRef GetMainBundle()
{
#if _UNITTEST
return ::CFBundleGetBundleWithIdentifier(
CFSTR("com.badbase.cello.unittest"));
#else
return CFBundleGetMainBundle();
#endif
}
No comments:
Post a Comment