Mercurial > irccd
annotate tests/test-jsapi-timer.c @ 1036:bafb5943cd35
misc: add missing compat.h includes
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 12 Apr 2021 11:16:18 +0200 |
parents | 371e1cc2c697 |
children | 99dccafade22 |
rev | line source |
---|---|
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
1 /* |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
2 * test-jsapi-timer.c -- test Irccd.System API |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
3 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
4 * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
5 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
6 * Permission to use, copy, modify, and/or distribute this software for any |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
7 * purpose with or without fee is hereby granted, provided that the above |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
8 * copyright notice and this permission notice appear in all copies. |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
9 * |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
17 */ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
18 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
19 /* TODO: We need proper bot function to dispatch */ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 #if 0 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 #define GREATEST_USE_ABBREVS 0 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 #include <greatest.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
25 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
26 // TODO: irccd/ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
27 #include <config.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
28 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
29 #include <irccd/js-plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 #include <irccd/plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
31 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 static struct irc_plugin *plugin; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 static struct irc_js_plugin_data *data; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
36 setup(void *udata) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
37 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
39 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
40 plugin = irc_js_plugin_open(SOURCE "/data/timer.js"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 data = plugin->data; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
42 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
43 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 teardown(void *udata) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
46 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
47 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
48 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 irc_plugin_finish(plugin); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
50 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
51 plugin = NULL; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 data = NULL; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
54 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
56 set_type(const char *name) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
57 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
58 duk_get_global_string(data->ctx, "Irccd"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 duk_get_prop_string(data->ctx, -1, "Timer"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
60 duk_get_prop_string(data->ctx, -1, name.c_str()); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
61 duk_put_global_string(data->ctx, "type"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
62 duk_pop_n(data->ctx, 2); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
63 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
64 plugin_->open(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
65 plugin_->handle_load(bot_); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
66 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
67 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
68 BOOST_AUTO_TEST_CASE(single) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
69 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
70 boost::timer::cpu_timer timer; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
71 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
72 set_type("Single"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
73 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
74 while (timer.elapsed().wall / 1000000LL < 3000) { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
75 ctx_.reset(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
76 ctx_.poll(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
77 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
78 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 BOOST_TEST(duk_get_global_string(data->ctx, "count")); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 BOOST_TEST(duk_get_int(data->ctx, -1) == 1); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
81 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
82 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 BOOST_AUTO_TEST_CASE(repeat) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
84 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
85 boost::timer::cpu_timer timer; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 set_type("Repeat"); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
88 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
89 while (timer.elapsed().wall / 1000000LL < 3000) { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
90 ctx_.reset(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
91 ctx_.poll(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
92 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
93 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
94 BOOST_TEST(duk_get_global_string(data->ctx, "count")); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
95 BOOST_TEST(duk_get_int(data->ctx, -1) >= 5); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
96 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
97 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
98 #endif |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
99 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
100 int |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
101 main(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
102 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
103 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
104 } |