test_sysinfo.mod 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. MODULE test_sysinfo ;
  2. (*
  3. m2SDL3 smoke tests, no window needed:
  4. - power: SDL_GetPowerInfo returns a known state id.
  5. - locale: preferred-locales list decodes (first language nonempty).
  6. - filesystem: base path + current directory are nonempty strings.
  7. SDL-allocated results are released with SDL_free.
  8. *)
  9. FROM SYSTEM IMPORT ADDRESS;
  10. FROM SDL3Power IMPORT SDL_GetPowerInfo,
  11. PowerError, PowerUnknown, PowerOnBattery,
  12. PowerNoBattery, PowerCharging, PowerCharged;
  13. FROM SDL3Locale IMPORT SDLLocale, LocalePtr, LocaleVecPtr,
  14. SDL_GetPreferredLocales;
  15. FROM SDL3Filesystem IMPORT SDL_GetBasePath, SDL_GetCurrentDirectory;
  16. FROM SDL3Stdinc IMPORT SDL_free;
  17. FROM SDL3Utils IMPORT CStrToM2;
  18. FROM libc IMPORT printf;
  19. VAR
  20. secs, pct, state, n, i: INTEGER;
  21. vec: LocaleVecPtr;
  22. entry: LocalePtr;
  23. p: ADDRESS;
  24. buf: ARRAY [0..255] OF CHAR;
  25. PROCEDURE Fail (msg: ARRAY OF CHAR);
  26. BEGIN
  27. printf("FAIL test_sysinfo: %s\n", msg);
  28. HALT(1)
  29. END Fail;
  30. BEGIN
  31. (* power *)
  32. secs := 0; pct := 0;
  33. state := SDL_GetPowerInfo(secs, pct);
  34. printf("power state=%d secs=%d pct=%d\n", state, secs, pct);
  35. IF (state < PowerError) OR (state > PowerCharged) THEN
  36. Fail("power state out of range")
  37. END;
  38. (* locale *)
  39. n := 0;
  40. vec := SDL_GetPreferredLocales(n);
  41. IF vec = NIL THEN Fail("locale list NIL") END;
  42. printf("locales: %d\n", n);
  43. IF n <= 0 THEN Fail("locale count not positive") END;
  44. IF n > 256 THEN Fail("locale count over 256") END;
  45. entry := vec^[0];
  46. IF entry = NIL THEN Fail("first locale NIL") END;
  47. CStrToM2(entry^.language, buf);
  48. printf("first locale: %s\n", buf);
  49. IF buf[0] = 0C THEN Fail("first language empty") END;
  50. FOR i := 0 TO n - 1 DO
  51. IF vec^[i] = NIL THEN Fail("locale entry NIL") END
  52. END;
  53. SDL_free(vec);
  54. (* filesystem *)
  55. p := SDL_GetBasePath();
  56. CStrToM2(p, buf);
  57. SDL_free(p);
  58. printf("base: %s\n", buf);
  59. IF buf[0] = 0C THEN Fail("base path empty") END;
  60. p := SDL_GetCurrentDirectory();
  61. CStrToM2(p, buf);
  62. SDL_free(p);
  63. printf("cwd: %s\n", buf);
  64. IF buf[0] = 0C THEN Fail("cwd empty") END;
  65. printf("PASS test_sysinfo\n")
  66. END test_sysinfo.