comparison tests/timer-jsapi/main.cpp @ 579:84ea13c850f4

Tests: rename close to target names
author David Demelier <markand@malikania.fr>
date Mon, 04 Dec 2017 13:49:51 +0100
parents tests/js-timer/main.cpp@75e3711c95f8
children
comparison
equal deleted inserted replaced
578:a8b892177909 579:84ea13c850f4
1 /*
2 * main.cpp -- test Irccd.Timer 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 "Timer Javascript API"
20 #include <boost/test/unit_test.hpp>
21 #include <boost/timer/timer.hpp>
22
23 #include <irccd/js/plugin_jsapi.hpp>
24 #include <irccd/js/timer_jsapi.hpp>
25
26 #include <js_test.hpp>
27
28 #include <irccd/js/logger_jsapi.hpp>
29
30 namespace irccd {
31
32 namespace {
33
34 class js_timer_test : public js_test<plugin_jsapi, timer_jsapi> {
35 public:
36 js_timer_test()
37 : js_test(CMAKE_CURRENT_SOURCE_DIR "/timer.js")
38 {
39 }
40
41 void set_type(const std::string& name)
42 {
43 duk_get_global_string(plugin_->context(), "Irccd");
44 duk_get_prop_string(plugin_->context(), -1, "Timer");
45 duk_get_prop_string(plugin_->context(), -1, name.c_str());
46 duk_put_global_string(plugin_->context(), "type");
47 duk_pop_n(plugin_->context(), 2);
48
49 plugin_->open();
50 plugin_->on_load(irccd_);
51 }
52 };
53
54 } // !namespace
55
56 BOOST_FIXTURE_TEST_SUITE(js_timer_test_suite, js_timer_test)
57
58 BOOST_AUTO_TEST_CASE(single)
59 {
60 boost::timer::cpu_timer timer;
61
62 set_type("Single");
63
64 while (timer.elapsed().wall / 1000000LL < 3000) {
65 service_.reset();
66 service_.poll();
67 }
68
69 BOOST_TEST(duk_get_global_string(plugin_->context(), "count"));
70 BOOST_TEST(duk_get_int(plugin_->context(), -1) == 1);
71 }
72
73 BOOST_AUTO_TEST_CASE(repeat)
74 {
75 boost::timer::cpu_timer timer;
76
77 set_type("Repeat");
78
79 while (timer.elapsed().wall / 1000000LL < 3000) {
80 service_.reset();
81 service_.poll();
82 }
83
84 BOOST_TEST(duk_get_global_string(plugin_->context(), "count"));
85 BOOST_TEST(duk_get_int(plugin_->context(), -1) >= 5);
86 }
87
88 BOOST_AUTO_TEST_SUITE_END()
89
90 } // !irccd