Re: Target setup for unit testing (using cppunit)
Re: Target setup for unit testing (using cppunit)
- Subject: Re: Target setup for unit testing (using cppunit)
- From: Stefan van den Oord <email@hidden>
- Date: Mon, 28 Nov 2005 11:24:57 +0100
Just another note for others who may be reading this thread:
Instead of linking my testlib using '-lTestLib', I now use dlopen() to
load the library at run-time, when the --test argument is specified. I
pass the name of the dylib to load as a command line paramater,
because on Linux it is different (.so instead of .dylib).
Code snippit:
/* Type definition of the test function that is called */
typedef int (*mainTest)(int argc, char *argv[]);
/* Main function */
int main (int argc, char *argv[])
{
/* If the first argument is "--test" */
if (argc >= 2 && strcmp(argv[1],"--test")==0)
{
/* The lib we'll load is the second command line argument */
if (argc < 3)
{
printf("Error: supply test dynamic library as second parameter on
command line\n");
return -1;
}
const char *lib = argv[2];
/* Open the library */
void *handle = NULL;
handle = dlopen(lib, RTLD_LAZY);
if (handle == NULL)
{
printf("Could not dlopen() library: %s\n", dlerror());
return -2;
}
/* Load the mainTest symbol */
void* mainTestFunc = dlsym(handle, "mainTest");
if (mainTestFunc == NULL) {
printf("Symbol %s not found!\n", "mainTest");
}
/* Run the test */
return ((mainTest)mainTestFunc)(argc, argv);
}
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden