testlocale.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  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 <stdio.h>
  11. #include "SDL.h"
  12. #include "SDL_test.h"
  13. /* !!! FIXME: move this to the test framework */
  14. static void log_locales(void)
  15. {
  16. SDL_Locale *locales = SDL_GetPreferredLocales();
  17. if (!locales) {
  18. SDL_Log("Couldn't determine locales: %s", SDL_GetError());
  19. } else {
  20. SDL_Locale *l;
  21. unsigned int total = 0;
  22. SDL_Log("Locales, in order of preference:");
  23. for (l = locales; l->language; l++) {
  24. const char *c = l->country;
  25. SDL_Log(" - %s%s%s", l->language, c ? "_" : "", c ? c : "");
  26. total++;
  27. }
  28. SDL_Log("%u locales seen.", total);
  29. SDL_free(locales);
  30. }
  31. }
  32. int main(int argc, char **argv)
  33. {
  34. SDLTest_CommonState *state;
  35. SDL_bool listen = SDL_FALSE;
  36. int i = 1;
  37. state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
  38. if (!state) {
  39. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
  40. return 1;
  41. }
  42. /* Enable standard application logging */
  43. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  44. /* Parse commandline */
  45. for (i = 1; i < argc;) {
  46. int consumed;
  47. consumed = SDLTest_CommonArg(state, i);
  48. if (!consumed) {
  49. if (SDL_strcmp("--listen", argv[i]) == 0) {
  50. listen = SDL_TRUE;
  51. consumed = 1;
  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. if (!SDLTest_CommonInit(state)) {
  62. return 1;
  63. }
  64. /* Print locales and languages */
  65. log_locales();
  66. if (listen) {
  67. SDL_bool keep_going = SDL_TRUE;
  68. while (keep_going) {
  69. SDL_Event e;
  70. while (SDL_PollEvent(&e)) {
  71. if (e.type == SDL_QUIT) {
  72. keep_going = SDL_FALSE;
  73. } else if (e.type == SDL_LOCALECHANGED) {
  74. SDL_Log("Saw SDL_LOCALECHANGED event!");
  75. log_locales();
  76. }
  77. }
  78. SDL_Delay(10);
  79. }
  80. }
  81. SDLTest_CommonQuit(state);
  82. return 0;
  83. }
  84. /* vi: set ts=4 sw=4 expandtab: */