Added a test program for loadso subsystem. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Tue, 07 Nov 2006 14:31:25 +0000
branchSDL-1.2
changeset 3892b25dd008167b
parent 3891 2b5c30359c1d
child 3893 f1699aecb65d
Added a test program for loadso subsystem.
test/Makefile.in
test/testloadso.c
     1.1 --- a/test/Makefile.in	Tue Nov 07 14:06:25 2006 +0000
     1.2 +++ b/test/Makefile.in	Tue Nov 07 14:31:25 2006 +0000
     1.3 @@ -7,7 +7,7 @@
     1.4  CFLAGS  = @CFLAGS@
     1.5  LIBS	= @LIBS@
     1.6  
     1.7 -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE)
     1.8 +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcdrom$(EXE) testcursor$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testgamma$(EXE) testgl$(EXE) testhread$(EXE) testiconv$(EXE) testjoystick$(EXE) testkeys$(EXE) testlock$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testsem$(EXE) testsprite$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) testloadso$(EXE)
     1.9  
    1.10  all: $(TARGETS)
    1.11  
    1.12 @@ -104,6 +104,9 @@
    1.13  torturethread$(EXE): $(srcdir)/torturethread.c
    1.14  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.15  
    1.16 +testloadso$(EXE): $(srcdir)/testloadso.c
    1.17 +	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    1.18 +
    1.19  
    1.20  clean:
    1.21  	rm -f $(TARGETS)
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/testloadso.c	Tue Nov 07 14:31:25 2006 +0000
     2.3 @@ -0,0 +1,70 @@
     2.4 +
     2.5 +/* Test program to test dynamic loading with the loadso subsystem. 
     2.6 +*/
     2.7 +
     2.8 +#include <stdio.h>
     2.9 +#include <stdlib.h>
    2.10 +
    2.11 +#include "SDL.h"
    2.12 +
    2.13 +typedef int (*fntype)(const char *);
    2.14 +
    2.15 +int main(int argc, char *argv[])
    2.16 +{
    2.17 +	int retval = 0;
    2.18 +	int hello = 0;
    2.19 +	const char *libname = NULL;
    2.20 +	const char *symname = NULL;
    2.21 +	void *lib = NULL;
    2.22 +	fntype fn = NULL;
    2.23 +
    2.24 +	if (argc != 3) {
    2.25 +		fprintf(stderr, "USAGE: %s <library> <functionname>\n");
    2.26 +		fprintf(stderr, "       %s --hello <library with puts()>\n");
    2.27 +		return 1;
    2.28 +	}
    2.29 +
    2.30 +	/* Initialize SDL */
    2.31 +	if ( SDL_Init(0) < 0 ) {
    2.32 +		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
    2.33 +		return 2;
    2.34 +	}
    2.35 +
    2.36 +	if (strcmp(argv[1], "--hello") == 0) {
    2.37 +		hello = 1;
    2.38 +		libname = argv[2];
    2.39 +		symname = "puts";
    2.40 +	} else {
    2.41 +		libname = argv[1];
    2.42 +		symname = argv[2];
    2.43 +	}
    2.44 +
    2.45 +	lib = SDL_LoadObject(libname);
    2.46 +        if (lib == NULL) {
    2.47 +		fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n",
    2.48 +		        libname, SDL_GetError());
    2.49 +		retval = 3;
    2.50 +	} else {
    2.51 +		fn = (fntype) SDL_LoadFunction(lib, symname);
    2.52 +		if (fn == NULL) {
    2.53 +			fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n",
    2.54 +			        symname, SDL_GetError());
    2.55 +			retval = 4;
    2.56 +		} else {
    2.57 +			printf("Found %s in %s at %p\n", symname, libname);
    2.58 +			if (hello) {
    2.59 +				printf("Calling function...\n");
    2.60 +				fflush(stdout);
    2.61 +				fn("     HELLO, WORLD!\n");
    2.62 +				printf("...apparently, we survived.  :)\n");
    2.63 +				printf("Unloading library...\n");
    2.64 +				fflush(stdout);
    2.65 +			}
    2.66 +		}
    2.67 +		SDL_UnloadObject(lib);
    2.68 +	}
    2.69 +	SDL_Quit();
    2.70 +	return(0);
    2.71 +}
    2.72 +
    2.73 +