]> git.lizzy.rs Git - irrlicht.git/blob - tests/timer.cpp
Fix include install location
[irrlicht.git] / tests / timer.cpp
1 #include "testUtils.h"\r
2 \r
3 using namespace irr;\r
4 using namespace core;\r
5 \r
6 // Test the functionality of the Irrlicht timer\r
7 bool testTimer(void)\r
8 {\r
9         bool success = true;\r
10 \r
11         IrrlichtDevice* device = createDevice(video::EDT_NULL);\r
12         if (!device)\r
13                 return false;\r
14 \r
15         logTestString("Testing virtual timer.\n");\r
16 \r
17         ITimer* timer = device->getTimer();\r
18 \r
19         // must be running at start\r
20         success &= !timer->isStopped();\r
21 \r
22         // starting more often should not stop the timer\r
23         timer->start();\r
24         success &= !timer->isStopped();\r
25 \r
26         // one stop should not stop the timer because it's started twice now\r
27         timer->stop();\r
28         success &= !timer->isStopped();\r
29 \r
30         // another stop should really stop it\r
31         timer->stop();\r
32         success &= timer->isStopped();\r
33 \r
34         // third stop - timer should still be stopped\r
35         timer->stop();\r
36         success &= timer->isStopped();\r
37 \r
38         // should not start yet\r
39         timer->start();\r
40         success &= timer->isStopped();\r
41 \r
42         // start again\r
43         timer->start();\r
44         success &= !timer->isStopped();\r
45 \r
46         logTestString("Testing virtual timer done. %s\n", success?"Success":"Failure");\r
47 \r
48         logTestString("Testing real timer.\n");\r
49         const u32 startVirtual = timer->getTime();\r
50         const u32 startReal = timer->getRealTime();\r
51         device->sleep(2);\r
52         if (startReal != timer->getRealTime())\r
53                 logTestString("Warning: Real timer did not progress. Maybe the time slices are too coarse to see.\n");\r
54         if (startVirtual != timer->getTime())\r
55                 logTestString("Warning: Virtual timer did not progress. Maybe the time slices are too coarse to see.\n");\r
56 \r
57         irr::ITimer::RealTimeDate date = timer->getRealTimeAndDate();\r
58         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);\r
59         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");\r
60 \r
61         device->closeDevice();\r
62         device->run();\r
63         device->drop();\r
64 \r
65         return success;\r
66 }\r