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/testlocale.c | |
parent | 8f228ade99dd3d4c8da9b78ade1815c9adf85c8f (diff) |
Update to SDL3
Diffstat (limited to 'src/contrib/SDL-3.2.20/test/testlocale.c')
-rw-r--r-- | src/contrib/SDL-3.2.20/test/testlocale.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/src/contrib/SDL-3.2.20/test/testlocale.c b/src/contrib/SDL-3.2.20/test/testlocale.c new file mode 100644 index 0000000..14083ad --- /dev/null +++ b/src/contrib/SDL-3.2.20/test/testlocale.c | |||
@@ -0,0 +1,101 @@ | |||
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 | #include <SDL3/SDL.h> | ||
13 | #include <SDL3/SDL_main.h> | ||
14 | #include <SDL3/SDL_test.h> | ||
15 | |||
16 | static void log_locales(void) | ||
17 | { | ||
18 | SDL_Locale **locales = SDL_GetPreferredLocales(NULL); | ||
19 | if (!locales) { | ||
20 | SDL_Log("Couldn't determine locales: %s", SDL_GetError()); | ||
21 | } else { | ||
22 | int i; | ||
23 | unsigned int total = 0; | ||
24 | SDL_Log("Locales, in order of preference:"); | ||
25 | for (i = 0; locales[i]; ++i) { | ||
26 | const SDL_Locale *l = locales[i]; | ||
27 | const char *c = l->country; | ||
28 | SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : ""); | ||
29 | total++; | ||
30 | } | ||
31 | SDL_Log("%u locales seen.", total); | ||
32 | SDL_free(locales); | ||
33 | } | ||
34 | } | ||
35 | |||
36 | int main(int argc, char **argv) | ||
37 | { | ||
38 | int i; | ||
39 | int listen = 0; | ||
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[1], "--listen") == 0) { | ||
55 | listen = 1; | ||
56 | consumed = 1; | ||
57 | state->flags |= SDL_INIT_VIDEO; | ||
58 | } | ||
59 | } | ||
60 | if (consumed <= 0) { | ||
61 | static const char *options[] = { "[--listen]", NULL }; | ||
62 | SDLTest_CommonLogUsage(state, argv[0], options); | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | i += consumed; | ||
67 | } | ||
68 | |||
69 | /* Print locales and languages */ | ||
70 | if (SDLTest_CommonInit(state) == false) { | ||
71 | return 1; | ||
72 | } | ||
73 | |||
74 | log_locales(); | ||
75 | |||
76 | if (listen) { | ||
77 | int done = 0; | ||
78 | while (!done) { | ||
79 | SDL_Event e; | ||
80 | SDLTest_CommonEvent(state, &e, &done); | ||
81 | while (SDL_PollEvent(&e)) { | ||
82 | if (e.type == SDL_EVENT_QUIT) { | ||
83 | done = 1; | ||
84 | } else if (e.type == SDL_EVENT_LOCALE_CHANGED) { | ||
85 | SDL_Log("Saw SDL_EVENT_LOCALE_CHANGED event!"); | ||
86 | log_locales(); | ||
87 | } | ||
88 | } | ||
89 | |||
90 | for (i = 0; i < state->num_windows; i++) { | ||
91 | SDL_RenderPresent(state->renderers[i]); | ||
92 | } | ||
93 | |||
94 | SDL_Delay(10); | ||
95 | } | ||
96 | } | ||
97 | |||
98 | SDLTest_CommonQuit(state); | ||
99 | |||
100 | return 0; | ||
101 | } | ||