Mercurial > irccd
comparison tests/irccd-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-irccd/main.cpp@bf56628e070b |
children |
comparison
equal
deleted
inserted
replaced
578:a8b892177909 | 579:84ea13c850f4 |
---|---|
1 /* | |
2 * main.cpp -- test Irccd 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 "Irccd Javascript API" | |
20 #include <boost/test/unit_test.hpp> | |
21 | |
22 #include <js_test.hpp> | |
23 | |
24 namespace irccd { | |
25 | |
26 BOOST_FIXTURE_TEST_SUITE(irccd_jsapi_suite, js_test<irccd_jsapi>) | |
27 | |
28 BOOST_AUTO_TEST_CASE(version) | |
29 { | |
30 auto ret = duk_peval_string(plugin_->context(), | |
31 "major = Irccd.version.major;" | |
32 "minor = Irccd.version.minor;" | |
33 "patch = Irccd.version.patch;" | |
34 ); | |
35 | |
36 if (ret != 0) | |
37 throw dukx_stack(plugin_->context(), -1); | |
38 | |
39 BOOST_TEST(duk_get_global_string(plugin_->context(), "major")); | |
40 BOOST_TEST(IRCCD_VERSION_MAJOR == duk_get_int(plugin_->context(), -1)); | |
41 BOOST_TEST(duk_get_global_string(plugin_->context(), "minor")); | |
42 BOOST_TEST(IRCCD_VERSION_MINOR == duk_get_int(plugin_->context(), -1)); | |
43 BOOST_TEST(duk_get_global_string(plugin_->context(), "patch")); | |
44 BOOST_TEST(IRCCD_VERSION_PATCH == duk_get_int(plugin_->context(), -1)); | |
45 } | |
46 | |
47 BOOST_AUTO_TEST_CASE(from_javascript) | |
48 { | |
49 auto ret = duk_peval_string(plugin_->context(), | |
50 "try {" | |
51 " throw new Irccd.SystemError(1, 'test');" | |
52 "} catch (e) {" | |
53 " errno = e.errno;" | |
54 " name = e.name;" | |
55 " message = e.message;" | |
56 " v1 = (e instanceof Error);" | |
57 " v2 = (e instanceof Irccd.SystemError);" | |
58 "}" | |
59 ); | |
60 | |
61 if (ret != 0) | |
62 throw dukx_stack(plugin_->context(), -1); | |
63 | |
64 BOOST_TEST(duk_get_global_string(plugin_->context(), "errno")); | |
65 BOOST_TEST(1 == duk_get_int(plugin_->context(), -1)); | |
66 BOOST_TEST(duk_get_global_string(plugin_->context(), "name")); | |
67 BOOST_TEST("SystemError" == duk_get_string(plugin_->context(), -1)); | |
68 BOOST_TEST(duk_get_global_string(plugin_->context(), "message")); | |
69 BOOST_TEST("test" == duk_get_string(plugin_->context(), -1)); | |
70 BOOST_TEST(duk_get_global_string(plugin_->context(), "v1")); | |
71 BOOST_TEST(duk_get_boolean(plugin_->context(), -1)); | |
72 BOOST_TEST(duk_get_global_string(plugin_->context(), "v2")); | |
73 BOOST_TEST(duk_get_boolean(plugin_->context(), -1)); | |
74 } | |
75 | |
76 BOOST_AUTO_TEST_CASE(from_native) | |
77 { | |
78 duk_push_c_function(plugin_->context(), [] (duk_context *ctx) -> duk_ret_t { | |
79 dukx_throw(ctx, system_error(EINVAL, "hey")); | |
80 | |
81 return 0; | |
82 }, 0); | |
83 | |
84 duk_put_global_string(plugin_->context(), "f"); | |
85 | |
86 auto ret = duk_peval_string(plugin_->context(), | |
87 "try {" | |
88 " f();" | |
89 "} catch (e) {" | |
90 " errno = e.errno;" | |
91 " name = e.name;" | |
92 " message = e.message;" | |
93 " v1 = (e instanceof Error);" | |
94 " v2 = (e instanceof Irccd.SystemError);" | |
95 "}" | |
96 ); | |
97 | |
98 if (ret != 0) | |
99 throw dukx_stack(plugin_->context(), -1); | |
100 | |
101 BOOST_TEST(duk_get_global_string(plugin_->context(), "errno")); | |
102 BOOST_TEST(EINVAL == duk_get_int(plugin_->context(), -1)); | |
103 BOOST_TEST(duk_get_global_string(plugin_->context(), "name")); | |
104 BOOST_TEST("SystemError" == duk_get_string(plugin_->context(), -1)); | |
105 BOOST_TEST(duk_get_global_string(plugin_->context(), "message")); | |
106 BOOST_TEST("hey" == duk_get_string(plugin_->context(), -1)); | |
107 BOOST_TEST(duk_get_global_string(plugin_->context(), "v1")); | |
108 BOOST_TEST(duk_get_boolean(plugin_->context(), -1)); | |
109 BOOST_TEST(duk_get_global_string(plugin_->context(), "v2")); | |
110 BOOST_TEST(duk_get_boolean(plugin_->context(), -1)); | |
111 } | |
112 | |
113 BOOST_AUTO_TEST_SUITE_END() | |
114 | |
115 } // !irccd |