Mercurial > irccd
annotate tests/test-jsapi-system.c @ 1001:b01f5d65d62a
misc: various fixes for glibc
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 13 Feb 2021 10:09:00 +0100 |
parents | 6da542806ed3 |
children | 8f8ce47aba8a |
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-system.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 #define GREATEST_USE_ABBREVS 0 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
20 #include <greatest.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
21 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
22 // TODO: irccd/ |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
23 #include <config.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
24 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
25 #include <irccd/js-plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
26 #include <irccd/plugin.h> |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
27 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
28 static struct irc_plugin *plugin; |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
29 static duk_context *ctx; |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
30 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
31 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
32 setup(void *udata) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
33 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
34 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
35 |
985 | 36 plugin = js_plugin_open("example", SOURCE "/data/example-plugin.js"); |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
37 ctx = js_plugin_get_context(plugin); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
38 } |
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 static void |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
41 teardown(void *udata) |
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 (void)udata; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
44 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
45 irc_plugin_finish(plugin); |
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 plugin = NULL; |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
48 ctx = NULL; |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
49 } |
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 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
52 basics_popen(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
53 { |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
54 int ret = duk_peval_string(ctx, |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
55 "f = Irccd.System.popen(\"" IRCCD_EXECUTABLE " version\", \"r\");" |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
56 "r = f.readline();" |
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 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
59 if (ret != 0) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
60 GREATEST_FAIL(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
61 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
62 GREATEST_ASSERT(duk_get_global_string(ctx, "r")); |
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
63 GREATEST_ASSERT_STR_EQ(IRCCD_VERSION, duk_get_string(ctx, -1)); |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
64 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
65 GREATEST_PASS(); |
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 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
69 basics_sleep(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
70 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
71 time_t start, now; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
72 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
73 start = time(NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
74 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
75 if (duk_peval_string(ctx, "Irccd.System.sleep(2)") != 0) |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
76 GREATEST_FAIL(); |
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 now = time(NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
79 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
80 GREATEST_ASSERT_IN_RANGE(2000LL, difftime(now, start) * 1000LL, 100LL); |
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 GREATEST_PASS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
83 } |
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 GREATEST_TEST |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
86 basics_usleep(void) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
87 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
88 time_t start, now; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
89 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
90 start = time(NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
91 |
965
a518664b20a0
irccd: move javascript API from library to frontend
David Demelier <markand@malikania.fr>
parents:
963
diff
changeset
|
92 if (duk_peval_string(ctx, "Irccd.System.usleep(2000000)") != 0) |
963
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
93 GREATEST_FAIL(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
94 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
95 now = time(NULL); |
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 GREATEST_ASSERT_IN_RANGE(2000LL, difftime(now, start) * 1000LL, 100LL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
98 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
99 GREATEST_PASS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
100 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
101 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
102 GREATEST_SUITE(suite_basics) |
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 GREATEST_SET_SETUP_CB(setup, NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
105 GREATEST_SET_TEARDOWN_CB(teardown, NULL); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
106 GREATEST_RUN_TEST(basics_popen); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
107 GREATEST_RUN_TEST(basics_sleep); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
108 GREATEST_RUN_TEST(basics_usleep); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
109 } |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
110 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
111 GREATEST_MAIN_DEFS(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
112 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
113 int |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
114 main(int argc, char **argv) |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
115 { |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
116 GREATEST_MAIN_BEGIN(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
117 GREATEST_RUN_SUITE(suite_basics); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
118 GREATEST_MAIN_END(); |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
119 |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
120 return 0; |
371e1cc2c697
tests: add 80% of the Javascript API
David Demelier <markand@malikania.fr>
parents:
diff
changeset
|
121 } |