Async.cpp 799 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "tests/framework/Framework.h"
  2. #include "anki/core/Async.h"
  3. #include "anki/core/Logger.h"
  4. #include "anki/util/HighRezTimer.h"
  5. #include "anki/util/StdTypes.h"
  6. namespace anki {
  7. /// Struct for our tests
  8. struct TestJob: AsyncJob
  9. {
  10. U32 result = 0;
  11. void operator()()
  12. {
  13. ANKI_LOGI("-- Job " << this << " starting");
  14. HighRezTimer::sleep(1.0);
  15. ++result;
  16. ANKI_LOGI("-- Job " << this << " done");
  17. }
  18. void post()
  19. {
  20. ANKI_LOGI("-- Job " << this << " starting post");
  21. HighRezTimer::sleep(1.0);
  22. ++result;
  23. ANKI_LOGI("-- Job " << this << " done post");
  24. }
  25. };
  26. } // end namespace anki
  27. ANKI_TEST(Core, Async)
  28. {
  29. Async a;
  30. TestJob pjob;
  31. a.start();
  32. a.assignNewJob(&pjob);
  33. HighRezTimer::sleep(2.0);
  34. a.cleanupFinishedJobs(123.0);
  35. a.stop();
  36. ANKI_TEST_EXPECT_EQ(pjob.result, 2);
  37. }