diff options
author | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-08-30 16:53:58 -0700 |
commit | 6aaedb813fa11ba0679c3051bc2eb28646b9506c (patch) | |
tree | 34acbfc9840e02cb4753e6306ea7ce978bf8b58e /src/contrib/SDL-3.2.20/test/testloadso.c | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testloadso.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testloadso.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testloadso.c b/src/contrib/SDL-3.2.20/test/testloadso.c new file mode 100644 index 0000000..106fbc7 --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testloadso.c | |||
@@ -0,0 +1,112 @@ | |||
1 | /* | ||
2 | Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org> | ||
3 | |||
4 | This software is provided 'as-is', without any express or implied | ||
5 | warranty. In no event will the authors be held liable for any damages | ||
6 | arising from the use of this software. | ||
7 | |||
8 | Permission is granted to anyone to use this software for any purpose, | ||
9 | including commercial applications, and to alter it and redistribute it | ||
10 | freely. | ||
11 | */ | ||
12 | |||
13 | /* Test program to test dynamic loading with the loadso subsystem. | ||
14 | */ | ||
15 | |||
16 | #include <stdio.h> | ||
17 | |||
18 | #include <SDL3/SDL.h> | ||
19 | #include <SDL3/SDL_main.h> | ||
20 | #include <SDL3/SDL_test.h> | ||
21 | |||
22 | typedef int (*fntype)(const char *); | ||
23 | |||
24 | static void log_usage(char *progname, SDLTest_CommonState *state) { | ||
25 | static const char *options[] = { "library", "functionname|--hello", NULL }; | ||
26 | SDLTest_CommonLogUsage(state, progname, options); | ||
27 | SDL_Log("USAGE: %s <library> <functionname>", progname); | ||
28 | SDL_Log(" %s <lib with puts()> --hello", progname); | ||
29 | } | ||
30 | |||
31 | int main(int argc, char *argv[]) | ||
32 | { | ||
33 | int i; | ||
34 | int result = 0; | ||
35 | int hello = 0; | ||
36 | const char *libname = NULL; | ||
37 | const char *symname = NULL; | ||
38 | SDL_SharedObject *lib = NULL; | ||
39 | fntype fn = NULL; | ||
40 | SDLTest_CommonState *state; | ||
41 | |||
42 | /* Initialize test framework */ | ||
43 | state = SDLTest_CommonCreateState(argv, 0); | ||
44 | if (!state) { | ||
45 | return 1; | ||
46 | } | ||
47 | |||
48 | /* Parse commandline */ | ||
49 | for (i = 1; i < argc;) { | ||
50 | int consumed; | ||
51 | |||
52 | consumed = SDLTest_CommonArg(state, i); | ||
53 | if (!consumed) { | ||
54 | if (SDL_strcmp(argv[i], "--hello") == 0) { | ||
55 | if (!symname || SDL_strcmp(symname, "puts") == 0) { | ||
56 | symname = "puts"; | ||
57 | consumed = 1; | ||
58 | hello = 1; | ||
59 | } | ||
60 | } else if (!libname) { | ||
61 | libname = argv[i]; | ||
62 | consumed = 1; | ||
63 | } else if (!symname) { | ||
64 | symname = argv[i]; | ||
65 | consumed = 1; | ||
66 | } | ||
67 | } | ||
68 | if (consumed <= 0) { | ||
69 | log_usage(argv[0], state); | ||
70 | return 1; | ||
71 | } | ||
72 | |||
73 | i += consumed; | ||
74 | } | ||
75 | |||
76 | if (!libname || !symname) { | ||
77 | log_usage(argv[0], state); | ||
78 | return 1; | ||
79 | } | ||
80 | |||
81 | /* Initialize SDL */ | ||
82 | if (!SDL_Init(0)) { | ||
83 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError()); | ||
84 | return 2; | ||
85 | } | ||
86 | |||
87 | lib = SDL_LoadObject(libname); | ||
88 | if (!lib) { | ||
89 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s", | ||
90 | libname, SDL_GetError()); | ||
91 | result = 3; | ||
92 | } else { | ||
93 | fn = (fntype)SDL_LoadFunction(lib, symname); | ||
94 | if (!fn) { | ||
95 | SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s", | ||
96 | symname, SDL_GetError()); | ||
97 | result = 4; | ||
98 | } else { | ||
99 | SDL_Log("Found %s in %s at %p", symname, libname, fn); | ||
100 | if (hello) { | ||
101 | SDL_Log("Calling function..."); | ||
102 | fn(" HELLO, WORLD!\n"); | ||
103 | SDL_Log("...apparently, we survived. :)"); | ||
104 | SDL_Log("Unloading library..."); | ||
105 | } | ||
106 | } | ||
107 | SDL_UnloadObject(lib); | ||
108 | } | ||
109 | SDL_Quit(); | ||
110 | SDLTest_CommonDestroyState(state); | ||
111 | return result; | ||
112 | } | ||