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.

94 lines
3.5KB

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