comparison tests/libclient/js-line/main.cpp @ 42:a47a4477f347

Misc: new style, closes #578
author David Demelier <markand@malikania.fr>
date Tue, 29 Nov 2016 21:21:36 +0100
parents 9af360f34c7d
children fabbe1759cec
comparison
equal deleted inserted replaced
41:3645200f46bf 42:a47a4477f347
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include <gtest/gtest.h> 19 #include <gtest/gtest.h>
20 20
21 #include <malikania/js-line.hpp> 21 #include <malikania/js_line.hpp>
22 22
23 using namespace malikania; 23 using namespace malikania;
24 24
25 class TestLine : public testing::Test { 25 class TestLine : public testing::Test {
26 protected: 26 protected:
49 "y1 = r.y1;" 49 "y1 = r.y1;"
50 "x2 = r.x2;" 50 "x2 = r.x2;"
51 "y2 = r.y2;" 51 "y2 = r.y2;"
52 ); 52 );
53 53
54 if (ret != 0) 54 if (ret != 0) {
55 throw dukx_exception(m_ctx, -1); 55 throw dukx_exception(m_ctx, -1);
56 }
56 57
57 duk_get_global_string(m_ctx, "x1"); 58 duk_get_global_string(m_ctx, "x1");
58 ASSERT_EQ(0, duk_to_int(m_ctx, -1)); 59 ASSERT_EQ(0, duk_to_int(m_ctx, -1));
59 duk_pop(m_ctx); 60 duk_pop(m_ctx);
60 duk_get_global_string(m_ctx, "y1"); 61 duk_get_global_string(m_ctx, "y1");
80 "y1 = r.y1;" 81 "y1 = r.y1;"
81 "x2 = r.x2;" 82 "x2 = r.x2;"
82 "y2 = r.y2;" 83 "y2 = r.y2;"
83 ); 84 );
84 85
85 if (ret != 0) 86 if (ret != 0) {
86 throw dukx_exception(m_ctx, -1); 87 throw dukx_exception(m_ctx, -1);
88 }
87 89
88 duk_get_global_string(m_ctx, "x1"); 90 duk_get_global_string(m_ctx, "x1");
89 ASSERT_EQ(10, duk_to_int(m_ctx, -1)); 91 ASSERT_EQ(10, duk_to_int(m_ctx, -1));
90 duk_pop(m_ctx); 92 duk_pop(m_ctx);
91 duk_get_global_string(m_ctx, "y1"); 93 duk_get_global_string(m_ctx, "y1");
111 "y1 = r.y1;" 113 "y1 = r.y1;"
112 "x2 = r.x2;" 114 "x2 = r.x2;"
113 "y2 = r.y2;" 115 "y2 = r.y2;"
114 ); 116 );
115 117
116 if (ret != 0) 118 if (ret != 0) {
117 throw dukx_exception(m_ctx, -1); 119 throw dukx_exception(m_ctx, -1);
120 }
118 121
119 duk_get_global_string(m_ctx, "x1"); 122 duk_get_global_string(m_ctx, "x1");
120 ASSERT_EQ(10, duk_to_int(m_ctx, -1)); 123 ASSERT_EQ(10, duk_to_int(m_ctx, -1));
121 duk_pop(m_ctx); 124 duk_pop(m_ctx);
122 duk_get_global_string(m_ctx, "y1"); 125 duk_get_global_string(m_ctx, "y1");
142 "y1 = r.y1;" 145 "y1 = r.y1;"
143 "x2 = r.x2;" 146 "x2 = r.x2;"
144 "y2 = r.y2;" 147 "y2 = r.y2;"
145 ); 148 );
146 149
147 if (ret != 0) 150 if (ret != 0) {
148 throw dukx_exception(m_ctx, -1); 151 throw dukx_exception(m_ctx, -1);
152 }
149 153
150 duk_get_global_string(m_ctx, "x1"); 154 duk_get_global_string(m_ctx, "x1");
151 ASSERT_EQ(10, duk_to_int(m_ctx, -1)); 155 ASSERT_EQ(10, duk_to_int(m_ctx, -1));
152 duk_pop(m_ctx); 156 duk_pop(m_ctx);
153 duk_get_global_string(m_ctx, "y1"); 157 duk_get_global_string(m_ctx, "y1");
179 " name = e.name;" 183 " name = e.name;"
180 " correct = (e instanceof TypeError);" 184 " correct = (e instanceof TypeError);"
181 "}" 185 "}"
182 ); 186 );
183 187
184 if (ret != 0) 188 if (ret != 0) {
185 throw dukx_exception(m_ctx, -1); 189 throw dukx_exception(m_ctx, -1);
190 }
186 191
187 duk_get_global_string(m_ctx, "name"); 192 duk_get_global_string(m_ctx, "name");
188 ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1)); 193 ASSERT_STREQ("TypeError", duk_to_string(m_ctx, -1));
189 duk_pop(m_ctx); 194 duk_pop(m_ctx);
190 duk_get_global_string(m_ctx, "correct"); 195 duk_get_global_string(m_ctx, "correct");
202 207
203 TEST_F(TestLine, requireSuccess) 208 TEST_F(TestLine, requireSuccess)
204 { 209 {
205 try { 210 try {
206 duk_push_c_function(m_ctx, [] (auto ctx) { 211 duk_push_c_function(m_ctx, [] (auto ctx) {
207 Line line = dukx_require_line(ctx, 0); 212 auto line = dukx_require_line(ctx, 0);
208 213
209 duk_push_int(ctx, line.x1()); 214 duk_push_int(ctx, line.x1());
210 duk_put_global_string(ctx, "x1"); 215 duk_put_global_string(ctx, "x1");
211 duk_push_int(ctx, line.y1()); 216 duk_push_int(ctx, line.y1());
212 duk_put_global_string(ctx, "y1"); 217 duk_put_global_string(ctx, "y1");
219 }, 1); 224 }, 1);
220 duk_put_global_string(m_ctx, "build"); 225 duk_put_global_string(m_ctx, "build");
221 226
222 auto ret = duk_peval_string(m_ctx, "build({ x1: 50, y1: 80, x2: 100, y2: 200 });"); 227 auto ret = duk_peval_string(m_ctx, "build({ x1: 50, y1: 80, x2: 100, y2: 200 });");
223 228
224 if (ret != 0) 229 if (ret != 0) {
225 throw dukx_exception(m_ctx, -1); 230 throw dukx_exception(m_ctx, -1);
231 }
226 232
227 duk_get_global_string(m_ctx, "x1"); 233 duk_get_global_string(m_ctx, "x1");
228 ASSERT_EQ(50, duk_to_int(m_ctx, -1)); 234 ASSERT_EQ(50, duk_to_int(m_ctx, -1));
229 duk_pop(m_ctx); 235 duk_pop(m_ctx);
230 duk_get_global_string(m_ctx, "y1"); 236 duk_get_global_string(m_ctx, "y1");
258 " name = e.name;" 264 " name = e.name;"
259 " correct = (e instanceof Error);" 265 " correct = (e instanceof Error);"
260 "}" 266 "}"
261 ); 267 );
262 268
263 if (ret != 0) 269 if (ret != 0) {
264 throw dukx_exception(m_ctx, -1); 270 throw dukx_exception(m_ctx, -1);
271 }
265 272
266 duk_get_global_string(m_ctx, "name"); 273 duk_get_global_string(m_ctx, "name");
267 ASSERT_STREQ("Error", duk_to_string(m_ctx, -1)); 274 ASSERT_STREQ("Error", duk_to_string(m_ctx, -1));
268 duk_pop(m_ctx); 275 duk_pop(m_ctx);
269 duk_get_global_string(m_ctx, "correct"); 276 duk_get_global_string(m_ctx, "correct");
281 288
282 TEST_F(TestLine, getAdjustAll) 289 TEST_F(TestLine, getAdjustAll)
283 { 290 {
284 try { 291 try {
285 duk_push_c_function(m_ctx, [] (auto ctx) { 292 duk_push_c_function(m_ctx, [] (auto ctx) {
286 Line line = dukx_get_line(ctx, 0); 293 auto line = dukx_get_line(ctx, 0);
287 294
288 duk_push_int(ctx, line.x1()); 295 duk_push_int(ctx, line.x1());
289 duk_put_global_string(ctx, "x1"); 296 duk_put_global_string(ctx, "x1");
290 duk_push_int(ctx, line.y1()); 297 duk_push_int(ctx, line.y1());
291 duk_put_global_string(ctx, "y1"); 298 duk_put_global_string(ctx, "y1");
298 }, 1); 305 }, 1);
299 duk_put_global_string(m_ctx, "build"); 306 duk_put_global_string(m_ctx, "build");
300 307
301 auto ret = duk_peval_string(m_ctx, "build({});"); 308 auto ret = duk_peval_string(m_ctx, "build({});");
302 309
303 if (ret != 0) 310 if (ret != 0) {
304 throw dukx_exception(m_ctx, -1); 311 throw dukx_exception(m_ctx, -1);
312 }
305 313
306 duk_get_global_string(m_ctx, "x1"); 314 duk_get_global_string(m_ctx, "x1");
307 ASSERT_EQ(0, duk_to_int(m_ctx, -1)); 315 ASSERT_EQ(0, duk_to_int(m_ctx, -1));
308 duk_pop(m_ctx); 316 duk_pop(m_ctx);
309 duk_get_global_string(m_ctx, "y1"); 317 duk_get_global_string(m_ctx, "y1");