test_main.cc 778 B

1234567891011121314151617181920212223242526272829303132
  1. #define DROGON_TEST_MAIN
  2. #include <drogon/drogon_test.h>
  3. #include <drogon/drogon.h>
  4. DROGON_TEST(BasicTest)
  5. {
  6. // Add your tests here
  7. }
  8. int main(int argc, char** argv)
  9. {
  10. using namespace drogon;
  11. std::promise<void> p1;
  12. std::future<void> f1 = p1.get_future();
  13. // Start the main loop on another thread
  14. std::thread thr([&]() {
  15. // Queues the promise to be fulfilled after starting the loop
  16. app().getLoop()->queueInLoop([&p1]() { p1.set_value(); });
  17. app().run();
  18. });
  19. // The future is only satisfied after the event loop started
  20. f1.get();
  21. int status = test::run(argc, argv);
  22. // Ask the event loop to shutdown and wait
  23. app().getLoop()->queueInLoop([]() { app().quit(); });
  24. thr.join();
  25. return status;
  26. }