aboutsummaryrefslogtreecommitdiff
path: root/tests/timer.cpp
blob: 935c2ef55cdad81093a89dc37b779fcb679a5018 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "testUtils.h"

using namespace irr;
using namespace core;

// Test the functionality of the Irrlicht timer
bool testTimer(void)
{
	bool success = true;

	IrrlichtDevice* device = createDevice(video::EDT_NULL);
	if (!device)
		return false;

	logTestString("Testing virtual timer.\n");

	ITimer* timer = device->getTimer();

	// must be running at start
	success &= !timer->isStopped();

	// starting more often should not stop the timer
	timer->start();
	success &= !timer->isStopped();

	// one stop should not stop the timer because it's started twice now
	timer->stop();
	success &= !timer->isStopped();

	// another stop should really stop it
	timer->stop();
	success &= timer->isStopped();

	// third stop - timer should still be stopped
	timer->stop();
	success &= timer->isStopped();

	// should not start yet
	timer->start();
	success &= timer->isStopped();

	// start again
	timer->start();
	success &= !timer->isStopped();

	logTestString("Testing virtual timer done. %s\n", success?"Success":"Failure");

	logTestString("Testing real timer.\n");
	const u32 startVirtual = timer->getTime();
	const u32 startReal = timer->getRealTime();
	device->sleep(2);
	if (startReal != timer->getRealTime())
		logTestString("Warning: Real timer did not progress. Maybe the time slices are too coarse to see.\n");
	if (startVirtual != timer->getTime())
		logTestString("Warning: Virtual timer did not progress. Maybe the time slices are too coarse to see.\n");

	irr::ITimer::RealTimeDate date = timer->getRealTimeAndDate();
	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);
	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");

	device->closeDevice();
	device->run();
	device->drop();

	return success;
}