Mercurial > sdl-ios-xcode
annotate test/testloadso.c @ 2067:dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 07 Nov 2006 14:36:47 +0000 |
parents | |
children | f16a7d02a176 |
rev | line source |
---|---|
2067
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 /* Test program to test dynamic loading with the loadso subsystem. |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 */ |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 #include "SDL.h" |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 typedef int (*fntype)(const char *); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 int main(int argc, char *argv[]) |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 int retval = 0; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 int hello = 0; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 const char *libname = NULL; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 const char *symname = NULL; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 void *lib = NULL; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
19 fntype fn = NULL; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
21 if (argc != 3) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
22 fprintf(stderr, "USAGE: %s <library> <functionname>\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 fprintf(stderr, " %s --hello <library with puts()>\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
24 return 1; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
25 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
26 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
27 /* Initialize SDL */ |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 if ( SDL_Init(0) < 0 ) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
30 return 2; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
31 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
32 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
33 if (strcmp(argv[1], "--hello") == 0) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 hello = 1; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 libname = argv[2]; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 symname = "puts"; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 } else { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
38 libname = argv[1]; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 symname = argv[2]; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
41 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 lib = SDL_LoadObject(libname); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 if (lib == NULL) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 fprintf(stderr, "SDL_LoadObject('%s') failed: %s\n", |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 libname, SDL_GetError()); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 retval = 3; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 } else { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 fn = (fntype) SDL_LoadFunction(lib, symname); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 if (fn == NULL) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 fprintf(stderr, "SDL_LoadFunction('%s') failed: %s\n", |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 symname, SDL_GetError()); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 retval = 4; |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 } else { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 printf("Found %s in %s at %p\n", symname, libname); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 if (hello) { |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 printf("Calling function...\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 fflush(stdout); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 fn(" HELLO, WORLD!\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 printf("...apparently, we survived. :)\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 printf("Unloading library...\n"); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 fflush(stdout); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 SDL_UnloadObject(lib); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
65 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 SDL_Quit(); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 return(0); |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 } |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
69 |
dcdb175c2829
Merged r2899:2900 from SDL-1.2 branch to trunk: testloadso program.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 |