Mercurial > malikania
view tests/libclient/animation/main.cpp @ 43:fabbe1759cec
Misc: switch to mlk namespace, closes #589
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Nov 2016 22:25:17 +0100 |
parents | a47a4477f347 |
children | f30c84b4b9ed |
line wrap: on
line source
/* * main.cpp -- test animation * * Copyright (c) 2013-2016 Malikania Authors * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <chrono> #include <thread> #include <exception> #include <gtest/gtest.h> #include <malikania/animation.hpp> #include <malikania/animator.hpp> #include <malikania/client_resources_loader.hpp> #include <malikania/resources_locator.hpp> #include <malikania/window.hpp> using namespace mlk; using namespace std::chrono_literals; namespace { window win(400, 400); } // !namespace class TestAnimation : public testing::Test { protected: directory_resources_locator m_locator; client_resources_loader m_loader; public: TestAnimation() : m_locator(SOURCE_DIRECTORY "/resources") , m_loader(m_locator) { } }; TEST_F(TestAnimation, standard) { try { auto animation = m_loader.load_animation("animations/margins.json"); ASSERT_EQ(12U, animation.frames().size()); ASSERT_EQ(500U, animation[0].delay()); ASSERT_EQ(501U, animation[1].delay()); ASSERT_EQ(502U, animation[2].delay()); ASSERT_EQ(503U, animation[3].delay()); ASSERT_EQ(504U, animation[4].delay()); ASSERT_EQ(505U, animation[5].delay()); ASSERT_EQ(506U, animation[6].delay()); ASSERT_EQ(507U, animation[7].delay()); ASSERT_EQ(508U, animation[8].delay()); ASSERT_EQ(509U, animation[9].delay()); ASSERT_EQ(510U, animation[10].delay()); ASSERT_EQ(511U, animation[11].delay()); } catch (const std::exception &ex) { FAIL() << ex.what(); } } TEST_F(TestAnimation, draw) { boost::timer::cpu_timer timer; try { animation animation = m_loader.load_animation("animations/margins.json"); animator animator(animation); auto x = (400 / 2) - (animation.sprite().cell().width() / 2); auto y = (400 / 2) - (animation.sprite().cell().height() / 2); while (timer.elapsed().wall / 1000000LL < 8000) { win.clear(); animator.draw(win, point(x, y)); animator.update(); win.present(); } } catch (const std::exception &ex) { FAIL() << ex.what(); } } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }