test.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * openmodal/test.c
  3. *
  4. * Copyright (C) 2023 bzt MIT license
  5. *
  6. * Permission is hereby granted, free of charge, to any person
  7. * obtaining a copy of this software and associated documentation
  8. * files (the "Software"), to deal in the Software without
  9. * restriction, including without limitation the rights to use, copy,
  10. * modify, merge, publish, distribute, sublicense, and/or sell copies
  11. * of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  21. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  22. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. *
  26. * @brief Test platform native open file modal windows
  27. *
  28. */
  29. #include "openmodal.h"
  30. #ifdef __WIN32__
  31. int main(int argc, char **argv);
  32. /* Windows GUI entry point */
  33. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  34. {
  35. (void)hInstance;
  36. (void)hPrevInstance;
  37. (void)lpCmdLine;
  38. (void)nCmdShow;
  39. return main(0, NULL);
  40. }
  41. #endif
  42. int main(int argc, char **argv)
  43. {
  44. char fn[PATH_MAX];
  45. uint8_t *data;
  46. int len = 0;
  47. (void)argc; (void)argv;
  48. printf("Loading file data\r\n");
  49. memset(fn, 0, sizeof(fn));
  50. data = openmodal_load(fn, &len);
  51. if(!data) {
  52. printf("User pressed Cancel\r\n");
  53. } else {
  54. printf("Returned %u bytes from file '%s'\r\n", len, fn);
  55. free(data);
  56. }
  57. printf("Saving file data\r\n");
  58. len = 8;
  59. data = malloc(len);
  60. memcpy(data, "Testing", len);
  61. strcpy(fn, "untitled.txt");
  62. if(!openmodal_save(fn, data, len)) {
  63. printf("User pressed Cancel\r\n");
  64. } else {
  65. printf("Data successfully saved to '%s'\r\n", fn);
  66. }
  67. free(data);
  68. }