comparison examples/js-animation/main.cpp @ 80:a162f380f02e

CMake: create examples, closes #615
author David Demelier <markand@malikania.fr>
date Sun, 22 Jan 2017 09:59:14 +0100
parents 78de82cc6bde
children 301599387b40
comparison
equal deleted inserted replaced
79:8b41e9a2e095 80:a162f380f02e
1 /* 1 /*
2 * main.cpp -- test Animation (JavaScript binding) 2 * main.cpp -- test Animation (JavaScript binding)
3 * 3 *
4 * Copyright (c) 2013-2016 Malikania Authors 4 * Copyright (c) 2013-2017 Malikania Authors
5 * 5 *
6 * Permission to use, copy, modify, and/or distribute this software for any 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 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
17 */ 17 */
18 18
19 #include <chrono> 19 #include <chrono>
20 #include <thread> 20 #include <thread>
21 21
22 #define BOOST_TEST_MODULE "Javascript Animation"
23 #include <boost/test/unit_test.hpp>
24
25 #include <malikania/js_client_resources_loader.hpp> 22 #include <malikania/js_client_resources_loader.hpp>
26 #include <malikania/js_animation.hpp> 23 #include <malikania/js_animation.hpp>
27 #include <malikania/js_animator.hpp> 24 #include <malikania/js_animator.hpp>
28 #include <malikania/js_window.hpp> 25 #include <malikania/js_window.hpp>
29 #include <malikania/resources_locator.hpp> 26 #include <malikania/resources_locator.hpp>
30 27
31 using namespace std::chrono_literals; 28 using namespace std::chrono_literals;
32 29
33 class test_animation { 30 int main()
34 protected: 31 {
35 mlk::directory_resources_locator m_locator; 32 try {
36 mlk::client_resources_loader m_loader; 33 mlk::directory_resources_locator locator(SOURCE_DIRECTORY);
37 dukx_context m_ctx; 34 mlk::client_resources_loader loader(locator);
35 dukx_context m_ctx;
38 36
39 public:
40 test_animation()
41 : m_locator(SOURCE_DIRECTORY "/resources")
42 , m_loader(m_locator)
43 {
44 duk_push_object(m_ctx); 37 duk_push_object(m_ctx);
45 duk_put_global_string(m_ctx, "Malikania"); 38 duk_put_global_string(m_ctx, "Malikania");
46 mlk::dukx_load_animation(m_ctx); 39 mlk::dukx_load_animation(m_ctx);
47 mlk::dukx_load_animator(m_ctx); 40 mlk::dukx_load_animator(m_ctx);
48 mlk::dukx_load_window(m_ctx); 41 mlk::dukx_load_window(m_ctx);
49 dukx_put_client_loader(m_ctx, m_loader); 42 dukx_put_client_loader(m_ctx, loader);
50 }
51 };
52 43
53 BOOST_FIXTURE_TEST_SUITE(test_animation_suite, test_animation)
54
55 BOOST_AUTO_TEST_CASE(basic)
56 {
57 try {
58 auto ret = duk_peval_string(m_ctx, 44 auto ret = duk_peval_string(m_ctx,
59 "w = new Malikania.Window();" 45 "w = new Malikania.Window();"
60 "a = new Malikania.Animation('animations/margins.json');" 46 "a = new Malikania.Animation('animations/margins.json');"
61 "d = new Malikania.Animator(a);" 47 "d = new Malikania.Animator(a);"
62 ); 48 );
81 } 67 }
82 } 68 }
83 69
84 std::this_thread::sleep_for(3s); 70 std::this_thread::sleep_for(3s);
85 } catch (const std::exception &ex) { 71 } catch (const std::exception &ex) {
86 BOOST_FAIL(ex.what()); 72 std::cerr << ex.what() << std::endl;
73 return 1;
87 } 74 }
88 } 75 }
89
90 BOOST_AUTO_TEST_SUITE_END()