comparison tests/src/elapsedtimer-jsapi/main.cpp @ 581:a51b5dd5b761

Tests: put everything in src/
author David Demelier <markand@malikania.fr>
date Mon, 04 Dec 2017 14:12:13 +0100
parents tests/elapsedtimer-jsapi/main.cpp@84ea13c850f4
children 9d4da384f5d6
comparison
equal deleted inserted replaced
580:2e16c3623531 581:a51b5dd5b761
1 /*
2 * main.cpp -- test Irccd.ElapsedTimer API
3 *
4 * Copyright (c) 2013-2017 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #define BOOST_TEST_MODULE "ElapsedTimer Javascript API"
20 #include <boost/test/unit_test.hpp>
21
22 #include <thread>
23
24 #include <irccd/js/elapsed_timer_jsapi.hpp>
25
26 #include <js_test.hpp>
27
28 using namespace std::chrono_literals;
29
30 namespace irccd {
31
32 BOOST_FIXTURE_TEST_SUITE(elapsed_timer_jsapi_suite, js_test<elapsed_timer_jsapi>)
33
34 BOOST_AUTO_TEST_CASE(standard)
35 {
36 if (duk_peval_string(plugin_->context(), "timer = new Irccd.ElapsedTimer();") != 0)
37 throw dukx_stack(plugin_->context(), -1);
38
39 std::this_thread::sleep_for(300ms);
40
41 if (duk_peval_string(plugin_->context(), "result = timer.elapsed();") != 0)
42 throw dukx_stack(plugin_->context(), -1);
43
44 BOOST_REQUIRE(duk_get_global_string(plugin_->context(), "result"));
45 BOOST_REQUIRE_GE(duk_get_int(plugin_->context(), -1), 250);
46 BOOST_REQUIRE_LE(duk_get_int(plugin_->context(), -1), 350);
47 }
48
49 } // !irccd
50
51 BOOST_AUTO_TEST_SUITE_END()