comparison tests/libclient/js-point/main.cpp @ 63:96ba0c5cf893

Misc: update duktape.hpp to new style
author David Demelier <markand@malikania.fr>
date Fri, 16 Dec 2016 16:11:24 +0100
parents fe7e3524e571
children 858621081b95
comparison
equal deleted inserted replaced
62:a0081be977b5 63:96ba0c5cf893
21 21
22 #include <malikania/js_point.hpp> 22 #include <malikania/js_point.hpp>
23 23
24 class test_point { 24 class test_point {
25 protected: 25 protected:
26 UniqueContext m_ctx; 26 dukx_context m_ctx;
27 27
28 public: 28 public:
29 test_point() 29 test_point()
30 { 30 {
31 duk_push_object(m_ctx); 31 duk_push_object(m_ctx);
51 "x = p.x;" 51 "x = p.x;"
52 "y = p.y;" 52 "y = p.y;"
53 ); 53 );
54 54
55 if (ret != 0) { 55 if (ret != 0) {
56 throw dukx_exception(m_ctx, -1); 56 throw dukx_get_exception(m_ctx, -1);
57 } 57 }
58 58
59 duk_get_global_string(m_ctx, "x"); 59 duk_get_global_string(m_ctx, "x");
60 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); 60 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1));
61 duk_pop(m_ctx); 61 duk_pop(m_ctx);
75 "x = p.x;" 75 "x = p.x;"
76 "y = p.y;" 76 "y = p.y;"
77 ); 77 );
78 78
79 if (ret != 0) { 79 if (ret != 0) {
80 throw dukx_exception(m_ctx, -1); 80 throw dukx_get_exception(m_ctx, -1);
81 } 81 }
82 82
83 duk_get_global_string(m_ctx, "x"); 83 duk_get_global_string(m_ctx, "x");
84 BOOST_REQUIRE_EQUAL(-10, duk_to_int(m_ctx, -1)); 84 BOOST_REQUIRE_EQUAL(-10, duk_to_int(m_ctx, -1));
85 duk_pop(m_ctx); 85 duk_pop(m_ctx);
99 "x = p.x;" 99 "x = p.x;"
100 "y = p.y;" 100 "y = p.y;"
101 ); 101 );
102 102
103 if (ret != 0) { 103 if (ret != 0) {
104 throw dukx_exception(m_ctx, -1); 104 throw dukx_get_exception(m_ctx, -1);
105 } 105 }
106 106
107 duk_get_global_string(m_ctx, "x"); 107 duk_get_global_string(m_ctx, "x");
108 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1)); 108 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1));
109 duk_pop(m_ctx); 109 duk_pop(m_ctx);
123 "x = p.x;" 123 "x = p.x;"
124 "y = p.y;" 124 "y = p.y;"
125 ); 125 );
126 126
127 if (ret != 0) { 127 if (ret != 0) {
128 throw dukx_exception(m_ctx, -1); 128 throw dukx_get_exception(m_ctx, -1);
129 } 129 }
130 130
131 duk_get_global_string(m_ctx, "x"); 131 duk_get_global_string(m_ctx, "x");
132 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1)); 132 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1));
133 duk_pop(m_ctx); 133 duk_pop(m_ctx);
159 " correct = (e instanceof TypeError);" 159 " correct = (e instanceof TypeError);"
160 "}" 160 "}"
161 ); 161 );
162 162
163 if (ret != 0) { 163 if (ret != 0) {
164 throw dukx_exception(m_ctx, -1); 164 throw dukx_get_exception(m_ctx, -1);
165 } 165 }
166 166
167 duk_get_global_string(m_ctx, "name"); 167 duk_get_global_string(m_ctx, "name");
168 BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); 168 BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1));
169 duk_pop(m_ctx); 169 duk_pop(m_ctx);
200 duk_put_global_string(m_ctx, "build"); 200 duk_put_global_string(m_ctx, "build");
201 201
202 auto ret = duk_peval_string(m_ctx, "build({ x: 100, y: 200 });"); 202 auto ret = duk_peval_string(m_ctx, "build({ x: 100, y: 200 });");
203 203
204 if (ret != 0) { 204 if (ret != 0) {
205 throw dukx_exception(m_ctx, -1); 205 throw dukx_get_exception(m_ctx, -1);
206 } 206 }
207 207
208 duk_get_global_string(m_ctx, "x"); 208 duk_get_global_string(m_ctx, "x");
209 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1)); 209 BOOST_REQUIRE_EQUAL(100, duk_to_int(m_ctx, -1));
210 duk_pop(m_ctx); 210 duk_pop(m_ctx);
234 " correct = (e instanceof Error);" 234 " correct = (e instanceof Error);"
235 "}" 235 "}"
236 ); 236 );
237 237
238 if (ret != 0) { 238 if (ret != 0) {
239 throw dukx_exception(m_ctx, -1); 239 throw dukx_get_exception(m_ctx, -1);
240 } 240 }
241 241
242 duk_get_global_string(m_ctx, "name"); 242 duk_get_global_string(m_ctx, "name");
243 BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); 243 BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1));
244 duk_pop(m_ctx); 244 duk_pop(m_ctx);
275 duk_put_global_string(m_ctx, "build"); 275 duk_put_global_string(m_ctx, "build");
276 276
277 auto ret = duk_peval_string(m_ctx, "build({});"); 277 auto ret = duk_peval_string(m_ctx, "build({});");
278 278
279 if (ret != 0) { 279 if (ret != 0) {
280 throw dukx_exception(m_ctx, -1); 280 throw dukx_get_exception(m_ctx, -1);
281 } 281 }
282 282
283 duk_get_global_string(m_ctx, "x"); 283 duk_get_global_string(m_ctx, "x");
284 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); 284 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1));
285 duk_pop(m_ctx); 285 duk_pop(m_ctx);
286 duk_get_global_string(m_ctx, "y"); 286 duk_get_global_string(m_ctx, "y");
287 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1)); 287 BOOST_REQUIRE_EQUAL(0, duk_to_int(m_ctx, -1));
288 duk_pop(m_ctx); 288 duk_pop(m_ctx);
289 } catch (const std::exception &ex) { 289 } catch (const std::exception &ex) {
290 BOOST_FAIL(ex.what()); 290 BOOST_FAIL(ex.what());
291 } 291 }
292 } 292 }
293 293
294 BOOST_AUTO_TEST_SUITE_END() 294 BOOST_AUTO_TEST_SUITE_END()
295 295
296 BOOST_AUTO_TEST_SUITE_END() 296 BOOST_AUTO_TEST_SUITE_END()