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.

92 lines
3.4KB

  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. #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. USE_NAMESPACE_DGL;
  38. // regular usage
  39. {
  40. Application app(true);
  41. IdleCallbackCounter idleCounter;
  42. app.addIdleCallback(&idleCounter);
  43. DISTRHO_ASSERT_EQUAL(app.isQuiting(), false, "app MUST NOT be set as quitting during init");
  44. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 0, "app MUST NOT have triggered idle callbacks yet");
  45. app.idle();
  46. DISTRHO_ASSERT_EQUAL(app.isQuiting(), false, "app MUST NOT be set as quitting after idle()");
  47. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 1, "app MUST have triggered 1 idle callback");
  48. app.idle();
  49. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 2, "app MUST have triggered 2 idle callbacks");
  50. app.quit();
  51. DISTRHO_ASSERT_EQUAL(app.isQuiting(), true, "app MUST be set as quitting after quit()");
  52. DISTRHO_ASSERT_EQUAL(idleCounter.counter, 2, "app MUST have triggered only 2 idle callbacks in its lifetime");
  53. }
  54. // standalone exec, must not block forever due to quit() called from another thread
  55. {
  56. Application app(true);
  57. ApplicationQuitter appQuitter(app);
  58. IdleCallbackCounter idleCounter;
  59. app.addIdleCallback(&idleCounter);
  60. app.exec();
  61. DISTRHO_ASSERT_EQUAL(appQuitter.isThreadRunning(), false, "app quit triggered because we told it so");
  62. DISTRHO_ASSERT_NOT_EQUAL(idleCounter.counter, 0, "app idle callbacks MUST have been triggered");
  63. }
  64. // standalone exec, but with 0 as timeout
  65. {
  66. Application app(true);
  67. ApplicationQuitter appQuitter(app);
  68. IdleCallbackCounter idleCounter;
  69. app.addIdleCallback(&idleCounter);
  70. app.exec(0);
  71. DISTRHO_ASSERT_EQUAL(appQuitter.isThreadRunning(), false, "app quit triggered because we told it so");
  72. DISTRHO_ASSERT_NOT_EQUAL(idleCounter.counter, 0, "app idle callbacks MUST have been triggered");
  73. }
  74. return 0;
  75. }
  76. // --------------------------------------------------------------------------------------------------------------------