Mercurial > malikania
comparison tests/libclient/js-size/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 |
---|---|
23 | 23 |
24 using namespace mlk; | 24 using namespace mlk; |
25 | 25 |
26 class test_size { | 26 class test_size { |
27 protected: | 27 protected: |
28 UniqueContext m_ctx; | 28 dukx_context m_ctx; |
29 | 29 |
30 public: | 30 public: |
31 test_size() | 31 test_size() |
32 { | 32 { |
33 duk_push_object(m_ctx); | 33 duk_push_object(m_ctx); |
53 "w = s.width;" | 53 "w = s.width;" |
54 "h = s.height;" | 54 "h = s.height;" |
55 ); | 55 ); |
56 | 56 |
57 if (ret != 0) { | 57 if (ret != 0) { |
58 throw dukx_exception(m_ctx, -1); | 58 throw dukx_get_exception(m_ctx, -1); |
59 } | 59 } |
60 | 60 |
61 duk_get_global_string(m_ctx, "w"); | 61 duk_get_global_string(m_ctx, "w"); |
62 BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); | 62 BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); |
63 duk_pop(m_ctx); | 63 duk_pop(m_ctx); |
77 "w = s.width;" | 77 "w = s.width;" |
78 "h = s.height;" | 78 "h = s.height;" |
79 ); | 79 ); |
80 | 80 |
81 if (ret != 0) { | 81 if (ret != 0) { |
82 throw dukx_exception(m_ctx, -1); | 82 throw dukx_get_exception(m_ctx, -1); |
83 } | 83 } |
84 | 84 |
85 duk_get_global_string(m_ctx, "w"); | 85 duk_get_global_string(m_ctx, "w"); |
86 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); | 86 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); |
87 duk_pop(m_ctx); | 87 duk_pop(m_ctx); |
101 "w = s.width;" | 101 "w = s.width;" |
102 "h = s.height;" | 102 "h = s.height;" |
103 ); | 103 ); |
104 | 104 |
105 if (ret != 0) { | 105 if (ret != 0) { |
106 throw dukx_exception(m_ctx, -1); | 106 throw dukx_get_exception(m_ctx, -1); |
107 } | 107 } |
108 | 108 |
109 duk_get_global_string(m_ctx, "w"); | 109 duk_get_global_string(m_ctx, "w"); |
110 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); | 110 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); |
111 duk_pop(m_ctx); | 111 duk_pop(m_ctx); |
125 "w = s.width;" | 125 "w = s.width;" |
126 "h = s.height;" | 126 "h = s.height;" |
127 ); | 127 ); |
128 | 128 |
129 if (ret != 0) { | 129 if (ret != 0) { |
130 throw dukx_exception(m_ctx, -1); | 130 throw dukx_get_exception(m_ctx, -1); |
131 } | 131 } |
132 | 132 |
133 duk_get_global_string(m_ctx, "w"); | 133 duk_get_global_string(m_ctx, "w"); |
134 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); | 134 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); |
135 duk_pop(m_ctx); | 135 duk_pop(m_ctx); |
161 " correct = (e instanceof TypeError);" | 161 " correct = (e instanceof TypeError);" |
162 "}" | 162 "}" |
163 ); | 163 ); |
164 | 164 |
165 if (ret != 0) { | 165 if (ret != 0) { |
166 throw dukx_exception(m_ctx, -1); | 166 throw dukx_get_exception(m_ctx, -1); |
167 } | 167 } |
168 | 168 |
169 duk_get_global_string(m_ctx, "name"); | 169 duk_get_global_string(m_ctx, "name"); |
170 BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); | 170 BOOST_REQUIRE_EQUAL("TypeError", duk_to_string(m_ctx, -1)); |
171 duk_pop(m_ctx); | 171 duk_pop(m_ctx); |
188 " correct = (e instanceof RangeError);" | 188 " correct = (e instanceof RangeError);" |
189 "}" | 189 "}" |
190 ); | 190 ); |
191 | 191 |
192 if (ret != 0) { | 192 if (ret != 0) { |
193 throw dukx_exception(m_ctx, -1); | 193 throw dukx_get_exception(m_ctx, -1); |
194 } | 194 } |
195 | 195 |
196 duk_get_global_string(m_ctx, "name"); | 196 duk_get_global_string(m_ctx, "name"); |
197 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); | 197 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); |
198 duk_pop(m_ctx); | 198 duk_pop(m_ctx); |
215 " correct = (e instanceof RangeError);" | 215 " correct = (e instanceof RangeError);" |
216 "}" | 216 "}" |
217 ); | 217 ); |
218 | 218 |
219 if (ret != 0) { | 219 if (ret != 0) { |
220 throw dukx_exception(m_ctx, -1); | 220 throw dukx_get_exception(m_ctx, -1); |
221 } | 221 } |
222 | 222 |
223 duk_get_global_string(m_ctx, "name"); | 223 duk_get_global_string(m_ctx, "name"); |
224 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); | 224 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); |
225 duk_pop(m_ctx); | 225 duk_pop(m_ctx); |
242 " correct = (e instanceof RangeError);" | 242 " correct = (e instanceof RangeError);" |
243 "}" | 243 "}" |
244 ); | 244 ); |
245 | 245 |
246 if (ret != 0) { | 246 if (ret != 0) { |
247 throw dukx_exception(m_ctx, -1); | 247 throw dukx_get_exception(m_ctx, -1); |
248 } | 248 } |
249 | 249 |
250 duk_get_global_string(m_ctx, "name"); | 250 duk_get_global_string(m_ctx, "name"); |
251 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); | 251 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); |
252 duk_pop(m_ctx); | 252 duk_pop(m_ctx); |
269 " correct = (e instanceof RangeError);" | 269 " correct = (e instanceof RangeError);" |
270 "}" | 270 "}" |
271 ); | 271 ); |
272 | 272 |
273 if (ret != 0) { | 273 if (ret != 0) { |
274 throw dukx_exception(m_ctx, -1); | 274 throw dukx_get_exception(m_ctx, -1); |
275 } | 275 } |
276 | 276 |
277 duk_get_global_string(m_ctx, "name"); | 277 duk_get_global_string(m_ctx, "name"); |
278 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); | 278 BOOST_REQUIRE_EQUAL("RangeError", duk_to_string(m_ctx, -1)); |
279 duk_pop(m_ctx); | 279 duk_pop(m_ctx); |
310 duk_put_global_string(m_ctx, "build"); | 310 duk_put_global_string(m_ctx, "build"); |
311 | 311 |
312 auto ret = duk_peval_string(m_ctx, "build({ width: 100, height: 200 });"); | 312 auto ret = duk_peval_string(m_ctx, "build({ width: 100, height: 200 });"); |
313 | 313 |
314 if (ret != 0) { | 314 if (ret != 0) { |
315 throw dukx_exception(m_ctx, -1); | 315 throw dukx_get_exception(m_ctx, -1); |
316 } | 316 } |
317 | 317 |
318 duk_get_global_string(m_ctx, "w"); | 318 duk_get_global_string(m_ctx, "w"); |
319 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); | 319 BOOST_REQUIRE_EQUAL(100U, duk_to_uint(m_ctx, -1)); |
320 duk_pop(m_ctx); | 320 duk_pop(m_ctx); |
344 " correct = (e instanceof Error);" | 344 " correct = (e instanceof Error);" |
345 "}" | 345 "}" |
346 ); | 346 ); |
347 | 347 |
348 if (ret != 0) { | 348 if (ret != 0) { |
349 throw dukx_exception(m_ctx, -1); | 349 throw dukx_get_exception(m_ctx, -1); |
350 } | 350 } |
351 | 351 |
352 duk_get_global_string(m_ctx, "name"); | 352 duk_get_global_string(m_ctx, "name"); |
353 BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); | 353 BOOST_REQUIRE_EQUAL("Error", duk_to_string(m_ctx, -1)); |
354 duk_pop(m_ctx); | 354 duk_pop(m_ctx); |
385 duk_put_global_string(m_ctx, "build"); | 385 duk_put_global_string(m_ctx, "build"); |
386 | 386 |
387 auto ret = duk_peval_string(m_ctx, "build({});"); | 387 auto ret = duk_peval_string(m_ctx, "build({});"); |
388 | 388 |
389 if (ret != 0) { | 389 if (ret != 0) { |
390 throw dukx_exception(m_ctx, -1); | 390 throw dukx_get_exception(m_ctx, -1); |
391 } | 391 } |
392 | 392 |
393 duk_get_global_string(m_ctx, "w"); | 393 duk_get_global_string(m_ctx, "w"); |
394 BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); | 394 BOOST_REQUIRE_EQUAL(0U, duk_to_uint(m_ctx, -1)); |
395 duk_pop(m_ctx); | 395 duk_pop(m_ctx); |