comparison tests/js-irccd/main.cpp @ 179:ef527409e638

Irccd: update JavaScript code
author David Demelier <markand@malikania.fr>
date Tue, 31 May 2016 21:03:01 +0200
parents f2099005b23d
children cb61cc16e2b6
comparison
equal deleted inserted replaced
178:084081b24024 179:ef527409e638
46 "minor = Irccd.version.minor;" 46 "minor = Irccd.version.minor;"
47 "patch = Irccd.version.patch;" 47 "patch = Irccd.version.patch;"
48 ); 48 );
49 49
50 if (ret != 0) 50 if (ret != 0)
51 throw duk::error(m_plugin->context(), -1); 51 throw duk::exception(m_plugin->context(), -1);
52 52
53 ASSERT_EQ(IRCCD_VERSION_MAJOR, duk::getGlobal<int>(m_plugin->context(), "major")); 53 ASSERT_EQ(IRCCD_VERSION_MAJOR, duk::getGlobal<int>(m_plugin->context(), "major"));
54 ASSERT_EQ(IRCCD_VERSION_MINOR, duk::getGlobal<int>(m_plugin->context(), "minor")); 54 ASSERT_EQ(IRCCD_VERSION_MINOR, duk::getGlobal<int>(m_plugin->context(), "minor"));
55 ASSERT_EQ(IRCCD_VERSION_PATCH, duk::getGlobal<int>(m_plugin->context(), "patch")); 55 ASSERT_EQ(IRCCD_VERSION_PATCH, duk::getGlobal<int>(m_plugin->context(), "patch"));
56 } catch (const std::exception &ex) { 56 } catch (const std::exception &ex) {
72 " v2 = (e instanceof Irccd.SystemError);" 72 " v2 = (e instanceof Irccd.SystemError);"
73 "}" 73 "}"
74 ); 74 );
75 75
76 if (ret != 0) 76 if (ret != 0)
77 throw duk::error(m_plugin->context(), -1); 77 throw duk::exception(m_plugin->context(), -1);
78 78
79 ASSERT_EQ(1, duk::getGlobal<int>(m_plugin->context(), "errno")); 79 ASSERT_EQ(1, duk::getGlobal<int>(m_plugin->context(), "errno"));
80 ASSERT_EQ("SystemError", duk::getGlobal<std::string>(m_plugin->context(), "name")); 80 ASSERT_EQ("SystemError", duk::getGlobal<std::string>(m_plugin->context(), "name"));
81 ASSERT_EQ("test", duk::getGlobal<std::string>(m_plugin->context(), "message")); 81 ASSERT_EQ("test", duk::getGlobal<std::string>(m_plugin->context(), "message"));
82 ASSERT_TRUE(duk::getGlobal<bool>(m_plugin->context(), "v1")); 82 ASSERT_TRUE(duk::getGlobal<bool>(m_plugin->context(), "v1"));
87 } 87 }
88 88
89 TEST_F(TestJsIrccd, fromNative) 89 TEST_F(TestJsIrccd, fromNative)
90 { 90 {
91 try { 91 try {
92 duk::push(m_plugin->context(), duk::Function{[] (duk::ContextPtr ctx) -> duk::Ret { 92 duk::push(m_plugin->context(), duk::Function{[] (duk::Context *ctx) -> duk::Ret {
93 duk::raise(ctx, SystemError{EINVAL, "hey"}); 93 duk::raise(ctx, SystemError{EINVAL, "hey"});
94 94
95 return 0; 95 return 0;
96 }}); 96 }});
97 97
108 " v2 = (e instanceof Irccd.SystemError);" 108 " v2 = (e instanceof Irccd.SystemError);"
109 "}" 109 "}"
110 ); 110 );
111 111
112 if (ret != 0) 112 if (ret != 0)
113 throw duk::error(m_plugin->context(), -1); 113 throw duk::exception(m_plugin->context(), -1);
114 114
115 ASSERT_EQ(EINVAL, duk::getGlobal<int>(m_plugin->context(), "errno")); 115 ASSERT_EQ(EINVAL, duk::getGlobal<int>(m_plugin->context(), "errno"));
116 ASSERT_EQ("SystemError", duk::getGlobal<std::string>(m_plugin->context(), "name")); 116 ASSERT_EQ("SystemError", duk::getGlobal<std::string>(m_plugin->context(), "name"));
117 ASSERT_EQ("hey", duk::getGlobal<std::string>(m_plugin->context(), "message")); 117 ASSERT_EQ("hey", duk::getGlobal<std::string>(m_plugin->context(), "message"));
118 ASSERT_TRUE(duk::getGlobal<bool>(m_plugin->context(), "v1")); 118 ASSERT_TRUE(duk::getGlobal<bool>(m_plugin->context(), "v1"));