diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/test/testlocale.c | |
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/test/testlocale.c')
| -rw-r--r-- | contrib/SDL-3.2.8/test/testlocale.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/test/testlocale.c b/contrib/SDL-3.2.8/test/testlocale.c new file mode 100644 index 0000000..14083ad --- /dev/null +++ b/contrib/SDL-3.2.8/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 | } | ||
