Mercurial > malikania
comparison tests/libclient/js-animation/main.cpp @ 44:f30c84b4b9ed
Tests: switch from GoogleTest to Boost.Unit, closes #588
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 30 Nov 2016 21:15:53 +0100 |
parents | fabbe1759cec |
children | 96ba0c5cf893 |
comparison
equal
deleted
inserted
replaced
43:fabbe1759cec | 44:f30c84b4b9ed |
---|---|
17 */ | 17 */ |
18 | 18 |
19 #include <chrono> | 19 #include <chrono> |
20 #include <thread> | 20 #include <thread> |
21 | 21 |
22 #include <gtest/gtest.h> | 22 #define BOOST_TEST_MODULE "Javascript Animation" |
23 #include <boost/test/unit_test.hpp> | |
23 | 24 |
24 #include <malikania/js_client_resources_loader.hpp> | 25 #include <malikania/js_client_resources_loader.hpp> |
25 #include <malikania/js_animation.hpp> | 26 #include <malikania/js_animation.hpp> |
26 #include <malikania/js_animator.hpp> | 27 #include <malikania/js_animator.hpp> |
27 #include <malikania/js_window.hpp> | 28 #include <malikania/js_window.hpp> |
28 #include <malikania/resources_locator.hpp> | 29 #include <malikania/resources_locator.hpp> |
29 | 30 |
30 using namespace std::chrono_literals; | 31 using namespace std::chrono_literals; |
31 | 32 |
32 class TestAnimation : public testing::Test { | 33 class test_animation { |
33 protected: | 34 protected: |
34 mlk::directory_resources_locator m_locator; | 35 mlk::directory_resources_locator m_locator; |
35 mlk::client_resources_loader m_loader; | 36 mlk::client_resources_loader m_loader; |
36 UniqueContext m_ctx; | 37 UniqueContext m_ctx; |
37 | 38 |
38 public: | 39 public: |
39 TestAnimation() | 40 test_animation() |
40 : m_locator(SOURCE_DIRECTORY "/resources") | 41 : m_locator(SOURCE_DIRECTORY "/resources") |
41 , m_loader(m_locator) | 42 , m_loader(m_locator) |
42 { | 43 { |
43 duk_push_object(m_ctx); | 44 duk_push_object(m_ctx); |
44 duk_put_global_string(m_ctx, "Malikania"); | 45 duk_put_global_string(m_ctx, "Malikania"); |
47 mlk::dukx_load_window(m_ctx); | 48 mlk::dukx_load_window(m_ctx); |
48 dukx_put_client_loader(m_ctx, m_loader); | 49 dukx_put_client_loader(m_ctx, m_loader); |
49 } | 50 } |
50 }; | 51 }; |
51 | 52 |
52 TEST_F(TestAnimation, basic) | 53 BOOST_FIXTURE_TEST_SUITE(test_animation_suite, test_animation) |
54 | |
55 BOOST_AUTO_TEST_CASE(basic) | |
53 { | 56 { |
54 try { | 57 try { |
55 auto ret = duk_peval_string(m_ctx, | 58 auto ret = duk_peval_string(m_ctx, |
56 "w = new Malikania.Window();" | 59 "w = new Malikania.Window();" |
57 "a = new Malikania.Animation('animations/margins.json');" | 60 "a = new Malikania.Animation('animations/margins.json');" |
58 "d = new Malikania.Animator(a);" | 61 "d = new Malikania.Animator(a);" |
59 ); | 62 ); |
60 | 63 |
61 if (ret != 0) | 64 if (ret != 0) { |
62 throw dukx_exception(m_ctx, -1); | 65 throw dukx_exception(m_ctx, -1); |
66 } | |
63 | 67 |
64 boost::timer::cpu_timer timer; | 68 boost::timer::cpu_timer timer; |
65 | 69 |
66 while (timer.elapsed().wall / 1000000LL < 8000) { | 70 while (timer.elapsed().wall / 1000000LL < 8000) { |
67 auto ret = duk_peval_string(m_ctx, | 71 auto ret = duk_peval_string(m_ctx, |
70 "d.draw(w, { x: 320 - 16, y: 240 - 16 });" | 74 "d.draw(w, { x: 320 - 16, y: 240 - 16 });" |
71 "d.update();" | 75 "d.update();" |
72 "w.present();" | 76 "w.present();" |
73 ); | 77 ); |
74 | 78 |
75 if (ret != 0) | 79 if (ret != 0) { |
76 throw dukx_exception(m_ctx, -1); | 80 throw dukx_exception(m_ctx, -1); |
81 } | |
77 } | 82 } |
78 | 83 |
79 std::this_thread::sleep_for(3s); | 84 std::this_thread::sleep_for(3s); |
80 } catch (const std::exception &ex) { | 85 } catch (const std::exception &ex) { |
81 FAIL() << ex.what(); | 86 BOOST_FAIL(ex.what()); |
82 } | 87 } |
83 } | 88 } |
84 | 89 |
85 int main(int argc, char **argv) | 90 BOOST_AUTO_TEST_SUITE_END() |
86 { | |
87 testing::InitGoogleTest(&argc, argv); | |
88 | |
89 return RUN_ALL_TESTS(); | |
90 } |