comparison tests/libmlk-client/js-color/main.cpp @ 193:209bdaa13a49

Tests: rename directories to match targets
author David Demelier <markand@malikania.fr>
date Sat, 27 Oct 2018 07:16:28 +0200
parents tests/libclient/js-color/main.cpp@f28cb6d04731
children
comparison
equal deleted inserted replaced
192:74afc5a41c83 193:209bdaa13a49
1 /*
2 * main.cpp -- test Color (JavaScript binding)
3 *
4 * Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #define BOOST_TEST_MODULE "Javascript Color"
20 #include <boost/test/unit_test.hpp>
21
22 #include <malikania/client/js/test/js_api_fixture.hpp>
23
24 namespace mlk::client {
25
26 namespace {
27
28 auto component(duk_context* ctx, const char* name) -> int
29 {
30 duk_get_global_string(ctx, name);
31 auto value = duk_require_int(ctx, -1);
32 duk_pop(ctx);
33
34 return value;
35 }
36
37 BOOST_FIXTURE_TEST_SUITE(test_color_suite, js::test::js_api_fixture)
38
39 /*
40 * Valid constructors.
41 * ------------------------------------------------------------------
42 */
43
44 BOOST_AUTO_TEST_SUITE(constructors)
45
46 BOOST_AUTO_TEST_CASE(constructor_default)
47 {
48 const auto ret = duk_peval_string(ctx_,
49 "c = Malikania.Color();"
50 "r = c.red;"
51 "g = c.green;"
52 "b = c.blue;"
53 "a = c.alpha;"
54 );
55
56 if (ret != 0)
57 throw mlk::js::duk::get_stack(ctx_, -1);
58
59 BOOST_TEST(component(ctx_, "r") == 0);
60 BOOST_TEST(component(ctx_, "g") == 0);
61 BOOST_TEST(component(ctx_, "b") == 0);
62 BOOST_TEST(component(ctx_, "a") == 255);
63 }
64
65 BOOST_AUTO_TEST_CASE(constructor_string)
66 {
67 const auto ret = duk_peval_string(ctx_,
68 "c = Malikania.Color('white');"
69 "r = c.red;"
70 "g = c.green;"
71 "b = c.blue;"
72 "a = c.alpha;"
73 );
74
75 if (ret != 0)
76 throw mlk::js::duk::get_stack(ctx_, -1);
77
78 BOOST_TEST(component(ctx_, "r") == 255);
79 BOOST_TEST(component(ctx_, "g") == 255);
80 BOOST_TEST(component(ctx_, "b") == 255);
81 BOOST_TEST(component(ctx_, "a") == 255);
82 }
83
84 BOOST_AUTO_TEST_CASE(constructor_string_rgb)
85 {
86 const auto ret = duk_peval_string(ctx_,
87 "c = Malikania.Color('#0000ff');"
88 "r = c.red;"
89 "g = c.green;"
90 "b = c.blue;"
91 "a = c.alpha;"
92 );
93
94 if (ret != 0)
95 throw mlk::js::duk::get_stack(ctx_, -1);
96
97 BOOST_TEST(component(ctx_, "r") == 0);
98 BOOST_TEST(component(ctx_, "g") == 0);
99 BOOST_TEST(component(ctx_, "b") == 255);
100 BOOST_TEST(component(ctx_, "a") == 255);
101 }
102
103 BOOST_AUTO_TEST_CASE(constructor_3_args)
104 {
105 const auto ret = duk_peval_string(ctx_,
106 "c = Malikania.Color(10, 20, 30);"
107 "r = c.red;"
108 "g = c.green;"
109 "b = c.blue;"
110 "a = c.alpha;"
111 );
112
113 if (ret != 0)
114 throw mlk::js::duk::get_stack(ctx_, -1);
115
116 BOOST_TEST(component(ctx_, "r") == 10);
117 BOOST_TEST(component(ctx_, "g") == 20);
118 BOOST_TEST(component(ctx_, "b") == 30);
119 BOOST_TEST(component(ctx_, "a") == 255);
120 }
121
122 BOOST_AUTO_TEST_CASE(constructor_4_args)
123 {
124 const auto ret = duk_peval_string(ctx_,
125 "c = Malikania.Color(10, 20, 30, 40);"
126 "r = c.red;"
127 "g = c.green;"
128 "b = c.blue;"
129 "a = c.alpha;"
130 );
131
132 if (ret != 0)
133 throw mlk::js::duk::get_stack(ctx_, -1);
134
135 BOOST_TEST(component(ctx_, "r") == 10);
136 BOOST_TEST(component(ctx_, "g") == 20);
137 BOOST_TEST(component(ctx_, "b") == 30);
138 BOOST_TEST(component(ctx_, "a") == 40);
139 }
140
141 BOOST_AUTO_TEST_CASE(constructor_object_no_alpha)
142 {
143 const auto ret = duk_peval_string(ctx_,
144 "c = Malikania.Color({ red: 10, green: 20, blue: 30 });"
145 "r = c.red;"
146 "g = c.green;"
147 "b = c.blue;"
148 "a = c.alpha;"
149 );
150
151 if (ret != 0)
152 throw mlk::js::duk::get_stack(ctx_, -1);
153
154 BOOST_TEST(component(ctx_, "r") == 10);
155 BOOST_TEST(component(ctx_, "g") == 20);
156 BOOST_TEST(component(ctx_, "b") == 30);
157 BOOST_TEST(component(ctx_, "a") == 255);
158 }
159
160 BOOST_AUTO_TEST_CASE(constructor_object_alpha)
161 {
162 const auto ret = duk_peval_string(ctx_,
163 "c = Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });"
164 "r = c.red;"
165 "g = c.green;"
166 "b = c.blue;"
167 "a = c.alpha;"
168 );
169
170 if (ret != 0)
171 throw mlk::js::duk::get_stack(ctx_, -1);
172
173 BOOST_TEST(component(ctx_, "r") == 10);
174 BOOST_TEST(component(ctx_, "g") == 20);
175 BOOST_TEST(component(ctx_, "b") == 30);
176 BOOST_TEST(component(ctx_, "a") == 40);
177 }
178
179 BOOST_AUTO_TEST_CASE(constructor_new)
180 {
181 /*
182 * Just one test, function parse the same way, only 'this' or a new
183 * object is returned.
184 */
185 const auto ret = duk_peval_string(ctx_,
186 "c = new Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 40 });"
187 "r = c.red;"
188 "g = c.green;"
189 "b = c.blue;"
190 "a = c.alpha;"
191 );
192
193 if (ret != 0)
194 throw mlk::js::duk::get_stack(ctx_, -1);
195
196 BOOST_TEST(component(ctx_, "r") == 10);
197 BOOST_TEST(component(ctx_, "g") == 20);
198 BOOST_TEST(component(ctx_, "b") == 30);
199 BOOST_TEST(component(ctx_, "a") == 40);
200 }
201
202 BOOST_AUTO_TEST_SUITE_END()
203
204 /*
205 * Invalid constructors.
206 * ------------------------------------------------------------------
207 */
208
209 BOOST_AUTO_TEST_SUITE(invalid_constructors)
210
211 BOOST_AUTO_TEST_CASE(constructor_arg_1)
212 {
213 const auto ret = duk_peval_string(ctx_,
214 "try {"
215 " Malikania.Color(null);"
216 "} catch (e) {"
217 " name = e.name;"
218 " correct = (e instanceof TypeError);"
219 "}"
220 );
221
222 if (ret != 0)
223 throw mlk::js::duk::get_stack(ctx_, -1);
224
225 duk_get_global_string(ctx_, "name");
226 BOOST_TEST(duk_to_string(ctx_, -1) == "TypeError");
227 duk_pop(ctx_);
228 duk_get_global_string(ctx_, "correct");
229 BOOST_TEST(duk_to_boolean(ctx_, -1));
230 duk_pop(ctx_);
231 }
232
233 BOOST_AUTO_TEST_CASE(constructor_arg_2)
234 {
235 const auto ret = duk_peval_string(ctx_,
236 "try {"
237 " Malikania.Color(10, null, 30);"
238 "} catch (e) {"
239 " name = e.name;"
240 " correct = (e instanceof TypeError);"
241 "}"
242 );
243
244 if (ret != 0)
245 throw mlk::js::duk::get_stack(ctx_, -1);
246
247 duk_get_global_string(ctx_, "name");
248 BOOST_TEST(duk_to_string(ctx_, -1) == "TypeError");
249 duk_pop(ctx_);
250 duk_get_global_string(ctx_, "correct");
251 BOOST_TEST(duk_to_boolean(ctx_, -1));
252 duk_pop(ctx_);
253 }
254
255 #if 0
256
257 // TODO: determine what's the best thing to do with negative values
258
259 BOOST_AUTO_TEST_CASE(constructor_range_1)
260 {
261 const auto ret = duk_peval_string(ctx_,
262 "try {"
263 " Malikania.Color(-1, 20, 30);"
264 "} catch (e) {"
265 " name = e.name;"
266 " correct = (e instanceof RangeError);"
267 "}"
268 );
269
270 if (ret != 0)
271 throw mlk::js::duk::get_stack(ctx_, -1);
272
273 duk_get_global_string(ctx_, "name");
274 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
275 duk_pop(ctx_);
276 duk_get_global_string(ctx_, "correct");
277 BOOST_TEST(duk_to_boolean(ctx_, -1));
278 duk_pop(ctx_);
279 }
280
281 BOOST_AUTO_TEST_CASE(constructor_range_2)
282 {
283 const auto ret = duk_peval_string(ctx_,
284 "try {"
285 " Malikania.Color(10, 20, 256);"
286 "} catch (e) {"
287 " name = e.name;"
288 " correct = (e instanceof RangeError);"
289 "}"
290 );
291
292 if (ret != 0)
293 throw mlk::js::duk::get_stack(ctx_, -1);
294
295 duk_get_global_string(ctx_, "name");
296 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
297 duk_pop(ctx_);
298 duk_get_global_string(ctx_, "correct");
299 BOOST_TEST(duk_to_boolean(ctx_, -1));
300 duk_pop(ctx_);
301 }
302
303 BOOST_AUTO_TEST_CASE(constructor_range_3)
304 {
305 const auto ret = duk_peval_string(ctx_,
306 "try {"
307 " Malikania.Color(10, 20, 30, 800);"
308 "} catch (e) {"
309 " name = e.name;"
310 " correct = (e instanceof RangeError);"
311 "}"
312 );
313
314 if (ret != 0)
315 throw mlk::js::duk::get_stack(ctx_, -1);
316
317 duk_get_global_string(ctx_, "name");
318 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
319 duk_pop(ctx_);
320 duk_get_global_string(ctx_, "correct");
321 BOOST_TEST(duk_to_boolean(ctx_, -1));
322 duk_pop(ctx_);
323 }
324
325 BOOST_AUTO_TEST_CASE(constructor_object_range_red)
326 {
327 const auto ret = duk_peval_string(ctx_,
328 "try {"
329 " Malikania.Color({ red: -1, green: 20, blue: 30 });"
330 "} catch (e) {"
331 " name = e.name;"
332 " correct = (e instanceof RangeError);"
333 "}"
334 );
335
336 if (ret != 0)
337 throw mlk::js::duk::get_stack(ctx_, -1);
338
339 duk_get_global_string(ctx_, "name");
340 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
341 duk_pop(ctx_);
342 duk_get_global_string(ctx_, "correct");
343 BOOST_TEST(duk_to_boolean(ctx_, -1));
344 duk_pop(ctx_);
345 }
346
347 BOOST_AUTO_TEST_CASE(constructor_object_range_alpha)
348 {
349 const auto ret = duk_peval_string(ctx_,
350 "try {"
351 " Malikania.Color({ red: 10, green: 20, blue: 30, alpha: 800 });"
352 "} catch (e) {"
353 " name = e.name;"
354 " correct = (e instanceof RangeError);"
355 "}"
356 );
357
358 if (ret != 0)
359 throw mlk::js::duk::get_stack(ctx_, -1);
360
361 duk_get_global_string(ctx_, "name");
362 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
363 duk_pop(ctx_);
364 duk_get_global_string(ctx_, "correct");
365 BOOST_TEST(duk_to_boolean(ctx_, -1));
366 duk_pop(ctx_);
367 }
368
369 #endif
370
371 BOOST_AUTO_TEST_CASE(constructor_string)
372 {
373 const auto ret = duk_peval_string(ctx_,
374 "try {"
375 " Malikania.Color('does not exist');"
376 "} catch (e) {"
377 " name = e.name;"
378 " correct = (e instanceof Error);"
379 "}"
380 );
381
382 if (ret != 0)
383 throw mlk::js::duk::get_stack(ctx_, -1);
384
385 duk_get_global_string(ctx_, "name");
386 BOOST_TEST(duk_to_string(ctx_, -1) == "Error");
387 duk_pop(ctx_);
388 duk_get_global_string(ctx_, "correct");
389 BOOST_TEST(duk_to_boolean(ctx_, -1));
390 duk_pop(ctx_);
391 }
392
393 BOOST_AUTO_TEST_CASE(constructor_string_rgb)
394 {
395 const auto ret = duk_peval_string(ctx_,
396 "try {"
397 " Malikania.Color('#ghijkl');"
398 "} catch (e) {"
399 " name = e.name;"
400 " correct = (e instanceof Error);"
401 "}"
402 );
403
404 if (ret != 0)
405 throw mlk::js::duk::get_stack(ctx_, -1);
406
407 duk_get_global_string(ctx_, "name");
408 BOOST_TEST(duk_to_string(ctx_, -1) == "Error");
409 duk_pop(ctx_);
410 duk_get_global_string(ctx_, "correct");
411 BOOST_TEST(duk_to_boolean(ctx_, -1));
412 duk_pop(ctx_);
413 }
414
415 BOOST_AUTO_TEST_SUITE_END()
416
417 /*
418 * Require.
419 * ------------------------------------------------------------------
420 *
421 * TypeTraits<Color>::require expect to have a valid color, it raises an error
422 * for any invalid component. Only alpha can be ommitted but if it is present
423 * and incorrect, an exception is also raised.
424 */
425
426 BOOST_AUTO_TEST_SUITE(require)
427
428 BOOST_AUTO_TEST_CASE(success)
429 {
430 duk_push_c_function(ctx_, [] (auto ctx) {
431 const auto color = mlk::js::duk::require<mlk::client::color>(ctx, 0);
432
433 duk_push_uint(ctx, color.red);
434 duk_put_global_string(ctx, "r");
435 duk_push_uint(ctx, color.green);
436 duk_put_global_string(ctx, "g");
437 duk_push_uint(ctx, color.blue);
438 duk_put_global_string(ctx, "b");
439 duk_push_uint(ctx, color.alpha);
440 duk_put_global_string(ctx, "a");
441
442 return 0;
443 }, 1);
444 duk_put_global_string(ctx_, "draw");
445
446 const auto ret = duk_peval_string(ctx_, "draw('#ff0000');");
447
448 if (ret != 0)
449 throw mlk::js::duk::get_stack(ctx_, -1);
450
451 duk_get_global_string(ctx_, "r");
452 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
453 duk_pop(ctx_);
454 duk_get_global_string(ctx_, "g");
455 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
456 duk_pop(ctx_);
457 duk_get_global_string(ctx_, "b");
458 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
459 duk_pop(ctx_);
460 duk_get_global_string(ctx_, "a");
461 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
462 duk_pop(ctx_);
463 }
464
465 BOOST_AUTO_TEST_CASE(fail)
466 {
467 duk_push_c_function(ctx_, [] (auto ctx) {
468 mlk::js::duk::require<mlk::client::color>(ctx, 0);
469
470 return 0;
471 }, 1);
472 duk_put_global_string(ctx_, "draw");
473
474 const auto ret = duk_peval_string(ctx_,
475 "try {"
476 " draw('#ghijkl');"
477 "} catch (e) {"
478 " name = e.name;"
479 " correct = (e instanceof Error);"
480 "}"
481 );
482
483 if (ret != 0)
484 throw mlk::js::duk::get_stack(ctx_, -1);
485
486 duk_get_global_string(ctx_, "name");
487 BOOST_TEST(duk_to_string(ctx_, -1) == "Error");
488 duk_pop(ctx_);
489 duk_get_global_string(ctx_, "correct");
490 BOOST_TEST(duk_to_boolean(ctx_, -1));
491 duk_pop(ctx_);
492 }
493
494 #if 0
495
496 TODO: check what to do with out of range value
497
498 BOOST_AUTO_TEST_CASE(fail_alpha)
499 {
500 duk_push_c_function(ctx_, [] (auto ctx) {
501 mlk::js::duk::require<mlk::client::color>(ctx, 0);
502
503 return 0;
504 }, 1);
505 duk_put_global_string(ctx_, "draw");
506
507 const auto ret = duk_peval_string(ctx_,
508 "try {"
509 " draw({ red: 10, green: 20, blue: 30, alpha: 800 });"
510 "} catch (e) {"
511 " name = e.name;"
512 " correct = (e instanceof RangeError);"
513 "}"
514 );
515
516 if (ret != 0)
517 throw mlk::js::duk::get_stack(ctx_, -1);
518
519 duk_get_global_string(ctx_, "name");
520 BOOST_TEST(duk_to_string(ctx_, -1) == "RangeError");
521 duk_pop(ctx_);
522 duk_get_global_string(ctx_, "correct");
523 BOOST_TEST(duk_to_boolean(ctx_, -1));
524 duk_pop(ctx_);
525 }
526
527 #endif
528
529 BOOST_AUTO_TEST_SUITE_END()
530
531 /*
532 * Get.
533 * ------------------------------------------------------------------
534 *
535 * TypeTraits<Color>::get readjust any invalid values.
536 */
537
538 BOOST_AUTO_TEST_SUITE(get)
539
540 BOOST_AUTO_TEST_CASE(normal)
541 {
542 duk_push_c_function(ctx_, [] (auto ctx) {
543 const auto color = mlk::js::duk::get<mlk::client::color>(ctx, 0);
544
545 duk_push_uint(ctx, color.red);
546 duk_put_global_string(ctx, "r");
547 duk_push_uint(ctx, color.green);
548 duk_put_global_string(ctx, "g");
549 duk_push_uint(ctx, color.blue);
550 duk_put_global_string(ctx, "b");
551 duk_push_uint(ctx, color.alpha);
552 duk_put_global_string(ctx, "a");
553
554 return 0;
555 }, 1);
556 duk_put_global_string(ctx_, "draw");
557
558 const auto ret = duk_peval_string(ctx_, "draw('#ff0000');");
559
560 if (ret != 0)
561 throw mlk::js::duk::get_stack(ctx_, -1);
562
563 duk_get_global_string(ctx_, "r");
564 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
565 duk_pop(ctx_);
566 duk_get_global_string(ctx_, "g");
567 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
568 duk_pop(ctx_);
569 duk_get_global_string(ctx_, "b");
570 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
571 duk_pop(ctx_);
572 duk_get_global_string(ctx_, "a");
573 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
574 duk_pop(ctx_);
575 }
576
577 BOOST_AUTO_TEST_CASE(adjust_rgb)
578 {
579 duk_push_c_function(ctx_, [] (auto ctx) {
580 const auto color = mlk::js::duk::get<mlk::client::color>(ctx, 0);
581
582 duk_push_uint(ctx, color.red);
583 duk_put_global_string(ctx, "r");
584 duk_push_uint(ctx, color.green);
585 duk_put_global_string(ctx, "g");
586 duk_push_uint(ctx, color.blue);
587 duk_put_global_string(ctx, "b");
588 duk_push_uint(ctx, color.alpha);
589 duk_put_global_string(ctx, "a");
590
591 return 0;
592 }, 1);
593 duk_put_global_string(ctx_, "draw");
594
595 const auto ret = duk_peval_string(ctx_, "draw('#ghijkl');");
596
597 if (ret != 0)
598 throw mlk::js::duk::get_stack(ctx_, -1);
599
600 duk_get_global_string(ctx_, "r");
601 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
602 duk_pop(ctx_);
603 duk_get_global_string(ctx_, "g");
604 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
605 duk_pop(ctx_);
606 duk_get_global_string(ctx_, "b");
607 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
608 duk_pop(ctx_);
609 duk_get_global_string(ctx_, "a");
610 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
611 duk_pop(ctx_);
612 }
613
614 #if 0
615
616 BOOST_AUTO_TEST_CASE(adjust_all)
617 {
618 duk_push_c_function(ctx_, [] (auto ctx) {
619 const auto color = mlk::js::duk::get<mlk::client::color>(ctx, 0);
620
621 duk_push_uint(ctx, color.red);
622 duk_put_global_string(ctx, "r");
623 duk_push_uint(ctx, color.green);
624 duk_put_global_string(ctx, "g");
625 duk_push_uint(ctx, color.blue);
626 duk_put_global_string(ctx, "b");
627 duk_push_uint(ctx, color.alpha);
628 duk_put_global_string(ctx, "a");
629
630 return 0;
631 }, 1);
632 duk_put_global_string(ctx_, "draw");
633
634 const auto ret = duk_peval_string(ctx_, "draw({ red: -1, green: 256, blue: 100, alpha: 800 });");
635
636 if (ret != 0)
637 throw mlk::js::duk::get_stack(ctx_, -1);
638
639 duk_get_global_string(ctx_, "r");
640 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
641 duk_pop(ctx_);
642 duk_get_global_string(ctx_, "g");
643 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
644 duk_pop(ctx_);
645 duk_get_global_string(ctx_, "b");
646 BOOST_TEST(duk_to_uint(ctx_, -1) == 100U);
647 duk_pop(ctx_);
648 duk_get_global_string(ctx_, "a");
649 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
650 duk_pop(ctx_);
651 }
652
653 #endif
654
655 BOOST_AUTO_TEST_CASE(something_else)
656 {
657 duk_push_c_function(ctx_, [] (auto ctx) {
658 const auto color = mlk::js::duk::get<mlk::client::color>(ctx, 0);
659
660 duk_push_uint(ctx, color.red);
661 duk_put_global_string(ctx, "r");
662 duk_push_uint(ctx, color.green);
663 duk_put_global_string(ctx, "g");
664 duk_push_uint(ctx, color.blue);
665 duk_put_global_string(ctx, "b");
666 duk_push_uint(ctx, color.alpha);
667 duk_put_global_string(ctx, "a");
668
669 return 0;
670 }, 1);
671 duk_put_global_string(ctx_, "draw");
672
673 const auto ret = duk_peval_string(ctx_, "draw(null);");
674
675 if (ret != 0)
676 throw mlk::js::duk::get_stack(ctx_, -1);
677
678 duk_get_global_string(ctx_, "r");
679 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
680 duk_pop(ctx_);
681 duk_get_global_string(ctx_, "g");
682 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
683 duk_pop(ctx_);
684 duk_get_global_string(ctx_, "b");
685 BOOST_TEST(duk_to_uint(ctx_, -1) == 0U);
686 duk_pop(ctx_);
687 duk_get_global_string(ctx_, "a");
688 BOOST_TEST(duk_to_uint(ctx_, -1) == 255U);
689 duk_pop(ctx_);
690 }
691
692 BOOST_AUTO_TEST_SUITE_END()
693
694 BOOST_AUTO_TEST_SUITE_END()
695
696 } // !namespace
697
698 } // !mlk::client