Mercurial > malikania
comparison tests/libcommon/js-elapsed-timer/main.cpp @ 189:f28cb6d04731
Misc: extreme refactoring
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 25 Oct 2018 21:36:14 +0200 |
parents | 0cecdadfb5c4 |
children |
comparison
equal
deleted
inserted
replaced
188:0cecdadfb5c4 | 189:f28cb6d04731 |
---|---|
48 BOOST_FIXTURE_TEST_SUITE(test_elapsed_timer_suite, js::test::js_api_fixture) | 48 BOOST_FIXTURE_TEST_SUITE(test_elapsed_timer_suite, js::test::js_api_fixture) |
49 | 49 |
50 BOOST_AUTO_TEST_CASE(standard) | 50 BOOST_AUTO_TEST_CASE(standard) |
51 { | 51 { |
52 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) | 52 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) |
53 throw duk::get_stack(ctx_, -1); | 53 throw mlk::js::duk::get_stack(ctx_, -1); |
54 | 54 |
55 std::this_thread::sleep_for(300ms); | 55 std::this_thread::sleep_for(300ms); |
56 | 56 |
57 if (duk_peval_string(ctx_, "result = timer.elapsed();") != 0) | 57 if (duk_peval_string(ctx_, "result = timer.elapsed();") != 0) |
58 throw duk::get_stack(ctx_, -1); | 58 throw mlk::js::duk::get_stack(ctx_, -1); |
59 | 59 |
60 duk_get_global_string(ctx_, "result"); | 60 duk_get_global_string(ctx_, "result"); |
61 assert_range(duk_to_int(ctx_, -1), 300); | 61 assert_range(duk_to_int(ctx_, -1), 300); |
62 duk_pop(ctx_); | 62 duk_pop(ctx_); |
63 } | 63 } |
64 | 64 |
65 BOOST_AUTO_TEST_CASE(pause) | 65 BOOST_AUTO_TEST_CASE(pause) |
66 { | 66 { |
67 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) | 67 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) |
68 throw duk::get_stack(ctx_, -1); | 68 throw mlk::js::duk::get_stack(ctx_, -1); |
69 | 69 |
70 /* | 70 /* |
71 * Simulate a pause in the game like this: | 71 * Simulate a pause in the game like this: |
72 * | 72 * |
73 * start pause restart elapsed | 73 * start pause restart elapsed |
76 * Since the game was paused, the 5ms must not be totalized. | 76 * Since the game was paused, the 5ms must not be totalized. |
77 */ | 77 */ |
78 std::this_thread::sleep_for(10ms); | 78 std::this_thread::sleep_for(10ms); |
79 | 79 |
80 if (duk_peval_string(ctx_, "timer.pause();") != 0) | 80 if (duk_peval_string(ctx_, "timer.pause();") != 0) |
81 throw duk::get_stack(ctx_, -1); | 81 throw mlk::js::duk::get_stack(ctx_, -1); |
82 | 82 |
83 std::this_thread::sleep_for(5ms); | 83 std::this_thread::sleep_for(5ms); |
84 | 84 |
85 if (duk_peval_string(ctx_, "timer.restart();") != 0) | 85 if (duk_peval_string(ctx_, "timer.restart();") != 0) |
86 throw duk::get_stack(ctx_, -1); | 86 throw mlk::js::duk::get_stack(ctx_, -1); |
87 | 87 |
88 std::this_thread::sleep_for(6ms); | 88 std::this_thread::sleep_for(6ms); |
89 | 89 |
90 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) | 90 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) |
91 throw duk::get_stack(ctx_, -1); | 91 throw mlk::js::duk::get_stack(ctx_, -1); |
92 | 92 |
93 duk_get_global_string(ctx_, "result"); | 93 duk_get_global_string(ctx_, "result"); |
94 assert_range(duk_to_int(ctx_, -1), 16); | 94 assert_range(duk_to_int(ctx_, -1), 16); |
95 duk_pop(ctx_); | 95 duk_pop(ctx_); |
96 } | 96 } |
97 | 97 |
98 BOOST_AUTO_TEST_CASE(doublecheck) | 98 BOOST_AUTO_TEST_CASE(doublecheck) |
99 { | 99 { |
100 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) | 100 if (duk_peval_string(ctx_, "timer = new Malikania.ElapsedTimer();") != 0) |
101 throw duk::get_stack(ctx_, -1); | 101 throw mlk::js::duk::get_stack(ctx_, -1); |
102 | 102 |
103 std::this_thread::sleep_for(50ms); | 103 std::this_thread::sleep_for(50ms); |
104 | 104 |
105 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) | 105 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) |
106 throw duk::get_stack(ctx_, -1); | 106 throw mlk::js::duk::get_stack(ctx_, -1); |
107 | 107 |
108 std::this_thread::sleep_for(50ms); | 108 std::this_thread::sleep_for(50ms); |
109 | 109 |
110 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) | 110 if (duk_peval_string(ctx_, "result = timer.elapsed()") != 0) |
111 throw duk::get_stack(ctx_, -1); | 111 throw mlk::js::duk::get_stack(ctx_, -1); |
112 | 112 |
113 duk_get_global_string(ctx_, "result"); | 113 duk_get_global_string(ctx_, "result"); |
114 assert_range(duk_to_int(ctx_, -1), 100); | 114 assert_range(duk_to_int(ctx_, -1), 100); |
115 duk_pop(ctx_); | 115 duk_pop(ctx_); |
116 } | 116 } |