timer.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "testUtils.h"
  2. using namespace irr;
  3. using namespace core;
  4. // Test the functionality of the Irrlicht timer
  5. bool testTimer(void)
  6. {
  7. bool success = true;
  8. IrrlichtDevice* device = createDevice(video::EDT_NULL);
  9. if (!device)
  10. return false;
  11. logTestString("Testing virtual timer.\n");
  12. ITimer* timer = device->getTimer();
  13. // must be running at start
  14. success &= !timer->isStopped();
  15. // starting more often should not stop the timer
  16. timer->start();
  17. success &= !timer->isStopped();
  18. // one stop should not stop the timer because it's started twice now
  19. timer->stop();
  20. success &= !timer->isStopped();
  21. // another stop should really stop it
  22. timer->stop();
  23. success &= timer->isStopped();
  24. // third stop - timer should still be stopped
  25. timer->stop();
  26. success &= timer->isStopped();
  27. // should not start yet
  28. timer->start();
  29. success &= timer->isStopped();
  30. // start again
  31. timer->start();
  32. success &= !timer->isStopped();
  33. logTestString("Testing virtual timer done. %s\n", success?"Success":"Failure");
  34. logTestString("Testing real timer.\n");
  35. const u32 startVirtual = timer->getTime();
  36. const u32 startReal = timer->getRealTime();
  37. device->sleep(2);
  38. if (startReal != timer->getRealTime())
  39. logTestString("Warning: Real timer did not progress. Maybe the time slices are too coarse to see.\n");
  40. if (startVirtual != timer->getTime())
  41. logTestString("Warning: Virtual timer did not progress. Maybe the time slices are too coarse to see.\n");
  42. irr::ITimer::RealTimeDate date = timer->getRealTimeAndDate();
  43. logTestString("Real time and date. %d.%d.%d at %d:%d:%d\n", date.Day, date.Month, date.Year, date.Hour, date.Minute, date.Second);
  44. logTestString("This is day %d of the year and weekday %d. The current time zone has daylight saving %s\n", date.Yearday, date.Weekday, date.IsDST?"enabled":"disabled");
  45. device->closeDevice();
  46. device->run();
  47. device->drop();
  48. return success;
  49. }