comparison tests/src/libirccd-js/js-api-irccd/main.cpp @ 773:8c44bbcbbab9

Misc: style, cleanup and update
author David Demelier <markand@malikania.fr>
date Fri, 26 Oct 2018 13:01:00 +0200
parents 35c1517d705d
children 06cc2f95f479
comparison
equal deleted inserted replaced
772:f5ccf65ae929 773:8c44bbcbbab9
30 30
31 BOOST_FIXTURE_TEST_SUITE(irccd_js_api_suite, js_fixture) 31 BOOST_FIXTURE_TEST_SUITE(irccd_js_api_suite, js_fixture)
32 32
33 BOOST_AUTO_TEST_CASE(version) 33 BOOST_AUTO_TEST_CASE(version)
34 { 34 {
35 const auto ret = duk_peval_string(plugin_->get_context(), 35 const auto ret = duk_peval_string(plugin_->get_context(),
36 "major = Irccd.version.major;" 36 "major = Irccd.version.major;"
37 "minor = Irccd.version.minor;" 37 "minor = Irccd.version.minor;"
38 "patch = Irccd.version.patch;" 38 "patch = Irccd.version.patch;"
39 ); 39 );
40 40
41 if (ret != 0) 41 if (ret != 0)
42 throw duk::get_stack(plugin_->get_context(), -1); 42 throw duk::get_stack(plugin_->get_context(), -1);
43 43
44 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "major")); 44 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "major"));
45 BOOST_TEST(IRCCD_VERSION_MAJOR == duk_get_int(plugin_->get_context(), -1)); 45 BOOST_TEST(IRCCD_VERSION_MAJOR == duk_get_int(plugin_->get_context(), -1));
46 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "minor")); 46 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "minor"));
47 BOOST_TEST(IRCCD_VERSION_MINOR == duk_get_int(plugin_->get_context(), -1)); 47 BOOST_TEST(IRCCD_VERSION_MINOR == duk_get_int(plugin_->get_context(), -1));
48 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "patch")); 48 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "patch"));
49 BOOST_TEST(IRCCD_VERSION_PATCH == duk_get_int(plugin_->get_context(), -1)); 49 BOOST_TEST(IRCCD_VERSION_PATCH == duk_get_int(plugin_->get_context(), -1));
50 } 50 }
51 51
52 BOOST_AUTO_TEST_CASE(from_javascript) 52 BOOST_AUTO_TEST_CASE(from_javascript)
53 { 53 {
54 const auto ret = duk_peval_string(plugin_->get_context(), 54 const auto ret = duk_peval_string(plugin_->get_context(),
55 "try {" 55 "try {"
56 " throw new Irccd.SystemError(1, 'test');" 56 " throw new Irccd.SystemError(1, 'test');"
57 "} catch (e) {" 57 "} catch (e) {"
58 " errno = e.errno;" 58 " errno = e.errno;"
59 " name = e.name;" 59 " name = e.name;"
60 " message = e.message;" 60 " message = e.message;"
61 " v1 = (e instanceof Error);" 61 " v1 = (e instanceof Error);"
62 " v2 = (e instanceof Irccd.SystemError);" 62 " v2 = (e instanceof Irccd.SystemError);"
63 "}" 63 "}"
64 ); 64 );
65 65
66 if (ret != 0) 66 if (ret != 0)
67 throw duk::get_stack(plugin_->get_context(), -1); 67 throw duk::get_stack(plugin_->get_context(), -1);
68 68
69 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "errno")); 69 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "errno"));
70 BOOST_TEST(1 == duk_get_int(plugin_->get_context(), -1)); 70 BOOST_TEST(1 == duk_get_int(plugin_->get_context(), -1));
71 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name")); 71 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
72 BOOST_TEST("SystemError" == duk_get_string(plugin_->get_context(), -1)); 72 BOOST_TEST("SystemError" == duk_get_string(plugin_->get_context(), -1));
73 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message")); 73 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "message"));
74 BOOST_TEST("test" == duk_get_string(plugin_->get_context(), -1)); 74 BOOST_TEST("test" == duk_get_string(plugin_->get_context(), -1));
75 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v1")); 75 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v1"));
76 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1)); 76 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1));
77 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v2")); 77 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v2"));
78 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1)); 78 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1));
79 } 79 }
80 80
81 BOOST_AUTO_TEST_CASE(from_native) 81 BOOST_AUTO_TEST_CASE(from_native)
82 { 82 {
83 duk_push_c_function(plugin_->get_context(), [] (duk_context *ctx) -> duk_ret_t { 83 duk_push_c_function(plugin_->get_context(), [] (duk_context *ctx) -> duk_ret_t {
84 duk::raise(ctx, std::system_error(make_error_code(std::errc::invalid_argument))); 84 duk::raise(ctx, std::system_error(make_error_code(std::errc::invalid_argument)));
85 85
86 return 0; 86 return 0;
87 }, 0); 87 }, 0);
88 88
89 duk_put_global_string(plugin_->get_context(), "f"); 89 duk_put_global_string(plugin_->get_context(), "f");
90 90
91 const auto ret = duk_peval_string(plugin_->get_context(), 91 const auto ret = duk_peval_string(plugin_->get_context(),
92 "try {" 92 "try {"
93 " f();" 93 " f();"
94 "} catch (e) {" 94 "} catch (e) {"
95 " errno = e.errno;" 95 " errno = e.errno;"
96 " name = e.name;" 96 " name = e.name;"
97 " v1 = (e instanceof Error);" 97 " v1 = (e instanceof Error);"
98 " v2 = (e instanceof Irccd.SystemError);" 98 " v2 = (e instanceof Irccd.SystemError);"
99 "}" 99 "}"
100 ); 100 );
101 101
102 if (ret != 0) 102 if (ret != 0)
103 throw duk::get_stack(plugin_->get_context(), -1); 103 throw duk::get_stack(plugin_->get_context(), -1);
104 104
105 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "errno")); 105 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "errno"));
106 BOOST_TEST(EINVAL == duk_get_int(plugin_->get_context(), -1)); 106 BOOST_TEST(EINVAL == duk_get_int(plugin_->get_context(), -1));
107 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name")); 107 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "name"));
108 BOOST_TEST("SystemError" == duk_get_string(plugin_->get_context(), -1)); 108 BOOST_TEST("SystemError" == duk_get_string(plugin_->get_context(), -1));
109 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v1")); 109 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v1"));
110 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1)); 110 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1));
111 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v2")); 111 BOOST_TEST(duk_get_global_string(plugin_->get_context(), "v2"));
112 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1)); 112 BOOST_TEST(duk_get_boolean(plugin_->get_context(), -1));
113 } 113 }
114 114
115 BOOST_AUTO_TEST_SUITE_END() 115 BOOST_AUTO_TEST_SUITE_END()
116 116
117 } // !namespace 117 } // !namespace