Mercurial > malikania
comparison examples/js-window/main.cpp @ 74:78de82cc6bde
Tests: move graphical examples into examples, closes #606
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 22 Dec 2016 15:17:43 +0100 |
parents | |
children | a162f380f02e |
comparison
equal
deleted
inserted
replaced
73:efe1a7fb43f8 | 74:78de82cc6bde |
---|---|
1 /* | |
2 * main.cpp -- test Window (JavaScript binding) | |
3 * | |
4 * Copyright (c) 2013-2016 Malikania Authors | |
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 #include <chrono> | |
20 #include <thread> | |
21 | |
22 #define BOOST_TEST_MODULE "Javascript Window" | |
23 #include <boost/test/unit_test.hpp> | |
24 | |
25 #include <malikania/js_window.hpp> | |
26 | |
27 using namespace mlk; | |
28 using namespace std::chrono_literals; | |
29 | |
30 class test_window { | |
31 protected: | |
32 dukx_context m_ctx; | |
33 | |
34 public: | |
35 test_window() | |
36 { | |
37 duk_push_object(m_ctx); | |
38 duk_put_global_string(m_ctx, "Malikania"); | |
39 mlk::dukx_load_window(m_ctx); | |
40 } | |
41 }; | |
42 | |
43 BOOST_FIXTURE_TEST_SUITE(test_window_suite, test_window) | |
44 | |
45 BOOST_AUTO_TEST_CASE(basic) | |
46 { | |
47 try { | |
48 auto ret = duk_peval_string(m_ctx, | |
49 "w = new Malikania.Window();" | |
50 "w.setDrawingColor('lightskyblue');" | |
51 "w.clear();" | |
52 "w.present();" | |
53 ); | |
54 | |
55 if (ret != 0) { | |
56 throw dukx_get_exception(m_ctx, -1); | |
57 } | |
58 | |
59 std::this_thread::sleep_for(3s); | |
60 } catch (const std::exception &ex) { | |
61 BOOST_FAIL(ex.what()); | |
62 } | |
63 } | |
64 | |
65 BOOST_AUTO_TEST_CASE(rect) | |
66 { | |
67 try { | |
68 auto ret = duk_peval_string(m_ctx, | |
69 "w = new Malikania.Window();" | |
70 "w.setDrawingColor('lightskyblue');" | |
71 "w.clear();" | |
72 "w.setDrawingColor('white');" | |
73 "w.drawRectangle({ x: 10, y: 10, width: 10, height: 10 });" | |
74 "w.present();" | |
75 ); | |
76 | |
77 if (ret != 0) { | |
78 throw dukx_get_exception(m_ctx, -1); | |
79 } | |
80 | |
81 std::this_thread::sleep_for(3s); | |
82 } catch (const std::exception &ex) { | |
83 BOOST_FAIL(ex.what()); | |
84 } | |
85 } | |
86 | |
87 BOOST_AUTO_TEST_SUITE_END() |