1: <?php
2: 3: 4: 5:
6: class QTimerTests extends QUnitTestCaseBase {
7: public function testTimerBasic() {
8: QTimer::start('timer1');
9: $this->longOperation();
10: $fltValue1 = QTimer::stop('timer1');
11: $fltValue2 = QTimer::getTime('timer1');
12:
13: $this->assertTrue($fltValue1 > 0);
14:
15:
16: $this->assertTrue(abs($fltValue1 - $fltValue2) < 0.000000001);
17: }
18:
19: public function testTimerResume() {
20: QTimer::start('timer2');
21: $this->longOperation();
22: $fltValue1 = QTimer::stop('timer2');
23:
24: $this->assertTrue($fltValue1 > 0);
25:
26: QTimer::start('timer2');
27: $this->longOperation();
28: $fltValue2 = QTimer::stop('timer2');
29:
30: QTimer::start('timer2');
31: $this->longOperation();
32: $fltValue3 = QTimer::stop('timer2');
33:
34:
35: $this->assertTrue($fltValue1 > 0);
36: $this->assertTrue($fltValue2 > 0);
37: $this->assertTrue($fltValue3 > 0);
38: $this->assertTrue($fltValue1 < $fltValue2);
39: $this->assertTrue($fltValue2 < $fltValue3);
40:
41: $objTimer = QTimer::GetTimer('timer2');
42: $this->assertEquals(3, $objTimer->CountStarted);
43: }
44:
45: public function testReset() {
46: QTimer::start('timerA');
47: $this->longOperation();
48: $fltValue1 = QTimer::GetTime('timerA');
49: $this->longOperation();
50: $fltValue2 = QTimer::GetTime('timerA');
51: $this->longOperation();
52: $fltValue3 = QTimer::reset('timerA');
53: $fltValue4 = QTimer::stop('timerA');
54:
55: $this->assertTrue($fltValue1 > 0);
56: $this->assertTrue($fltValue2 > 0);
57: $this->assertTrue($fltValue3 > 0);
58: $this->assertTrue($fltValue4 > 0);
59: $this->assertTrue($fltValue1 < $fltValue2);
60: $this->assertTrue($fltValue2 < $fltValue3);
61: $this->assertTrue($fltValue4 < $fltValue3);
62:
63: $objTimer = QTimer::GetTimer('timerA');
64: $this->assertEquals(2, $objTimer->CountStarted);
65: }
66:
67:
68: public function testExceptions1() {
69:
70: $this->setExpectedException("QCallerException");
71: QTimer::stop('timer4');
72: }
73:
74: public function testExceptions2() {
75: $this->setExpectedException("QCallerException");
76: QTimer::getTime('timer5');
77: }
78:
79: public function testExceptions3() {
80: QTimer::start('timer6');
81: $this->setExpectedException("QCallerException");
82: QTimer::start('timer6');
83: }
84:
85: public function testExceptions4() {
86: $objTimer = QTimer::GetTimer('timer7');
87: $this->assertEquals(null, $objTimer, "Requests for non-existing timer objects should return null");
88: }
89:
90:
91: private function longOperation() {
92: Person::LoadAll();
93: }
94: }