Mercurial > malikania
comparison examples/animation/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 animation | |
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 #include <exception> | |
22 | |
23 #define BOOST_TEST_MODULE "Animation" | |
24 #include <boost/test/unit_test.hpp> | |
25 | |
26 #include <malikania/animation.hpp> | |
27 #include <malikania/animator.hpp> | |
28 #include <malikania/client_resources_loader.hpp> | |
29 #include <malikania/resources_locator.hpp> | |
30 #include <malikania/window.hpp> | |
31 | |
32 namespace { | |
33 | |
34 mlk::window win(400, 400); | |
35 | |
36 } // !namespace | |
37 | |
38 class test_animation { | |
39 protected: | |
40 mlk::directory_resources_locator m_locator; | |
41 mlk::client_resources_loader m_loader; | |
42 | |
43 public: | |
44 test_animation() | |
45 : m_locator(SOURCE_DIRECTORY "/resources") | |
46 , m_loader(m_locator) | |
47 { | |
48 } | |
49 }; | |
50 | |
51 BOOST_FIXTURE_TEST_SUITE(test_animation_suite, test_animation) | |
52 | |
53 BOOST_AUTO_TEST_CASE(standard) | |
54 { | |
55 try { | |
56 auto animation = m_loader.load_animation("animations/margins.json"); | |
57 | |
58 BOOST_REQUIRE_EQUAL(12U, animation.frames().size()); | |
59 BOOST_REQUIRE_EQUAL(500U, animation[0].delay()); | |
60 BOOST_REQUIRE_EQUAL(501U, animation[1].delay()); | |
61 BOOST_REQUIRE_EQUAL(502U, animation[2].delay()); | |
62 BOOST_REQUIRE_EQUAL(503U, animation[3].delay()); | |
63 BOOST_REQUIRE_EQUAL(504U, animation[4].delay()); | |
64 BOOST_REQUIRE_EQUAL(505U, animation[5].delay()); | |
65 BOOST_REQUIRE_EQUAL(506U, animation[6].delay()); | |
66 BOOST_REQUIRE_EQUAL(507U, animation[7].delay()); | |
67 BOOST_REQUIRE_EQUAL(508U, animation[8].delay()); | |
68 BOOST_REQUIRE_EQUAL(509U, animation[9].delay()); | |
69 BOOST_REQUIRE_EQUAL(510U, animation[10].delay()); | |
70 BOOST_REQUIRE_EQUAL(511U, animation[11].delay()); | |
71 } catch (const std::exception &ex) { | |
72 BOOST_FAIL(ex.what()); | |
73 } | |
74 } | |
75 | |
76 BOOST_AUTO_TEST_CASE(draw) | |
77 { | |
78 boost::timer::cpu_timer timer; | |
79 | |
80 try { | |
81 mlk::animation animation = m_loader.load_animation("animations/margins.json"); | |
82 mlk::animator animator(animation); | |
83 | |
84 auto x = (400 / 2) - (animation.sprite().cell().width() / 2); | |
85 auto y = (400 / 2) - (animation.sprite().cell().height() / 2); | |
86 | |
87 while (timer.elapsed().wall / 1000000LL < 8000) { | |
88 win.clear(); | |
89 animator.draw(win, mlk::point(x, y)); | |
90 animator.update(); | |
91 win.present(); | |
92 } | |
93 } catch (const std::exception &ex) { | |
94 BOOST_FAIL(ex.what()); | |
95 } | |
96 } | |
97 | |
98 BOOST_AUTO_TEST_SUITE_END() |