testlocale.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Copyright (C) 1997-2024 Sam Lantinga <[email protected]>
  3. This software is provided 'as-is', without any express or implied
  4. warranty. In no event will the authors be held liable for any damages
  5. arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it
  8. freely.
  9. */
  10. #include <SDL3/SDL.h>
  11. #include <SDL3/SDL_main.h>
  12. #include <SDL3/SDL_test.h>
  13. static void log_locales(void)
  14. {
  15. SDL_Locale *locales = SDL_GetPreferredLocales();
  16. if (!locales) {
  17. SDL_Log("Couldn't determine locales: %s", SDL_GetError());
  18. } else {
  19. SDL_Locale *l;
  20. unsigned int total = 0;
  21. SDL_Log("Locales, in order of preference:");
  22. for (l = locales; l->language; l++) {
  23. const char *c = l->country;
  24. SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : "");
  25. total++;
  26. }
  27. SDL_Log("%u locales seen.", total);
  28. SDL_free(locales);
  29. }
  30. }
  31. int main(int argc, char **argv)
  32. {
  33. int i;
  34. int listen = 0;
  35. SDLTest_CommonState *state;
  36. /* Initialize test framework */
  37. state = SDLTest_CommonCreateState(argv, 0);
  38. if (!state) {
  39. return 1;
  40. }
  41. /* Enable standard application logging */
  42. SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  43. /* Parse commandline */
  44. for (i = 1; i < argc;) {
  45. int consumed;
  46. consumed = SDLTest_CommonArg(state, i);
  47. if (!consumed) {
  48. if (SDL_strcmp(argv[1], "--listen") == 0) {
  49. listen = 1;
  50. consumed = 1;
  51. state->flags |= SDL_INIT_VIDEO;
  52. }
  53. }
  54. if (consumed <= 0) {
  55. static const char *options[] = { "[--listen]", NULL };
  56. SDLTest_CommonLogUsage(state, argv[0], options);
  57. return 1;
  58. }
  59. i += consumed;
  60. }
  61. /* Print locales and languages */
  62. if (SDLTest_CommonInit(state) == SDL_FALSE) {
  63. return 1;
  64. }
  65. log_locales();
  66. if (listen) {
  67. int done = 0;
  68. while (!done) {
  69. SDL_Event e;
  70. SDLTest_CommonEvent(state, &e, &done);
  71. while (SDL_PollEvent(&e)) {
  72. if (e.type == SDL_EVENT_QUIT) {
  73. done = 1;
  74. } else if (e.type == SDL_EVENT_LOCALE_CHANGED) {
  75. SDL_Log("Saw SDL_EVENT_LOCALE_CHANGED event!");
  76. log_locales();
  77. }
  78. }
  79. for (i = 0; i < state->num_windows; i++) {
  80. SDL_RenderPresent(state->renderers[i]);
  81. }
  82. SDL_Delay(10);
  83. }
  84. }
  85. SDLTest_CommonQuit(state);
  86. return 0;
  87. }