testfilesystem.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /* Simple test of filesystem functions. */
  11. #include <stdio.h>
  12. #include "SDL.h"
  13. #include "SDL_test.h"
  14. int main(int argc, char *argv[])
  15. {
  16. char *base_path;
  17. char *pref_path;
  18. SDLTest_CommonState *state;
  19. state = SDLTest_CommonCreateState(argv, 0);
  20. if (!state) {
  21. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDLTest_CommonCreateState failed: %s\n", SDL_GetError());
  22. return 1;
  23. }
  24. /* Enable standard application logging */
  25. SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
  26. if (!SDLTest_CommonDefaultArgs(state, argc, argv)) {
  27. return 1;
  28. }
  29. if (!SDLTest_CommonInit(state)) {
  30. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
  31. return 1;
  32. }
  33. base_path = SDL_GetBasePath();
  34. if (!base_path) {
  35. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find base path: %s\n",
  36. SDL_GetError());
  37. } else {
  38. SDL_Log("base path: '%s'\n", base_path);
  39. SDL_free(base_path);
  40. }
  41. pref_path = SDL_GetPrefPath("libsdl", "test_filesystem");
  42. if (!pref_path) {
  43. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path: %s\n",
  44. SDL_GetError());
  45. } else {
  46. SDL_Log("pref path: '%s'\n", pref_path);
  47. SDL_free(pref_path);
  48. }
  49. pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
  50. if (!pref_path) {
  51. SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't find pref path without organization: %s\n",
  52. SDL_GetError());
  53. } else {
  54. SDL_Log("pref path: '%s'\n", pref_path);
  55. SDL_free(pref_path);
  56. }
  57. SDLTest_CommonQuit(state);
  58. return 0;
  59. }