comparison tests/js-irccd/main.cpp @ 207:6635b9187d71

Irccd: switch to 4 spaces indent, #518
author David Demelier <markand@malikania.fr>
date Tue, 21 Jun 2016 20:52:17 +0200
parents bdeda4baf684
children 79d9840811a1
comparison
equal deleted inserted replaced
206:11808e98218f 207:6635b9187d71
26 26
27 using namespace irccd; 27 using namespace irccd;
28 28
29 class TestJsIrccd : public testing::Test { 29 class TestJsIrccd : public testing::Test {
30 protected: 30 protected:
31 Irccd m_irccd; 31 Irccd m_irccd;
32 std::shared_ptr<JsPlugin> m_plugin; 32 std::shared_ptr<JsPlugin> m_plugin;
33 33
34 TestJsIrccd() 34 TestJsIrccd()
35 : m_plugin(std::make_shared<JsPlugin>("empty", SOURCEDIR "/empty.js")) 35 : m_plugin(std::make_shared<JsPlugin>("empty", SOURCEDIR "/empty.js"))
36 { 36 {
37 m_irccd.moduleService().get("Irccd")->load(m_irccd, m_plugin); 37 m_irccd.moduleService().get("Irccd")->load(m_irccd, m_plugin);
38 } 38 }
39 }; 39 };
40 40
41 TEST_F(TestJsIrccd, version) 41 TEST_F(TestJsIrccd, version)
42 { 42 {
43 try { 43 try {
44 auto ret = duk_peval_string(m_plugin->context(), 44 auto ret = duk_peval_string(m_plugin->context(),
45 "major = Irccd.version.major;" 45 "major = Irccd.version.major;"
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 dukx_exception(m_plugin->context(), -1); 51 throw dukx_exception(m_plugin->context(), -1);
52 52
53 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "major")); 53 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "major"));
54 ASSERT_EQ(IRCCD_VERSION_MAJOR, duk_get_int(m_plugin->context(), -1)); 54 ASSERT_EQ(IRCCD_VERSION_MAJOR, duk_get_int(m_plugin->context(), -1));
55 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "minor")); 55 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "minor"));
56 ASSERT_EQ(IRCCD_VERSION_MINOR, duk_get_int(m_plugin->context(), -1)); 56 ASSERT_EQ(IRCCD_VERSION_MINOR, duk_get_int(m_plugin->context(), -1));
57 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "patch")); 57 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "patch"));
58 ASSERT_EQ(IRCCD_VERSION_PATCH, duk_get_int(m_plugin->context(), -1)); 58 ASSERT_EQ(IRCCD_VERSION_PATCH, duk_get_int(m_plugin->context(), -1));
59 } catch (const std::exception &ex) { 59 } catch (const std::exception &ex) {
60 FAIL() << ex.what(); 60 FAIL() << ex.what();
61 } 61 }
62 } 62 }
63 63
64 TEST_F(TestJsIrccd, fromJavascript) 64 TEST_F(TestJsIrccd, fromJavascript)
65 { 65 {
66 try { 66 try {
67 auto ret = duk_peval_string(m_plugin->context(), 67 auto ret = duk_peval_string(m_plugin->context(),
68 "try {" 68 "try {"
69 " throw new Irccd.SystemError(1, 'test');" 69 " throw new Irccd.SystemError(1, 'test');"
70 "} catch (e) {" 70 "} catch (e) {"
71 " errno = e.errno;" 71 " errno = e.errno;"
72 " name = e.name;" 72 " name = e.name;"
73 " message = e.message;" 73 " message = e.message;"
74 " v1 = (e instanceof Error);" 74 " v1 = (e instanceof Error);"
75 " v2 = (e instanceof Irccd.SystemError);" 75 " v2 = (e instanceof Irccd.SystemError);"
76 "}" 76 "}"
77 ); 77 );
78 78
79 if (ret != 0) 79 if (ret != 0)
80 throw dukx_exception(m_plugin->context(), -1); 80 throw dukx_exception(m_plugin->context(), -1);
81 81
82 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "errno")); 82 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "errno"));
83 ASSERT_EQ(1, duk_get_int(m_plugin->context(), -1)); 83 ASSERT_EQ(1, duk_get_int(m_plugin->context(), -1));
84 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "name")); 84 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "name"));
85 ASSERT_STREQ("SystemError", duk_get_string(m_plugin->context(), -1)); 85 ASSERT_STREQ("SystemError", duk_get_string(m_plugin->context(), -1));
86 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "message")); 86 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "message"));
87 ASSERT_STREQ("test", duk_get_string(m_plugin->context(), -1)); 87 ASSERT_STREQ("test", duk_get_string(m_plugin->context(), -1));
88 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v1")); 88 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v1"));
89 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1)); 89 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1));
90 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v2")); 90 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v2"));
91 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1)); 91 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1));
92 } catch (const std::exception &ex) { 92 } catch (const std::exception &ex) {
93 FAIL() << ex.what(); 93 FAIL() << ex.what();
94 } 94 }
95 } 95 }
96 96
97 TEST_F(TestJsIrccd, fromNative) 97 TEST_F(TestJsIrccd, fromNative)
98 { 98 {
99 try { 99 try {
100 duk_push_c_function(m_plugin->context(), [] (duk_context *ctx) -> duk_ret_t { 100 duk_push_c_function(m_plugin->context(), [] (duk_context *ctx) -> duk_ret_t {
101 dukx_throw(ctx, SystemError(EINVAL, "hey")); 101 dukx_throw(ctx, SystemError(EINVAL, "hey"));
102 102
103 return 0; 103 return 0;
104 }, 0); 104 }, 0);
105 105
106 duk_put_global_string(m_plugin->context(), "f"); 106 duk_put_global_string(m_plugin->context(), "f");
107 107
108 auto ret = duk_peval_string(m_plugin->context(), 108 auto ret = duk_peval_string(m_plugin->context(),
109 "try {" 109 "try {"
110 " f();" 110 " f();"
111 "} catch (e) {" 111 "} catch (e) {"
112 " errno = e.errno;" 112 " errno = e.errno;"
113 " name = e.name;" 113 " name = e.name;"
114 " message = e.message;" 114 " message = e.message;"
115 " v1 = (e instanceof Error);" 115 " v1 = (e instanceof Error);"
116 " v2 = (e instanceof Irccd.SystemError);" 116 " v2 = (e instanceof Irccd.SystemError);"
117 "}" 117 "}"
118 ); 118 );
119 119
120 if (ret != 0) 120 if (ret != 0)
121 throw dukx_exception(m_plugin->context(), -1); 121 throw dukx_exception(m_plugin->context(), -1);
122 122
123 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "errno")); 123 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "errno"));
124 ASSERT_EQ(EINVAL, duk_get_int(m_plugin->context(), -1)); 124 ASSERT_EQ(EINVAL, duk_get_int(m_plugin->context(), -1));
125 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "name")); 125 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "name"));
126 ASSERT_STREQ("SystemError", duk_get_string(m_plugin->context(), -1)); 126 ASSERT_STREQ("SystemError", duk_get_string(m_plugin->context(), -1));
127 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "message")); 127 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "message"));
128 ASSERT_STREQ("hey", duk_get_string(m_plugin->context(), -1)); 128 ASSERT_STREQ("hey", duk_get_string(m_plugin->context(), -1));
129 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v1")); 129 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v1"));
130 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1)); 130 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1));
131 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v2")); 131 ASSERT_TRUE(duk_get_global_string(m_plugin->context(), "v2"));
132 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1)); 132 ASSERT_TRUE(duk_get_boolean(m_plugin->context(), -1));
133 } catch (const std::exception &ex) { 133 } catch (const std::exception &ex) {
134 FAIL() << ex.what(); 134 FAIL() << ex.what();
135 } 135 }
136 } 136 }
137 137
138 int main(int argc, char **argv) 138 int main(int argc, char **argv)
139 { 139 {
140 testing::InitGoogleTest(&argc, argv); 140 testing::InitGoogleTest(&argc, argv);
141 141
142 return RUN_ALL_TESTS(); 142 return RUN_ALL_TESTS();
143 } 143 }