Mercurial > malikania
diff tests/libclient/js-sprite/main.cpp @ 42:a47a4477f347
Misc: new style, closes #578
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Nov 2016 21:21:36 +0100 |
parents | 9af360f34c7d |
children | fabbe1759cec |
line wrap: on
line diff
--- a/tests/libclient/js-sprite/main.cpp Sun Nov 27 20:50:38 2016 +0100 +++ b/tests/libclient/js-sprite/main.cpp Tue Nov 29 21:21:36 2016 +0100 @@ -21,172 +21,178 @@ #include <gtest/gtest.h> -#include <malikania/js-client-resources-loader.hpp> -#include <malikania/js-image.hpp> -#include <malikania/js-sprite.hpp> -#include <malikania/js-window.hpp> -#include <malikania/resources-locator.hpp> +#include <malikania/js_client_resources_loader.hpp> +#include <malikania/js_image.hpp> +#include <malikania/js_sprite.hpp> +#include <malikania/js_window.hpp> +#include <malikania/resources_locator.hpp> -using namespace malikania; +namespace mlk = malikania; using namespace std::chrono_literals; class TestSprite : public testing::Test { protected: - ResourcesLocatorDirectory m_locator; - ClientResourcesLoader m_loader; - UniqueContext m_ctx; + mlk::directory_resources_locator m_locator; + mlk::client_resources_loader m_loader; + UniqueContext m_ctx; public: - TestSprite() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { + TestSprite() + : m_locator(SOURCE_DIRECTORY "/resources") + , m_loader(m_locator) + { duk_push_object(m_ctx); duk_put_global_string(m_ctx, "Malikania"); - dukx_load_image(m_ctx); - dukx_load_sprite(m_ctx); - dukx_load_window(m_ctx); - dukx_put_client_loader(m_ctx, &m_loader); - } + mlk::dukx_load_image(m_ctx); + mlk::dukx_load_sprite(m_ctx); + mlk::dukx_load_window(m_ctx); + dukx_put_client_loader(m_ctx, m_loader); + } }; TEST_F(TestSprite, cell) { - try { - auto ret = duk_peval_string(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.cell.width;" - "h = s.cell.height;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.cell.width;" + "h = s.cell.height;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(32U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, columns) { - try { - auto ret = duk_peval_string(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "n = s.columns;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "n = s.columns;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "n"); - ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, margins) { - try { - auto ret = duk_peval_string(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.margins.width;" - "h = s.margins.height;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.margins.width;" + "h = s.margins.height;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(4U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(6U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(6U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, rows) { - try { - auto ret = duk_peval_string(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "n = s.rows;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "n = s.rows;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "n"); - ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, space) { - try { - auto ret = duk_peval_string(m_ctx, - "s = new Malikania.Sprite('sprites/margins.json');" - "w = s.space.width;" - "h = s.space.height;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "s = new Malikania.Sprite('sprites/margins.json');" + "w = s.space.width;" + "h = s.space.height;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } duk_get_global_string(m_ctx, "w"); - ASSERT_EQ(2U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(2U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); duk_get_global_string(m_ctx, "h"); - ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); + ASSERT_EQ(3U, duk_to_uint(m_ctx, -1)); duk_pop(m_ctx); - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } TEST_F(TestSprite, basic) { - try { - auto ret = duk_peval_string(m_ctx, - "w = new Malikania.Window();" - "s = new Malikania.Sprite('sprites/margins.json');" - "c = 0;" - ); + try { + auto ret = duk_peval_string(m_ctx, + "w = new Malikania.Window();" + "s = new Malikania.Sprite('sprites/margins.json');" + "c = 0;" + ); - if (ret != 0) - throw dukx_exception(m_ctx, -1); + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } - for (unsigned c = 0; c < 12; ++c) { - auto ret = duk_peval_string(m_ctx, - "w.setDrawingColor('lightskyblue');" - "w.clear();" - "s.draw(w, c++, { x: 320 - 16, y: 240 - 16 });" - "w.present();" - ); + for (unsigned c = 0; c < 12; ++c) { + auto ret = duk_peval_string(m_ctx, + "w.setDrawingColor('lightskyblue');" + "w.clear();" + "s.draw(w, c++, { x: 320 - 16, y: 240 - 16 });" + "w.present();" + ); - if (ret != 0) { - throw dukx_exception(m_ctx, -1); - } + if (ret != 0) { + throw dukx_exception(m_ctx, -1); + } - std::this_thread::sleep_for(1s); - } - } catch (const std::exception &ex) { - FAIL() << ex.what(); - } + std::this_thread::sleep_for(1s); + } + } catch (const std::exception &ex) { + FAIL() << ex.what(); + } } int main(int argc, char **argv)