Mercurial > malikania
comparison examples/js-font/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 Font (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 Font" | |
23 #include <boost/test/unit_test.hpp> | |
24 | |
25 #include <malikania/js_client_resources_loader.hpp> | |
26 #include <malikania/js_font.hpp> | |
27 #include <malikania/js_window.hpp> | |
28 #include <malikania/resources_locator.hpp> | |
29 | |
30 using namespace std::chrono_literals; | |
31 | |
32 class test_font { | |
33 protected: | |
34 mlk::directory_resources_locator m_locator; | |
35 mlk::client_resources_loader m_loader; | |
36 dukx_context m_ctx; | |
37 | |
38 public: | |
39 test_font() | |
40 : m_locator(SOURCE_DIRECTORY "/resources") | |
41 , m_loader(m_locator) | |
42 { | |
43 duk_push_object(m_ctx); | |
44 duk_put_global_string(m_ctx, "Malikania"); | |
45 dukx_put_client_loader(m_ctx, m_loader); | |
46 mlk::dukx_load_font(m_ctx); | |
47 mlk::dukx_load_window(m_ctx); | |
48 } | |
49 }; | |
50 | |
51 BOOST_FIXTURE_TEST_SUITE(test_font_suite, test_font) | |
52 | |
53 BOOST_AUTO_TEST_CASE(basic) | |
54 { | |
55 try { | |
56 auto ret = duk_peval_string(m_ctx, | |
57 "w = new Malikania.Window();" | |
58 "f = new Malikania.Font('DejaVuSans.ttf', 10);" | |
59 "w.setDrawingColor('lightskyblue');" | |
60 "w.clear();" | |
61 "s = 'The world is Malikania.';" | |
62 "c = f.clip(s);" | |
63 "w.setDrawingColor('white');" | |
64 "w.drawText(s, f, { x: 320 - (c.width / 2), y: 240 - (c.height / 2) });" | |
65 "w.present();" | |
66 ); | |
67 | |
68 if (ret != 0) { | |
69 throw dukx_get_exception(m_ctx, -1); | |
70 } | |
71 | |
72 std::this_thread::sleep_for(3s); | |
73 } catch (const std::exception &ex) { | |
74 BOOST_FAIL(ex.what()); | |
75 } | |
76 } | |
77 | |
78 BOOST_AUTO_TEST_SUITE_END() |