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.

90 lines
3.4KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2025 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. #include "tests.hpp"
  17. #include "dgl.cpp"
  18. START_NAMESPACE_DGL
  19. // --------------------------------------------------------------------------------------------------------------------
  20. struct IdleCallbackCounter : IdleCallback
  21. {
  22. int counter;
  23. IdleCallbackCounter()
  24. : counter(0) {}
  25. void idleCallback() override
  26. {
  27. ++counter;
  28. }
  29. };
  30. // --------------------------------------------------------------------------------------------------------------------
  31. END_NAMESPACE_DGL
  32. int main()
  33. {
  34. using DGL_NAMESPACE::Application;
  35. using DGL_NAMESPACE::ApplicationQuitter;
  36. using DGL_NAMESPACE::IdleCallbackCounter;
  37. // regular usage
  38. {
  39. Application app(true);
  40. IdleCallbackCounter idleCounter;
  41. app.addIdleCallback(&idleCounter);
  42. DISTRHO_ASSERT_EQUAL(app.isQuitting(), false, "app MUST NOT be set as quitting during init");
  43. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 0, "app MUST NOT have triggered idle callbacks yet");
  44. app.idle();
  45. DISTRHO_ASSERT_EQUAL(app.isQuitting(), false, "app MUST NOT be set as quitting after idle()");
  46. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 1, "app MUST have triggered 1 idle callback");
  47. app.idle();
  48. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 2, "app MUST have triggered 2 idle callbacks");
  49. app.quit();
  50. DISTRHO_ASSERT_EQUAL(app.isQuitting(), true, "app MUST be set as quitting after quit()");
  51. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 2, "app MUST have triggered only 2 idle callbacks in its lifetime");
  52. }
  53. // standalone exec, must not block forever due to quit() called from another thread
  54. {
  55. Application app(true);
  56. ApplicationQuitter appQuitter(app);
  57. IdleCallbackCounter idleCounter;
  58. app.addIdleCallback(&idleCounter);
  59. app.exec();
  60. DISTRHO_ASSERT_EQUAL(appQuitter.isThreadRunning(), false, "app quit triggered because we told it so");
  61. DISTRHO_ASSERT_NOT_EQUAL(idleCounter.counter, 0, "app idle callbacks MUST have been triggered");
  62. }
  63. // standalone exec, but with 0 as timeout
  64. {
  65. Application app(true);
  66. ApplicationQuitter appQuitter(app);
  67. IdleCallbackCounter idleCounter;
  68. app.addIdleCallback(&idleCounter);
  69. app.exec(0);
  70. DISTRHO_ASSERT_EQUAL(appQuitter.isThreadRunning(), false, "app quit triggered because we told it so");
  71. DISTRHO_ASSERT_NOT_EQUAL(idleCounter.counter, 0, "app idle callbacks MUST have been triggered");
  72. }
  73. return 0;
  74. }
  75. // --------------------------------------------------------------------------------------------------------------------