Line data Source code
1 : #include "catch.hpp"
2 : #include "gametimer.h"
3 :
4 7 : SCENARIO( "GameTimer", "[GameTimer]" ) {
5 12 : GIVEN( "A game timer" ) {
6 : GameTimer t;
7 :
8 8 : WHEN( "init is called" ) {
9 2 : bool ok = t.init();
10 :
11 3 : THEN( "initialization succeeds on this platform" ) {
12 1 : REQUIRE(ok == true);
13 1 : }
14 :
15 : // On non-Windows, getFPS returns the fps member last set by
16 : // getElapsedSeconds. Before any getElapsedSeconds() call it is 0.0f.
17 : // (Windows is not currently supported; guard here for when it is.)
18 : #ifndef _WIN32
19 3 : THEN( "getFPS returns 0.0f before any elapsed-seconds call (non-Windows)" ) {
20 1 : REQUIRE(t.getFPS() == Approx(0.0f));
21 1 : }
22 : #endif
23 2 : }
24 :
25 8 : WHEN( "getElapsedSeconds is called after init" ) {
26 2 : t.init();
27 2 : float elapsed = t.getElapsedSeconds();
28 :
29 3 : THEN( "returns a positive elapsed time" ) {
30 1 : REQUIRE(elapsed > 0.0f);
31 1 : }
32 :
33 : // Mirrors the Engine frame loop: getElapsedSeconds then getFPS each frame.
34 3 : THEN( "getFPS returns a positive value after getElapsedSeconds" ) {
35 1 : REQUIRE(t.getFPS() > 0.0f);
36 1 : }
37 2 : }
38 :
39 : // getElapsedSeconds updates m_startTime each call so successive calls
40 : // each measure incremental elapsed time, not total since init.
41 7 : WHEN( "getElapsedSeconds is called twice" ) {
42 1 : t.init();
43 1 : float first = t.getElapsedSeconds();
44 1 : float second = t.getElapsedSeconds();
45 :
46 2 : THEN( "both calls return positive elapsed time" ) {
47 1 : REQUIRE(first > 0.0f);
48 1 : REQUIRE(second > 0.0f);
49 1 : }
50 1 : }
51 :
52 7 : WHEN( "init is called twice" ) {
53 2 : THEN( "both calls succeed" ) {
54 1 : REQUIRE(t.init() == true);
55 1 : REQUIRE(t.init() == true);
56 1 : }
57 1 : }
58 6 : }
59 6 : }
|