DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.6KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #define DPF_TEST_APPLICATION_CPP
  17. #include "dgl/src/pugl.cpp"
  18. #include "dgl/src/Application.cpp"
  19. #include "dgl/src/ApplicationPrivateData.cpp"
  20. #include "distrho/extra/Thread.hpp"
  21. #define DISTRHO_ASSERT_EQUAL(v1, v2, msg) \
  22. if (v1 != v2) { d_stderr2("Test condition failed: %s; file:%s line:%i", msg, __FILE__, __LINE__); return 1; }
  23. START_NAMESPACE_DGL
  24. // --------------------------------------------------------------------------------------------------------------------
  25. class ApplicationQuitter : public Thread
  26. {
  27. Application& app;
  28. public:
  29. ApplicationQuitter(Application& a)
  30. : Thread("ApplicationQuitter"),
  31. app(a)
  32. {
  33. startThread();
  34. }
  35. private:
  36. void run() override
  37. {
  38. d_sleep(5);
  39. app.quit();
  40. }
  41. };
  42. // --------------------------------------------------------------------------------------------------------------------
  43. END_NAMESPACE_DGL
  44. int main()
  45. {
  46. USE_NAMESPACE_DGL;
  47. // regular usage
  48. {
  49. Application app(true);
  50. DISTRHO_ASSERT_EQUAL(app.isQuiting(), false, "app MUST NOT be set as quitting during init");
  51. app.idle();
  52. DISTRHO_ASSERT_EQUAL(app.isQuiting(), false, "app MUST NOT be set as quitting after idle()");
  53. app.quit();
  54. DISTRHO_ASSERT_EQUAL(app.isQuiting(), true, "app MUST be set as quitting after quit()");
  55. }
  56. // standalone exec, must not block forever due to quit() called from another thread
  57. {
  58. Application app(true);
  59. ApplicationQuitter appQuitter(app);
  60. app.exec();
  61. DISTRHO_ASSERT_EQUAL(appQuitter.isThreadRunning(), false, "app quit triggered because we told it so");
  62. }
  63. return 0;
  64. }
  65. // --------------------------------------------------------------------------------------------------------------------